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 6905825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:13:54+00:00 2026-05-27T08:13:54+00:00

VC++ 2010, OpenGL, GLSL, SDL So I am having two major problems. I am

  • 0

VC++ 2010, OpenGL, GLSL, SDL

So I am having two major problems. I am hoping to primarily address this first one being: The normal map shader I am using does not work with normals that are pointing in the positive or negative x direction. z and y seem to work just fine (testing the texture and normals on a cube).

edit : It does not seem to be normals in the x direction, because when I rotate the geometry, the front facing quad will still work. So it seems whatever was originally oriented facing the x doesnt work.

Here is some simple test geometry:

glBegin(GL_QUADS);
    glNormal3f(0.0f, 0.0f, 1.0f);
    glTexCoord2f(0.0, 0.0); glVertex3f(-1.0f, 0.0f, 1.0f);
    glTexCoord2f(0.0, 1.0); glVertex3f(-1.0f, 2.0f, 1.0f);
    glTexCoord2f(1.0, 1.0); glVertex3f(1.0f, 2.0f, 1.0f);
    glTexCoord2f(1.0, 0.0); glVertex3f(1.0f, 0.0f, 1.0f);
glEnd();
glBegin(GL_QUADS);
    glNormal3f(-1.0f, 0.0f, 0.0f);
    glTexCoord2f(0.0, 0.0); glVertex3f(-1.0f, 0.0f, 1.0f);
    glTexCoord2f(0.0, 1.0); glVertex3f(-1.0f, 2.0f, 1.0f);
    glTexCoord2f(1.0, 1.0); glVertex3f(-1.0f, 2.0f, -1.0f);
    glTexCoord2f(1.0, 0.0); glVertex3f(-1.0f, 0.0f, -1.0f);
glEnd();

Vertex Shader

#define MAX_LIGHTS 8
#define NUM_LIGHTS 1

varying vec3 lightVec[MAX_LIGHTS];
varying vec3 viewVec;

attribute vec4 glTangent4f;

void main(void)
{
    gl_Position = ftransform();
    gl_TexCoord[0] = gl_MultiTexCoord0;

    vec3 n = normalize(gl_NormalMatrix * gl_Normal);
    vec3 t = normalize(gl_NormalMatrix * glTangent4f.xyz);
    vec3 b = cross(n, t);

    vec3 v;
    vec3 vVertex = vec3(gl_ModelViewMatrix * gl_Vertex);
    int i;
    for (i=0; i<NUM_LIGHTS; ++i)
    {
        vec3 lVec = gl_LightSource[i].position.xyz - vVertex;
        v.x = dot(lVec, t);
        v.y = dot(lVec, b);
        v.z = dot(lVec, n);
        lightVec[i] = v;
    }

    vec3 vVec = -vVertex;
    v.x = dot(vVec, t);
    v.y = dot(vVec, b);
    v.z = dot(vVec, n);
    viewVec = v;
}

Fragment Shader

#define MAX_LIGHTS 8
#define NUM_LIGHTS 1

varying vec3 lightVec[MAX_LIGHTS];
varying vec3 viewVec;

uniform sampler2D colorMap;
uniform sampler2D normalMap;

void main (void)
{
    vec2 uv = gl_TexCoord[0].st * 4.0;
    vec4 base = texture2D(colorMap, uv);
    vec4 final_color = vec4(0.2, 0.2, 0.2, 1.0) * base;
    vec3 vVec = normalize(viewVec);
    vec3 bump = normalize(texture2D(normalMap, uv).xyz * 2.0 - 1.0);
    vec3 R = reflect(-vVec, bump);

    int i;
    for (i=0; i<NUM_LIGHTS; ++i)
    {
        vec3 lVec = normalize(lightVec[i]);
        float diffuse = max(dot(lVec, bump), 0.0);
        vec4 vDiffuse = gl_FrontLightProduct[i].diffuse * diffuse * base;
        final_color += vDiffuse;

        float specular = pow(clamp(dot(R, lVec), 0.0, 1.0), gl_FrontMaterial.shininess);
        vec4 vSpecular = gl_FrontLightProduct[i].specular * specular * diffuse;
        final_color += vSpecular;
    }

    gl_FragColor = final_color;
}

The other problem (which I do not necessarily need to address right this moment) is the specular of the directional light seems to follow with the camera

  • 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-27T08:13:54+00:00Added an answer on May 27, 2026 at 8:13 am
    attribute vec4 glTangent4f;
    

    Where do you actually provide this value? It’s a vertex attribute, but your rendering code doesn’t seem to provide anything.

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

Sidebar

Related Questions

VC++ 2010, SDL, OpenGL, GLSL I am working on this class as a way
VC++ 2010, OpenGL, GLSL, SDL I am moving over to shaders, and have run
This is a follow-up of this question on here http://iphonedevelopment.blogspot.com/2010/02/drawing-hud-display-in-opengl-es.html It tackles on the
Delphi 2010 reportedly supports gestures for user interaction (mouse or touch interface), primarily through
I'm using Visual Studio 2010. I'm trying to write simple Camera class in OpenGL.
I'm trying to do my first pyopengl program but having some issues when calling
I want to run an openGL program in MS Visual Studio 2010, but it
I'm trying to use Visual Studio Express 2010 to write an openGL program, so
I'm working on some cross-platform code using OpenGL and SDL, but have immediately run
This one may be a bit strange. I have a solution in Visual Studio

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.