假设我想翻译一个多边形。如果在绘制它之前我使用 glTranslatef 它会被翻译,但是如果我想绘制两个多边形并且只翻译一个,我该怎么做?
#include <OpenGL/OpenGL.h>
#include <GLUT/GLUT.h>
#include "utility.h"
void init()
{
glLoadIdentity();
glOrtho(-1, 1, -1, 1, -1, 1);
}
void render()
{
glClearColor(APPLE_GRAY);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glTranslatef(0.5, 0.0, 0.0);
glBegin(GL_POLYGON);
glColor4f(RED);
glVertex2f(0,0.5);
glVertex2f(-0.5,-0.5);
glVertex2f(0.5, -0.5);
glBegin(GL_POLYGON);
glColor4f(BLUE);
glVertex2f(0.5,0.5);
glVertex2f(-0.5,0.5);
glVertex2f(-0.5, -0.5);
glVertex2f(0.5, -0.5);
glEnd();
glFlush();
}
我只想翻译三角形,而不是正方形。怎么做?