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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:41:34+00:00 2026-05-23T04:41:34+00:00

OpenGL: no light for a simple glut cube Hi, i’m trying to study lights

  • 0

OpenGL: no light for a simple glut cube

Hi, i’m trying to study lights in opengl and glut but I have problems quite early. I have this code for making a lighted cube in a custom position with custom camera setting:

void testApp::draw(){
    static float amb[] =  {0.4, 0.4, 0.4, 0.0};
    static float dif[] =  {1.0, 1.0, 1.0, 0.0};
    
    float light_diffuse[] = {1.0, 0.0, 1.0, 1.0}; 
    float light_position[] = {-1.0, 1.0, 1.0, 0.0}; // i tried a lot of positions here!
    
    // set camera
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(0, 200, 1200, 0,0,0, 0,1,0);

    // set lights
    glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);
    glEnable(GL_LIGHT0);
    glEnable(GL_LIGHT1);
    glEnable(GL_LIGHTING);
    glMaterialfv(GL_FRONT, GL_AMBIENT, amb);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, dif);

    // draw scene
    ofScale(50, 50, 50);
    glPushMatrix();

    glutSolidCube(2);

    // close everything
    glPopMatrix();
    glDisable(GL_LIGHT0);
    glDisable(GL_LIGHT1);
    glDisable(GL_LIGHTING); }

I see only a black cube, no light, I think the problem is the light position, I’ve tried a lot of positions but it does not work: black cube.

  • 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-23T04:41:35+00:00Added an answer on May 23, 2026 at 4:41 am

    You are really far away from your cube. Make it smaller and move it closer. Alternatively, change your lighting like this:

    float light_diffuse[] = {100.0, 0.0, 100.0, 100.0}; 
    float light_position[] = {-100.0, 100.0, 1.0, 0.0};
    

    You will hardly see any light effects on a cube. Consider using a teapot.

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

Sidebar

Related Questions

I'm quite new to openGL and I have been trying out some sample codes
I have a simple OpenGL app that displays arbitrary 3D models. I'd like to
This is OpenGL on iPhone 4. Im drawing scene using light and materials. Here
I am trying to make a very simple MFC OpenGL tutorial. There is a
While drawing a simple cube using opengl and glfw, the faces of the cube
I used to have CG shaders working with vertex arrays in OpenGL 2.x, but
I am trying to create street lights in my environment box in opengl using
I have a cube which I want to rotate. I also have a light
As I was reading RedBook I stayed quite confused, that openGL can have maximum
In OpenGL I'm trying to rotate a camera around a point, with camera being

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.