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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:52:10+00:00 2026-06-12T21:52:10+00:00

I’ve just finished creating a simple rectangle in OpenGL 3.2, now I want to

  • 0

I’ve just finished creating a simple rectangle in OpenGL 3.2, now I want to add lighting support. However, whenever I try to move my normals to the fragment shader, nothing appears. If I comment out that line, it works perfectly again. What would be the reason causing this? Nothing shows up in error log.

Vertex Shader:

#version 150

in vec4 position;
in vec3 inNormal;

out vec3 varNormal;

uniform mat4 modelViewProjectionMatrix;

void main()
{
    //varNormal = inNormal; //If I uncomment this line, nothing shows up    
gl_Position = modelViewProjectionMatrix * position;
}

Fragment Shader:

#version 150

in vec3 varNormal;

out vec4 fragColor;

void main()
{
fragColor = vec4(1, 1, 1, 1);   
}

And passing the normals:



GLuint posAttrib = 0;
GLuint normalAttrib = 1;

glBindAttribLocation(program, posAttrib, "position");
glBindAttribLocation(program, normalAttrib, "normalAttrib");

//Building the VAO's/VBO's
GLfloat posCoords[] = 
{
    -10, 0.0, -10,
    -10, 0.0, 10,
    10, 0.0, 10,
    10, 0.0, -10,   
};

GLfloat normalCoords[] = 
{
    0, 0, 1,
    0, 0, 1,
    0, 0, 1,
    0, 0, 1
};

glGenVertexArrays(1, &vaoName);
glBindVertexArray(vaoName);

GLuint posBuffer;
glGenBuffers(1, &posBuffer);
glBindBuffer(GL_ARRAY_BUFFER, posBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(posCoords), posCoords, GL_STATIC_DRAW);
glEnableVertexAttribArray(posAttrib);   
glVertexAttribPointer(posAttrib, 3, GL_FLOAT, GL_FALSE, 0, 0);

GLuint normalBuffer;        
glGenBuffers(1, &normalBuffer);
glBindBuffer(GL_ARRAY_BUFFER, normalBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(normalCoords), normalCoords, GL_STATIC_DRAW);
glEnableVertexAttribArray(normalAttrib);
glVertexAttribPointer(normalAttrib, 3, GL_FLOAT, GL_FALSE, 0, 0);

I haven’t tried putting all of my position and normal coords in a single VBO, but I’d prefer to not resort to that method.

  • 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-06-12T21:52:11+00:00Added an answer on June 12, 2026 at 9:52 pm

    Probably the most bizarre reason to fix this, but it works.

    First of all, make sure you know how the OpenGL Profiler works. There’s a tutorial provided by the Apple Docs

    Set a breakpoint before/after glDrawElements (or glDrawArray depending on what you’re using)

    Then look at your program’s vertex attributes and make sure the locations are in order.

    If they aren’t, rearrange them.

    From (or anything else):

    enum
    {
    POSITION_ATTR = 0,
    TEXTURE_ATTR=1,
    NORMAL_ATTR=2,
    };
    

    To:

    enum
    {
    NORMAL_ATTR = 0,
    TEXTURE_ATTR=2,
    POSITION_ATTR=1,
    };
    

    No idea how and why this is happening, but this is the solution to the problem.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I want to show the soap response to UIWebview.. my soap response is, <p><img

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.