Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 1 of 1

Thread: Not showing the lines

  1. #1
    Newbie Newbie
    Join Date
    Oct 2012
    Posts
    1

    Question Not showing the lines

    edit: I discovered I had to use glPushMatrix() and glPopMatrix()

    Good morning. I wrote the program below but I can't make it show the lines of x,y only translate the object. What could I have done wrong ?

    Code :
     
      #include "GL/freeglut.h"
      #include "GL/gl.h"
     
      void draw(void) 
      { 
     
    	glClear(GL_COLOR_BUFFER_BIT);
     
            // lines 
    	glBegin(GL_LINES);
    	glColor3f(1.0f, 1.0f, 1.0f);
    	glVertex2f(-1.0f, 0.0f); 
    	glVertex2f(1.0f, 0.0f); 
    	glVertex2f(0.0f, 1.0f);
    	glVertex2f(0.0f, -1.0f); 
    	glEnd();
     
     
    	glPushMatrix();
            glTranslatef(1.0f, -1.0f, 0.0f);
     
            // rectangle
            glBegin(GL_QUADS);
    	glColor3f(1.0f, 1.0f, 1.0f);
    	glVertex2f(-0.25f, 0.25f);
    	glVertex2f(-0.75f, 0.25f);
    	glVertex2f(-0.75f, 0.75f);
    	glVertex2f(-0.25f, 0.75f);
    	glEnd();
     
            glPopMatrix();
    	glFlush();  
    } 	   	  
     
      void init(void) 
      { 
    	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);  
      } 	   	  
     
      int main(int argc, char** argv) 
      { 
    	 glutInit(&argc, argv);
    	 glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    	 glutCreateWindow("Rectangle Translation");
    	 glutDisplayFunc(draw);  
    	 init();
    	 glutMainLoop();
      }
    Last edited by thames; 10-12-2012 at 09:07 AM. Reason: solved

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •