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 ?
#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();
}