Results 1 to 2 of 2

Thread: Drawing Circle doesnt work (check Code)

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2009
    Posts
    2

    Drawing Circle doesnt work (check Code)

    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.

    Code :
    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\n", SDL_GetError());
        return 1;
      }
     
      screen = SDL_SetVideoMode( 640, 480, 16, SDL_OPENGL );
      if ( !screen ) {
        printf("Unable to set video mode: %s\n", 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\n";
      } 
     
      bool quit = true;
      int currentDegree = 0;
      PointContainer con(0);
     
      while( quit) {
     
        while( SDL_PollEvent( &amp;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;
    }

  2. #2
    Member Contributor
    Join Date
    Jan 2001
    Posts
    82

    Re: Drawing Circle doesnt work (check Code)

    What are you using to offset the circle? It is centered at the bottom-left corner of the viewport. Also, with a delay of 20 (milliseconds?), the circle is being drawn and cleared so fast you may never actually see it. Try increasing the delay and see what happens.

Similar Threads

  1. How does drawing circle work?
    By yj1214 in forum OpenGL: General
    Replies: 1
    Last Post: 11-22-2015, 06:56 PM
  2. can someone tell me why this code doesnt work?
    By sandbucket in forum OpenGL: Basic Coding
    Replies: 14
    Last Post: 06-18-2013, 01:02 PM
  3. My first code doesnt work -help needed
    By glopengl in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 10-26-2008, 10:40 AM
  4. MipMaping doesnt work
    By jirkamelich in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 12-25-2002, 04:55 AM
  5. Correct OpenGL code in CodeWarrior doesnt work.
    By d98ped in forum OpenGL: macOS
    Replies: 5
    Last Post: 09-02-2001, 06:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean