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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:30:32+00:00 2026-05-24T21:30:32+00:00

EDIT: A few people have said to use glNormal3f() to solve my lighting problem,

  • 0

EDIT: A few people have said to use glNormal3f() to solve my lighting problem, but I researched and implemented that just now and it didn’t change anything at all.

I’m kind of new to OpenGL so I guess I’m doing something wrong, but I followed the examples in the Red Book as closely as I could and I just can’t figure out what’s wrong, so I figured I’d try and ask you guys.

I have two problems. One is that, even though I’m sure I’m using glFrustum correctly, it still renders an orthographic scene, and it renders objects that are both in front of and behind the camera for some reason. The other is that, even though I’m pretty sure I’m doing this lighting right (because I followed the example in the book), it’s lighting the scene with a uniform color, no shading or anything. Here’s my code:

#include "GraphicsManager.h"
#include <GL/gl.h>

void GraphicsManager::initialize () {
  fx = 0;
  fy = 0;  
  glEnable (GL_LIGHTING);
  glEnable (GL_LIGHT0);
  glDepthFunc (GL_LEQUAL);
  glEnable (GL_DEPTH_TEST);
  glViewport (0, 0, 800, 600);
  glMatrixMode (GL_PROJECTION);
  glLoadIdentity ();
  glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
  glMatrixMode (GL_MODELVIEW);
  glLoadIdentity ();
}

int GraphicsManager::draw (std::vector<float> buttoninfo) {
  // changing light_position makes no difference
  GLfloat light_position[] = { 1.0, 1.0, 1.0, 1.0 };
  int i, j, k;
  fx += buttoninfo[0];
  fy += buttoninfo[1];
  glClearColor (0.0, 0.0, 0.0, 1.0);
  glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glColor3f (0.5, 0.5, 0.8);
  glLoadIdentity ();
  glLightfv (GL_LIGHT0, GL_POSITION, light_position);�
  glRotatef (buttoninfo[3], 1.0, 0.0, 0.0);
  glRotatef (buttoninfo[2], 0.0, 1.0, 0.0);
  glTranslatef (-fx, 0, -fy);
  for (i = 0; i < 5; i ++) {
  for (j = 0; j < 5; j ++) {
  for (k = 0; k < 5; k ++) {
    glPushMatrix ();
    glTranslatef (i, j, k);
    glBegin (GL_TRIANGLE_FAN);
      glVertex3f (0.0, 0.5, 0.0);
      glVertex3f (-0.5, -0.5, -0.5);
      glVertex3f (-0.5, -0.5, 0.5);
      glVertex3f (0.5, -0.5, 0.5);
      glVertex3f (0.5, -0.5, -0.5);
      glVertex3f (-0.5, -0.5, -0.5);
    glEnd ();
    glPopMatrix ();
  }
  }
  }
  glFlush ();
  return (int)buttoninfo[5];
}

Can you help me figure out what’s wrong? Thanks in advance.

  • 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-24T21:30:33+00:00Added an answer on May 24, 2026 at 9:30 pm

    You are drawing the elements around the origin (0,0,0) but you don’t move the “camera” at the begining. so your are looking from the origin point at the scene, which is inside your elements.

    try if

    glMatrixMode (GL_MODELVIEW);
    glLoadIdentity ();
    glTranslate3f(0, 0, -10); 
    

    works to fix it

    and for Perspective rendering consider using gluPerspective.
    http://www.opengl.org/sdk/docs/man/xhtml/gluPerspective.xml

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

Sidebar

Related Questions

What is Lazy Loading? [Edit after reading a few answers] Why do people use
I have found a few libraries to edit MP3 tags (UltraID3Lib is great) but
A lot of people have said that ArrayList.removeAll is really slow with large size
It seems that this problem has already been encountered by quite a few people:
     Before we start I know a fair few people consider tests that hit the
I have a few objects serialized [edit: using BinaryFormatter] this way Obj_A 1 Obj_A
I've noticed over time that Clojure users have nothing but massive enthusiasm for the
People visit my website, and I have an algorithm that produces a score between
Several online searches give me the impression that very few people like to write
I have here a git repository with a few people working on it. I've

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.