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

  • Home
  • SEARCH
  • 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 6192933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:01:53+00:00 2026-05-24T03:01:53+00:00

I have browsed many online articles and adding lighting seems very straight forward but

  • 0

I have browsed many online articles and adding lighting seems very straight forward but I’m not able to get a result. I’m using OpenGL 3.0 and I use a vertex and fragment shaders for my animating model. Btw, I’m new to OpenGL.

Disregarding the lighting I have everything working fine with the 3D char running around the environment.

    glEnable(GL_DEPTH_TEST);
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

    *snip*

    glEnable(GL_LIGHTING);
    glEnable (GL_LIGHT0);

    float ambientLight0[] = { 0.2f, 0.2f, 0.2f, 1.0f };
    float diffuseLight0[] = { 0.8f, 0.8f, 0.8f, 1.0f };
    float specularLight0[] = { 0.5f, 0.5f, 0.5f, 1.0f };
    float position0[] = { -2.5f, 1.0f, -1.0f, 1.0f };   
    glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight0);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight0);
    glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight0);
    glLightfv(GL_LIGHT0, GL_POSITION, position0);

    //glEnable(GL_COLOR_MATERIAL);
    //float mcolor[] = { 1.0f, 0.0f, 0.0f, 1.0f };
    //glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mcolor);

    m_Beast.onRender();

Here’s how m_Beast.onRender() looks:

    glPushMatrix();

    Vector3 pos = getPosition();
    glTranslatef(pos.x, pos.y, pos.z);

    glBindTexture(GL_TEXTURE_2D, m_beastTextureID);

    static float modelviewMatrix[16];
    static float projectionMatrix[16];

    glGetFloatv(GL_MODELVIEW_MATRIX, modelviewMatrix);
    glGetFloatv(GL_PROJECTION_MATRIX, projectionMatrix);

    m_shaderProgram->bindShader();
    m_shaderProgram->sendUniform4x4("modelview_matrix", modelviewMatrix);
    m_shaderProgram->sendUniform4x4("projection_matrix", projectionMatrix);
    m_shaderProgram->sendUniformTexture("texture0", 0);

    glEnableVertexAttribArray(0);
    glEnableVertexAttribArray(1);

    glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer);
    glVertexAttribPointer((GLint)0, 3, GL_FLOAT, GL_FALSE, 0, 0);

    glBindBuffer(GL_ARRAY_BUFFER, m_texCoordBuffer);
    glVertexAttribPointer((GLint)1, 2, GL_FLOAT, GL_FALSE, 0, 0);

    glDrawArrays(GL_TRIANGLES, 0, m_interpolatedFrame.vertices.size());

    glDisableVertexAttribArray(1);
    glDisableVertexAttribArray(0);

    glPopMatrix();

I just want a quick way to get some directional lighting on my model. I’m really not interesting in writing a lighting shader at this point.

  • 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-24T03:01:55+00:00Added an answer on May 24, 2026 at 3:01 am

    As soon as you use vertex shaders, you must implement the lighting calculations yourself. In older OpenGL one could still use the fixed function vertex pipeline and program only the fragment stage. But with OpenGL-3 and onwards you’re required to do it all.

    However you shouldn’t feel too bad about this. In the end you’ll write less, because the huge plethora of function calls required to configure fixed function, can be replaced by much shorter and concise shader code.

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

Sidebar

Related Questions

I have browsed through many articles, but none of them mention how I can
I have browsed thru other postings on S/O, but I can't find a solution
This seems like a simple question, but I haven't been able to find the
I have read many posts regarding detection of popup blocker by javascript code but
While there are many guides for Browser Helper Objects, i have a hard time
I have browsed lift's MegaProtoUser and encountered this construction: ??(Last Name) . Can anyone
I have an ASP.NET web application the entire site is browsed over HTTPS using
I have built an online game system that depends on a timer that records
I have always hated wysiwyg editors but most of the applications I develop they
I have a web page that sends email to multiple users (online distribution list).

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.