本文介绍了glTranslatef在glBegin中不起作用.. glEnd的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试并排绘制不同颜色的2个正方形,我的问题是我无法让glTranslatef将第二个正方形向右移动,第二个正方形只是在第一个正方形之上绘制.
I'm trying to draw 2 squares side by side of different colours, my problem is I can't get glTranslatef to move my second square to the right, the second square just draws over the first.
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPointSize(10);
glBegin(GL_QUADS);
glColor3f(0.0,1.0,0.0);
drawSquare();
glTranslatef(10,0,0);
glColor3f(1.0,0.0,0.0);
drawSquare();
glEnd();
glFlush(); // Process all OpenGL routines
}
void drawSquare()
{
glVertex3f(0,0,0);
glVertex3f(10,0,0);
glVertex3f(10,10,0);
glVertex3f(0,10,0);
}
推荐答案
您无法在glBegin/glEnd
块内进行翻译,您已将其分为两个块.
You cannot translate inside a glBegin/glEnd
block, you have break it up into two blocks.
我建议您开始在代码中使用glGetError()
,它将帮助您发现这样的错误.
I recommend to start using glGetError()
in your code, it will help you find mistakes like this.
这篇关于glTranslatef在glBegin中不起作用.. glEnd的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!