Texture Coordinate Generation

Started by
0 comments, last by wasd 18 years, 6 months ago
Hello, can someone translate this code to directx? glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); float p[4] = { 0, 0, 0, 0 }; p[0] = 1.0f / xsize; p[3] = -x0 / xsize; glTexGenfv(GL_S, GL_OBJECT_PLANE, p); p[0] = 0; glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); p[2] = 1.0f / zsize; p[3] = -z0 / zsize; glTexGenfv(GL_T, GL_OBJECT_PLANE, p); I was searching internet but there was only info about spherical texture coordinate generation. Please help and sorry for dumb question.
Advertisement
I'm not too familiar with OpenGL, but I think this is what you might want. It looks like you're generating your texture coordinates based on the object's position (not sure if this is in object space or world space, but I'm assuming object space). So, you could just set up the texture coordinates when you set up your vertex buffer, something like:
float p[4] = {0, 0, 0, 0};p[0] = 1.0f / xsize;p[3] = -x0 / xsize;Vertices[X].Texcoords[0] = (p[0] * Vertices[X].Pos[0]) +                            (p[1] * Vertices[X].Pos[1]) +                            (p[2] * Vertices[X].Pos[2]) +                            (p[3] * Vertices[X].Pos[3]);p[0] = 0;p[2] = 1.0f / zsize;p[3] = -z0 / zsize;Vertices[X].Texcoords[1] = (p[0] * Vertices[X].Pos[0]) +                            (p[1] * Vertices[X].Pos[1]) +                            (p[2] * Vertices[X].Pos[2]) +                            (p[3] * Vertices[X].Pos[3]);


Where X is the current vertex you're calculating the texture coordinates for.

OpenGL performs the GL_OBJECT_LINEAR texture calculation using the following formula:

g = p0 * x + p1 * y + p2 * z + p3 * w

Where g is the output texture coordinate and p0 - p3 are the coefficients supplied (i.e. the p[4] array).

Once you have these set up, you can use texture transformations during rendering to dynamically alter the texture coordinates if you need to.

This topic is closed to new replies.

Advertisement