[较早地在一个问题中将其发布为两个问题。决定一次解决一个问题以减少代码壁]
proeceduralgeneration.cpp
void proeceduralgeneration::renderdisk(int sides)
{
float interval = ( 2 * PI )/sides;
float angle = 0.0f;
myTexture = SOIL_load_OGL_texture
(
"gfx/ground.png",//texture link
SOIL_LOAD_AUTO,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_MIPMAPS | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
);
glBegin(GL_TRIANGLES);
for (int i = 0; i < sides; i++)
{
glBindTexture(GL_TEXTURE_2D, myTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexCoord2f(0.5, -0.5);
glVertex3f(0, 0, 0);
glTexCoord2f(cos(angle) / 2 + 0.5, - (sin(angle) / 2 + 0.5));
glVertex3f(cos(angle), sin(angle), 0);
glTexCoord2f(cos(angle + interval) / 2 + 0.5, -(sin(angle + interval) / 2 - 0.5));
glVertex3f(cos(angle + interval), sin(angle + interval), 0);
angle += interval;
}
glVertex3f(cos(0), sin(0), 0);
glEnd();
}
磁盘可以渲染,但是纹理不能正常渲染。编辑后提示磁盘未正确纹理image of disk in test enviroment
GL_TEXTURE_MAG_FILTERcannot beGL_LINEAR_MIPMAP_LINEAR。它应该是GL_LINEAR。因此,请替换此行:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
with
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
无论如何,您都会收到OpenGL错误。在glBindTexture
序列中不允许分别使用glTexParameteri
,glTexEnvf
和glBegin
/glEnd
。仅允许修改属性或指定顶点的指令。绑定纹理并在glBegin
之前设置纹理参数:
glEnd