0

the desired result is for the texture to be pretty much the same throughout the disk however it seems to only render properly at a few triangle shaped areas round the edge

disk.cpp

void disk::disk(int sides)
{
    float interval = ( 2 * PI )/sides;
    float angle = 0.0f;
    groundtexture = SOIL_load_OGL_texture

    (
        "gfx/ground.png", 
        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,groundtexture);
        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();
    }

the disk does render but the texture does not render properly. with the edit suggested the disk does not texture right

3 Answers3

1

You'll get OpenGL errors, anyway. glBindTexture, glTexParameteri, respectively glTexEnvf is not allowed within glBegin/glEnd sequences. Only instructions which modify the attributes or specify a vertex are allowed.
Bind the texture and set the texture parameters before glBegin:

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);

glBegin(GL_TRIANGLES);
for (int i = 0; i < sides; i++)
{
    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;
}
glEnd();
Rabbid76
  • 202,892
  • 27
  • 131
  • 174
0

GL_TEXTURE_MAG_FILTER cannot be GL_LINEAR_MIPMAP_LINEAR. It should be GL_LINEAR instead. So replace this line:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);

with

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
SurvivalMachine
  • 7,946
  • 15
  • 57
  • 87
0

GL_MODULATE is an integer value, and not a float value. Use the correct method if you want correct results ;)

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
robthebloke
  • 9,331
  • 9
  • 12