1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
#include "Timer.h"
#include <windows.h>
#include <time.h>
#include "sdl_opengl.h"
#include "sdl.h"
#include "AStar.h"
#include <iostream>
const int iSCREEN_WIDTH = 800;
const int iSCREEN_HEIGHT = 600;
const int iNODE_COUNT_X = 26;
const int iNODE_COUNT_Y = 26;
sNode m_nodes[iNODE_COUNT_Y][iNODE_COUNT_X];
int InitGL(int width, int height)
{
int error;
error = SDL_Init (SDL_INIT_EVERYTHING);
//gl and SDL configurationss
SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 32);
SDL_GL_SetAttribute (SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute (SDL_GL_ALPHA_SIZE, 8);
//Use Hardware acceleration
unsigned int flags = SDL_OPENGL | SDL_HWSURFACE;
//Vid mode
SDL_SetVideoMode(width, height, 32, flags);
//Window color
glClearColor (0.0, 0.0, 0.0, 0.0);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho (0.0, width, height, 0.0, 0.0, 10.0);
glDisable(GL_TEXTURE_2D);
return error;
}
bool HandleInput()
{
SDL_Event event;
while (SDL_PollEvent (&event))
{
switch(event.type)
{
case SDL_QUIT:
{
return false;
}
case SDL_KEYDOWN:
{
switch (event.key.keysym.sym)
{
case SDLK_ESCAPE:
{
return false;
}
}
break;
}
}
}
return true;
}
void GenerateNodes()
{
const float fNodeSpacingX = iSCREEN_WIDTH / iNODE_COUNT_X + 2;
const float fNodeSpacingY = iSCREEN_WIDTH / iNODE_COUNT_Y + 2;
int iNodeCount = 0;
for(int y = 0; y < iNODE_COUNT_Y; ++y)
{
for(int x = 0; x < iNODE_COUNT_X; ++x)
{
m_nodes[y][x].vPosition.x = fNodeSpacingX * x;
m_nodes[y][x].vPosition.y = fNodeSpacingY * y;
std::cout << iNODE_COUNT_X << std::endl << iNODE_COUNT_Y ;
//give unique ID to all nodessssssssssssss
m_nodes[y][x].id = iNodeCount++;
}
}
}
void DrawNodes()
{
glColor4f( 1.0f, 0.0f, 0.0f, 1.0f );
//Point size
glPointSize( 3.5f );
//drawing points
glBegin(GL_POINTS);
for(int y = 0; y < iNODE_COUNT_Y; ++y)
{
for(int x = 0; x < iNODE_COUNT_X; ++x)
{
glVertex2f(m_nodes[y][x].vPosition.x, m_nodes[y][x].vPosition.y);
}
}
glEnd();
glBegin(GL_LINES);
for(int y = 0; y < iNODE_COUNT_Y; ++y)
{
for(int x = 0; x < iNODE_COUNT_X; ++x)
{
glVertex2f(m_nodes[y][x].vPosition.x, m_nodes[y][x].vPosition.y);
}
}
for(int x = 0; x < iNODE_COUNT_X; ++x)
{
for(int y = 0; y < iNODE_COUNT_Y; ++y)
{
glVertex2f(m_nodes[y][x].vPosition.x, m_nodes[y][x].vPosition.y);
}
}
glEnd();
}
int SDL_main(int argc, char* argv[])
{
InitGL(iSCREEN_WIDTH, iSCREEN_HEIGHT);
TimerInit();
srand(time(NULL));
GenerateNodes();
//smoothing
glShadeModel(GL_SMOOTH);
glEnable(GL_POINT_SMOOTH);
glEnable(GL_LINE_SMOOTH);
while(HandleInput())
{
float dt = TickTimer();
glClear(GL_COLOR_BUFFER_BIT);
DrawNodes();
SDL_GL_SwapBuffers();
}
return 0;
}
|