Results 1 to 4 of 4

Thread: Problem with drawing update.

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    8

    Problem with drawing update.

    Hello guys.
    I'm trying to make a drawing in a window change his size every time i hit 'b' in my keyboard, but is not working properly.
    Every time i hit 'b', "glVertex3f(x,y,z)" in "renderPrimitive()"function recieves new values for x and y and may drawing gets bigger. This is working fine, but my drawing gets bigger only if i click outside of my window and click back in the window. What i have to do to solve this problem?
    Code :
    void renderPrimitive(void) 
    {
    	glBegin(GL_QUADS);
    	//spaceship is a global TAD who update his variables everytime i hit 'b', i do this in a callback.
        	glVertex3f(spaceship->blcx, spaceship->blcy, 0.0); // The bottom left corner  
        	glVertex3f(spaceship->tlcx, spaceship->tlcy, 0.0); // The top left corner  
        	glVertex3f(spaceship->trcx, spaceship->trcy, 0.0); // The top right corner  
        	glVertex3f(spaceship->brcx, spaceship->brcy, 0.0); // The bottom right corner  
    	glEnd();
    }
    Code :
    void reshape(int width, int height)
    {
      	glViewport(0, 0, (GLsizei)width, (GLsizei)height);
    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();
    	gluPerspective(60, (GLfloat)width / (GLfloat)height, 1.0, 100.0);
    	glMatrixMode(GL_MODELVIEW);
    }
    Code :
    void display(void)
    {
    	glClearColor(1.f, 0.f, 0.f, 1.f);
    	glClear (GL_COLOR_BUFFER_BIT);
    	glLoadIdentity();	
    	glTranslatef(0.0f, 0.0f, -5.0f);	
    	renderPrimitive();
    	glFlush();
    }
    Code :
    int main(int argc, char **argv)
    {
    	spaceship = create_spaceship(spaceship);
    	glutInit(&argc, argv);
     
    	glutInitDisplayMode (GLUT_SINGLE); 
    	glutInitWindowSize (800, 600);
    	glutInitWindowPosition (100, 50);
    	glutCreateWindow ("My first OpenGL Window");
     
    	glutDisplayFunc(display);
    	glutReshapeFunc(reshape);
     
    	glutKeyboardFunc(key_pressed);
     
    	glutMainLoop();
    }

  2. #2
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    8
    I put "glutIdleFunc(display);" between "glutDisplayFunc(display);" and "glutReshapeFunc(reshape);" in "main" function, and ir works, but my window almost freezes, it gets heavy very very heavy!
    I tried to put after both functions too, but same thing happened.

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    8
    Please guys, i really need your help to solve this problem.

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    Your idle function should not be you display function it should just invalid the view.

Similar Threads

  1. glUseProgram var update problem
    By O-san in forum OpenGL: GLSL
    Replies: 12
    Last Post: 01-19-2009, 03:10 AM
  2. Drawing update (not every frame) ??
    By thebuffalo in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 12-28-2008, 04:23 AM
  3. Color update problem
    By Arifin in forum OpenGL: Windows
    Replies: 1
    Last Post: 07-22-2008, 01:32 AM
  4. Color update problem
    By Arifin in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 07-21-2008, 04:38 PM
  5. update texture problem
    By chenya in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 06-04-2008, 04:52 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