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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:31:22+00:00 2026-06-13T12:31:22+00:00

I’m an experienced C++ programmer tying to learn OpenGL. Among others, I’m reading Richard

  • 0

I’m an experienced C++ programmer tying to learn OpenGL. Among others, I’m reading Richard Wright’s OpenGL Super Bible. The support libraries there are hacker-head C, loosely translated into C++. Being a bit of a purist, I’ve translated most of the support code into C++. And I’m working in QT rather than Glut. I’ve gotten the examples from Chapter 2 and the “Primitives” example from Chapter 3 working, but can’t get the “GeoTest” example to work right. Here’s a simplified example of the problem:

void geotest::paintGL() {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glEnable(GL_CULL_FACE);
    model_view_matrix.push(view_frame);
        float red[] = { 1.0f, 0.0f, 0.0f, 1.0f };
        shader.use(
            transform_pipeline.get_model_view_matrix(),
            transform_pipeline.get_projection_matrix(),
            red);
        glBegin(GL_TRIANGLES);
            glVertex3f(-1.2f, -1.2f, 0.0f);
            glVertex3f( 1.2f, -1.2f, 0.0f);
            glVertex3f( 1.2f,  1.2f, 0.0f);
        glEnd();
    model_view_matrix.pop();
}

The shader is my adaptation of the book’s GLT_SHADER_DEFAULT_LIGHT. I’ve cut down the drawing to isolate the problem. When I run this code I get a seemingly blank window. The code that I haven’t shows provides support for rotating the image, and when I rotate it 180 degrees around the x or y axis I see the other side of the triangle, but it’s black instead of red. So it looks like the surface normal is initially pointing away from the viewer, so it gets culled.

I’ve tried adding 1 to 3 calls to glNormal3f(0.0f, 0.0f, -1.0f) (and 1.0f) everywhere I could imagine between the glBegin and glEnd calls, with no effect that I could see; the triangle is always drawn with its back face showing.

Am I missing something fundamental about normals? I’m pretty sure that the shader is okay (I get the same problem with the normal if I use the book’s GLT_SHADER_FLAT, although when the triangle appears it’s red, as it should be).

EDIT here’s the code for the shader:

const char *default_light_vp = "uniform mat4 mvMatrix;"
                               "uniform mat4 pMatrix;"
                               "varying vec4 vFragColor;"
                               "attribute vec4 vVertex;"
                               "attribute vec3 vNormal;"
                               "uniform vec4 vColor;"
                               "void main(void) { "
                               " mat3 mNormalMatrix;"
                               " mNormalMatrix[0] = mvMatrix[0].xyz;"
                               " mNormalMatrix[1] = mvMatrix[1].xyz;"
                               " mNormalMatrix[2] = mvMatrix[2].xyz;"
                               " vec3 vNorm = normalize(mNormalMatrix * vNormal);"
                               " vec3 vLightDir = vec3(0.0, 0.0, 1.0); "
                               " float fDot = max(0.0, dot(vNorm, vLightDir)); "
                               " vFragColor.rgb = vColor.rgb * fDot;"
                               " vFragColor.a = vColor.a;"
                               " mat4 mvpMatrix;"
                               " mvpMatrix = pMatrix * mvMatrix;"
                               " gl_Position = mvpMatrix * vVertex; "
                               "}";


const char *default_light_fp =   
#ifdef OPENGL_ES
                               "precision mediump float;"
#endif
                               "varying vec4 vFragColor; "
                               "void main(void) { "
                               " gl_FragColor = vFragColor; "
                               "}";
  • 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-13T12:31:23+00:00Added an answer on June 13, 2026 at 12:31 pm

    Culling isn’t based on the direction of the normals, it’s based on the winding order. Try switching the direction that you are drawing your vertices, and see if that makes a difference. To change the winding order, you can use glFrontFace with GL_CW and GL_CCW, which defines which face is front and which is back.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am writing an app with both english and french support. The app requests
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text

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.