Hi GL’ers,
im trying to draw a circle step by step. In while loop a container is filled with proper coordinates of circle, after each add into the container the content of the container is drawn. So every step i should see a circle being build up.
But i see nothing. Whats wrong with this code? Checked many websites and tutorials, looks ok.
int main(int argc, char *argv[])
{
SDL_Event event;
SDL_Surface* screen;
if( SDL_Init(SDL_INIT_VIDEO) != 0 ) {
printf("Unable to initialize SDL: %s
", SDL_GetError());
return 1;
}
screen = SDL_SetVideoMode( 640, 480, 16, SDL_OPENGL );
if ( !screen ) {
printf("Unable to set video mode: %s
", SDL_GetError());
return 1;
}
glClearColor( 0, 0, 0, 0 );
glViewport( 0, 0, 640, 480);
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho( 0, 640, 480, 0, -1, 1 );
glMatrixMode( GL_MODELVIEW);
glLoadIdentity();
if( glGetError() != GL_NO_ERROR ) {
std::cout << "Error in GL
";
}
bool quit = true;
int currentDegree = 0;
PointContainer con(0);
while( quit) {
while( SDL_PollEvent( &event)) {
if( event.type == SDL_KEYDOWN) {
if( event.key.keysym.sym == SDLK_ESCAPE) {
quit = false;
}
}
}
if( currentDegree > 360) {
currentDegree = 0;
con.clear();
}
//manage pointcontainer
float degInRad = currentDegree*DEG2RAD;
Point2D p2;
p2.x = cos( degInRad)*50;
p2.y = sin( degInRad)*50;
con.add( p2);
currentDegree += 1;
// Clear the screen before drawing
glClear( GL_COLOR_BUFFER_BIT );
glBegin( GL_LINES );
glColor3i( 255, 0, 0);
for( int i=0; i<con.size(); i++) {
glVertex3f( con.get(i).x, con.get( i).y, 0);
}
glEnd();
SDL_GL_SwapBuffers();
SDL_Delay( 20);
}
SDL_Quit();
return 0;
}