Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3996978
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:20:42+00:00 2026-05-20T07:20:42+00:00

I have been trying for several hours to implement a GLSL replacement for glTexGen

  • 0

I have been trying for several hours to implement a GLSL replacement for glTexGen with GL_OBJECT_LINEAR. For OpenGL ES 2.0. In Ogl GLSL there is the gl_TextureMatrix that makes this easier, but thats not available on OpenGL ES 2.0 / OpenGL ES Shader Language 1.0

Several sites have mentioned that this should be “easy” to do in a GLSL vert shader. But I just can not get it to work.

My hunch is that I’m not setting the planes up correctly, or I’m missing something in my understanding.

I’ve pored over the web. But most sites are talking about projected textures, I’m just looking to create UV’s based on planar projection. The models are being built in Maya, have 50k polygons and the modeler is using planer mapping, but Maya will not export the UV’s. So I’m trying to figure this out.

I’ve looked at the glTexGen manpage information:

g = p1xo + p2yo + p3zo + p4wo

What is g? Is g the value of s in the texture2d call?

I’ve looked at the site:

http://www.opengl.org/wiki/Mathematics_of_glTexGen

Another size explains the same function:

coord = P1*X + P2*Y + P3*Z + P4*W

I don’t get how coord (an UV vec2 in my mind) is equal to the dot product (a scalar value)? Same problem I had before with “g”.

What do I set the plane to be? In my opengl c++ 3.0 code, I set it to [0, 0, 1, 0] (basically unit z) and glTexGen works great.

I’m still missing something.

My vert shader looks basically like this:
WVPMatrix = World View Project Matrix.
POSITION is the model vertex position.

varying vec4 kOutBaseTCoord;
void main()
{
    gl_Position = WVPMatrix * vec4(POSITION, 1.0);

    vec4 sPlane = vec4(1.0, 0.0, 0.0, 0.0);
    vec4 tPlane = vec4(0.0, 1.0, 0.0, 0.0);
    vec4 rPlane = vec4(0.0, 0.0, 0.0, 0.0);
    vec4 qPlane = vec4(0.0, 0.0, 0.0, 0.0);

    kOutBaseTCoord.s = dot(vec4(POSITION, 1.0), sPlane);
    kOutBaseTCoord.t = dot(vec4(POSITION, 1.0), tPlane);
    //kOutBaseTCoord.r = dot(vec4(POSITION, 1.0), rPlane);
    //kOutBaseTCoord.q = dot(vec4(POSITION, 1.0), qPlane);

}

The frag shader

precision mediump float;
uniform sampler2D BaseSampler;
varying mediump vec4 kOutBaseTCoord;
void main()
{

    //gl_FragColor = vec4(kOutBaseTCoord.st, 0.0, 1.0);
    gl_FragColor = texture2D(BaseSampler, kOutBaseTCoord.st);
}

I’ve tried texture2DProj in frag shader

Here are some of the other links I’ve looked up

http://www.gamedev.net/topic/407961-texgen-not-working-with-glsl-with-fixed-pipeline-is-ok/

Thank you in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T07:20:43+00:00Added an answer on May 20, 2026 at 7:20 am

    From the glTexGen documentation ::

    void glTexGenfv ( GLenum coord ,
    GLenum pname , const GLfloat *params
    );

    • coord – Specifies a texture coordinate. Must
      be one of GL_S, GL_T, GL_R, or GL_Q.
    • pname – If the texture generation function is
      GL_OBJECT_LINEAR, the function

    g = p1 xo + p2 yo + p3 zo + p4 wo

    is used, where g is the value computed
    for the coordinate named in coord,…

    so g is indeed a scalar value, which can be either the s or t component of your vec2 uv value, depending on the value of coord (GL_S, or GL_T).

    To be more explicit, the calls to

    glTexGen(GL_S, GL_OBJECT_LINEAR, {ps0,ps1,ps2,ps3})
    glTexGen(GL_T, GL_OBJECT_LINEAR, {pt0,pt1,pt2,pt3})
    

    is similar to

    vec4 sPlane = vec4(ps0,ps1,ps2,ps3);
    vec4 tPlane = vec4(pt0,pt1,pt2,pt3);
    kOutBaseTCoord.s = dot(vec4(POSITION, 1.0), sPlane);
    kOutBaseTCoord.t = dot(vec4(POSITION, 1.0), tPlane);
    

    Depending on the scale of your POSITION values, the output st coordinates can be outside the (0,1) range. Using your values :

    vec4 sPlane = vec4(1.0, 0.0, 0.0, 0.0);
    vec4 tPlane = vec4(0.0, 1.0, 0.0, 0.0);
    

    will map directly the x coordinate of your model vertices to the s values of your texture coordinates, same for y and t. Thus, if your model has a coordinate range outside (0,1), the UV values will follow.

    To make the texture fit your model, you have to adapt the scale of the projection to the size of your model. For an example model size of 100.0, this would give the following code :

    float MODEL_SIZE = 100.0;
    vec4 sPlane = vec4(1.0/MODEL_SIZE, 0.0, 0.0, 0.0);
    vec4 tPlane = vec4(0.0, 1.0/MODEL_SIZE, 0.0, 0.0);
    

    This solution can still give you values < 0 if you model is centered in (0,0,0). To adjust this, you could add an offset to the resulting UV values. Such as :

    kOutBaseTCoord.st += vec(0.5);
    

    Note that all this in wildly dependent of your application, and what you try to achieve with your texture projection. Don’t hesitate to adjust your formulas to match your needs, that’s what shaders are for !

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to implement Win32's MessageBox using GTK. The app uses SDL/OpenGL,
I've been trying to learn this myself several hours and just had to give
I've been struggling for several hours trying to figure out how to get this
I have been searching the web for several hours to try to get an
I have been trying to find a really fast way to parse yyyy-mm-dd [hh:mm:ss]
I have been trying to determine a best case solution for registering a COM
I have been trying to work my way through Project Euler, and have noticed
I have been trying to get around this error for a day now and
I have been trying to explain the difference between switch statements and pattern matching(F#)
I have been trying to read a picture saved in Access DB as a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.