Skip to main content
gamedev.net
🔒 Locked

Automatic Texture Generation

Started by Brian Jones 0 replies 450+ views
Original Post
Brian Jones
Brian Jones
I am just using glTexGen to display a simple bitmap, to see how it works, yet, nothing gets display properly. So I was wondering if anyone could help. Render a simple square bitmap at vertices: glVertex3f(-50.0f, 50.0f, -100.0f); glVertex3f(-50.0f, -50.0f, -100.0f); glVertex3f(50.0f, -50.0f, -100.0f); glVertex3f(50.0f, 50.0f, -100.0f); If you could please just show me how to use the texGen function to place texture coordinates on those vertex coordinate, just the steps involved, no need for showing me to how bind or glTexParameteri anything, I will be very thankful. I don''t have a signature
I don't have a signature
dave j
dave j
Here is the relevant code from when I first got texture coord generation to work. This actually uses multi-texturing to apply a detail map as well.

Bits to note are:

You need separate coefficients for s and t coordinates. In the code below, s is based entirely on the vertex''s x coord and t on the vertex''s z coord.

In my program, the base texture is stretched to fit over a 1000x1000 quad - hence the 1.0/1000.0 (remember, texture coords go from 0 to 1). The detail texture repeats 10 times so I only divide by 100.

GLfloat baseCoeffsS[] = { 1.0/1000.0, 0.0, 0.0, 0.0 };
GLfloat baseCoeffsT[] = { 0.0, 0.0, 1.0/1000.0, 0.0 };
GLfloat detailCoeffsS[] = { 1.0/100.0, 0.0, 0.0, 0.0 };
GLfloat detailCoeffsT[] = { 0.0, 0.0, 1.0/100.0, 0.0 };


glActiveTextureARB(GL_TEXTURE0_ARB);
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGenfv(GL_S, GL_OBJECT_PLANE, baseCoeffsS);
glEnable(GL_TEXTURE_GEN_S);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGenfv(GL_T, GL_OBJECT_PLANE, baseCoeffsT);
glEnable(GL_TEXTURE_GEN_T);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glBindTexture(GL_TEXTURE_2D, landTexture);
glEnable(GL_TEXTURE_2D);

glActiveTextureARB(GL_TEXTURE1_ARB);
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGenfv(GL_S, GL_OBJECT_PLANE, detailCoeffsS);
glEnable(GL_TEXTURE_GEN_S);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGenfv(GL_T, GL_OBJECT_PLANE, detailCoeffsT);
glEnable(GL_TEXTURE_GEN_T);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBindTexture(GL_TEXTURE_2D, detailTexture);
glEnable(GL_TEXTURE_2D);

glColor3f(1.0, 1.0, 1.0);

glBegin(GL_TRIANGLE_STRIP);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(0.0, 0.0, 1000.0);
glVertex3f(1000.0, 0.0, 0.0);
glVertex3f(1000.0, 0.0, 1000.0);
glEnd();


glActiveTextureARB(GL_TEXTURE0_ARB);
glDisable(GL_TEXTURE_2D);

glActiveTextureARB(GL_TEXTURE1_ARB);
glDisable(GL_TEXTURE_2D);

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.