我试图将草纹理放到一个简单的矩形中,但我不能强迫它工作。将纹理绑定到id的功能正常工作(已测试),因此它必须在此处,但我无法识别错误。矩形仍然是白色,没有任何纹理,也没有任何试图进行纹理化的迹象
void Draw()
{
glBegin(GL_QUADS);
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBindTexture(GL_TEXTURE_2D, grass);
glPushMatrix();
float m_amb[] = { 1.0f, 1.0f, 1.0f, 1.0f };
float m_dif[] = { 1.0f, 1.0f, 1.0f, 1.0f };
float m_spe[] = { 0.0f, 0.0f, 0.0f, 1.0f };
glMaterialfv(GL_FRONT, GL_AMBIENT, m_amb);
glMaterialfv(GL_FRONT, GL_DIFFUSE, m_dif);
glMaterialfv(GL_FRONT, GL_SPECULAR, m_spe);
glTexCoord2f(0.0f, 0.0f);
glNormal3f(0.0f, 0.0f, 1.0f);
glVertex3f(place.x - 15.0f, place.y - 15.0f, place.z - 5.0f);
glTexCoord2f(1.0f, 0.0f);
glNormal3f(0.0f, 0.0f, 1.0f);
glVertex3f(place.x +15.0f, place.y - 15.0f, place.z - 5.0f);
glTexCoord2f(1.0f, 1.0f);
glNormal3f(0.0f, 0.0f, 1.0f);
glVertex3f(place.x + 15.0f, place.y + 15.0f, place.z - 5.0f);
glTexCoord2f(0.0f, 1.0f);
glNormal3f(0.0f, 0.0f, 1.0f);
glVertex3f(place.x - 15.0f, place.y + 15.0f, place.z - 5.0f);
glDisable(GL_TEXTURE_2D);
glEnd();
glPopMatrix();
}
答案 0 :(得分:1)
在glBegin
/glEnd
序列之间不允许有其他命令,除了用于指定顶点属性(例如=ActiveCell.Offset(2,20)=True
,glTexCoord2f
和glNormal3f
)的命令。
无视此操作将产生glVertex3f
错误,如glBegin
的OpenGL参考页所述。
要解决此问题,您必须将GL_INVALID_OPERATION
直接移到第一条glBegin(GL_QUADS);
指令之前,并将glTexCoord2f
直接移到最后一条glEnd();
指令之后:
glVertex3f