以下是我绘制线条的方法,我使用鼠标绘制线条
static struct
{
GLfloat p[MAX_POINTS][2];
GLuint point_cnt;
} contours [ MAX_CONTOURS ] ;
GLuint point_cnt_mouse;
point_cnt_mouse = contours[contour_cnt].point_cnt;
glColor3f( 0.0, 0.0, 0.0 );
glBegin(GL_LINES);
glLineWidth(5.0);
int i;
int j;
for(i = 0; i <= contour_cnt; i++)
{
GLuint point_cnt;
point_cnt = contours[i].point_cnt;
if (contours[i].point_cnt == 0)
{
glVertex2fv ( P );
glVertex2fv ( P );
}//if
else
{
for(j = 2; j <= point_cnt; j++)
{
glVertex2fv (contours[i].p[j-2]);
glVertex2fv (contours[i].p[j-1]);
}//for
}//else
}//for
if(point_cnt_mouse > 0)
{
glVertex2fv(contours[contour_cnt].p[point_cnt_mouse-1]);
glVertex2fv(P);
}//if
glEnd();
然后我使用glTexImage2D()来制作GL_TEXTURE_2D 我的展示是
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glPushMatrix ();
glTranslatef(-4.0, 5.0, -6.0);
//this is box and load texture on it
drawPlane();
glPopMatrix();
glutSwapBuffers();
glFlush();
}
void myinit()
{
glClearColor(1.0, 1.0, 1.0, 1.0);
glEnable(GL_DEPTH_TEST);
//load png image
drawLogo();
glDisable(GL_DEPTH_TEST);
}
徽标不会显示行,为什么?任何人都可以告诉我的代码有什么问题吗?
答案 0 :(得分:2)
确保在绘制线条之前禁用纹理(glDisable(GL_TEXTURE_2D)
)。在绘制纹理之前重新启用(glEnable(GL_TEXTURE_2D)
)。
如果您使用默认的GL_MODULATE
纹理环境,请确保在使用纹理绘制之前将当前颜色设置为白色(glColor3ub(255,255,255)
)。如果你在行例程glColor3f( 0.0, 0.0, 0.0 )
之后绘制纹理,那么GL_MODULATE
会将所有纹素RGB值乘以零,从而使你到处都是黑色。
答案 1 :(得分:0)
对我来说,display()
函数从不调用drawLogo()
,我觉得有点怀疑。
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glPushMatrix ();
glTranslatef(-4.0, 5.0, -6.0);
//this is box and load texture on it
drawPlane();
glPopMatrix();
glutSwapBuffers();
glFlush();
}