【发布时间】:2011-11-21 15:47:45
【问题描述】:
我的代码有问题,但对于我绘制的任意数量的基元,尽管调用了 glClearColor 然后使用 glColor3f 选择颜色,但出现的颜色是完全随机的...
所以在我的渲染类中,我循环遍历所有对象并调用它们的绘图方法,对于它们看起来像的图元:
inline void PrimitiveDrawer::drawWireframePrism(Vector3 pos, float radius, Vector3 col){
glClearColor( 1.0f, 1.0f, 1.0f, 1.0f );
glColor3f(col.x, col.y, col.z);
glLineWidth(3);
glBegin (GL_LINE_LOOP);
...
glEnd()
但无论我选择什么颜色,我总是得到不同的颜色......有趣的是,我用这种方法绘制的所有原始线都假定它们绑定的模型的颜色(它们是网格的边界体积)... 可能与我使用的模型加载器有关吗?
这会影响每个形状(模型周围的形状除外),其中每个 GL_LINE 都采用相同的颜色(出于某种原因为绿色),包括我试图绘制的 glutBitMapCharacter...这是困扰我的主要想法因为我想为文本绘图选择颜色,目前我正在做:
void renderBitmapString(float x, float y, void *font,char *string)
{
char *c;
glRasterPos2f(x, y);
for (c=string; *c != '\0'; c++) {
glutBitmapCharacter(font, *c);
}
}
void drawText(char text[20], float x, float y){
glPushMatrix();
setOrthographicProjection();
glLoadIdentity();
glClearColor( 0, 0, 0, 0 );
glColor4f(0, 0, 1, 1);
renderBitmapString(x, y,(void *)font, text);
resetPerspectiveProjection();
glPopMatrix();
}
但是文本显示为绿色而不是蓝色?
【问题讨论】:
-
你为什么一直打电话
glClearColor,完全没用,除非后面跟着glClear。