Newbie in Over-Head

Hey All, I am a meganewb so bear with me.

Long story short, I have been brought in on a project to help a local school to replace someone else who didn’t have time to finish it. Neither me nor the person I’m replacing had any gl experience coming into the project, So I’m trying to teach myself based on what she’s accomplished thus far teaching herself. I’m not doing TOO bad so far (I’ve got one that will take points from a file and produce a simple shape using the points and then I can rotate it and slide it around the page) but I’ve hit a few problems and I fear that I’m having some issues with the stuff I’m doing because one or both of us working on the project thus far didn’t understand some more simple concept from it.

My Current Issues: Lighting, because I am bringing in Data from a file we thought to view it graphically represented in 3D that we need either to change the color of each panel we add to the object (I’ve been assured that I will be passed coordinates of a series of triangles and won’t have to worry about calculating points so assuming it’s as easy as they make it sound…) or if we use the same color which sounds easier, we need to use lighting… however I’ve been finding incomplete resources for lighting, most of them assuming I’ve read earlier tutorials written by them and I’m getting all sorts of different information. Some tell me I need to specify normals but they don’t really go into detail on that, and my lines with the normals seem to break it more (or maybe just differently) and I thought I did my normals right. All the problems I’ve been having though are likely the result of either me or the person I’m replacing not understanding a simpler concept that is overlooked or something like that I’m going to post a copy of one of the projects I was working on (I’ll clean it up a bit hopefully it’ll be readable) but I was hoping someone can tell me why my light position commands seem to do nothing unless I remove them entirely, and hopefully if I’m missing something else or misusing something else altogether maybe point that out because documentation for a lot of this is inconsistent from source to source.

#include <stdio.h>
#include <stdlib.h>
#include <GL/gl.h>
#include <GL/glx.h>
#include<GL/glu.h>

/* Removed a bunch of stuff here from the post because while it looked important it didn’t look relevant to my questions so obviously this doesn’t run as is but should include any code that’s even remotely relevant still */

glClearColor(0.0,0.0,0.0,1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPointSize(5.0);
glLoadIdentity();
//glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE, color);
// glRotatef(20,1.0,0.0,0.0);

glNewList(1,GL_COMPILE);
glEnable(GL_CULL_FACE);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
//glEnable(GL_LIGHT2);
GLfloat lightpos0[] = {1,1,0, 1};
glLightfv(GL_LIGHT0, GL_POSITION, lightpos0);
GLfloat lightpos1[] = {0,0,1, 1};
glLightfv(GL_LIGHT1, GL_POSITION, lightpos1);
GLfloat intensity1[]={.0f,.5f,.5f,1};
glLightfv(GL_LIGHT1,GL_AMBIENT,intensity1);
GLfloat lightpos2[] = {0,0,1, 1};
//glLightfv(GL_LIGHT2, GL_POSITION, lightpos2);
GLfloat intensity2[]={.5f,.0f,.5f,1};
//glLightfv(GL_LIGHT2,GL_AMBIENT,intensity2);

// glEnable(GL_DEPTH_BUFFER);

/Draw each side of the cube/
glBegin(GL_QUADS);
GLfloat white[] = {1.f,1.f, 1.f, 1.f};
GLfloat cyan[] = {0.f, .8f, .8f, 1.f};
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, white);
glColor3f(0,.5,.5); //teal
// glNormal3d(0,-1,0);
glVertex3f(.5,-.5,.5);
glVertex3f(-.5,-.5,.5);
glVertex3f(-.5,-.5,-.5);
glVertex3f(.5,-.5,-.5);
// glRotatef(45,1.0,0.0,0.0);

glBegin(GL_QUADS);
glColor3f(1,1,1);//white
//GLfloat white[] = {1.f,1.f, 1.f, 1.f};
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, white);
//glNormal3d(-1,0,0);
glVertex3f(-.5,-.5,.5);
glVertex3f(-.5,.5,.5);
glVertex3f(-.5,.5,-.5);
glVertex3f(-.5,-.5,-.5);
//glRotatef(45,1.0,0.0,0.0);

glColor3f(1,0,0);//red
glBegin(GL_QUADS);
GLfloat red[] = {1.f,0.f, 0.f, 1.f};
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, white);
//glNormal3d(0,0,1);
glVertex3f(.5,-.5,.5);
glVertex3f(.5,.5,.5);
glVertex3f(-.5,.5,.5);
glVertex3f(-.5,-.5,.5);
glEnd();

glBegin(GL_QUADS);
glColor3f(.5,0,.5);//purple
GLfloat purple[] = {0.5f,0.f, 0.5f, 1.f};
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, white);
//glNormal3d;(0,1,0);
glVertex3f(.5,.5,.5);
glVertex3f(.5,.5,-.5);
glVertex3f(-.5,.5,-.5);
glVertex3f(-.5,.5,.5);
// glRotatef(45,1.0,0.0,0.0);

glBegin(GL_QUADS);
glColor3f(0,0,1);//blue
//glNormal3d(0,0,-1);
GLfloat blue[] = {0.f,0.f, 1.f, 1.f};
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, white);
//glNormal3d(0,0,-1);
glVertex3f(-.5,-.5,-.5);
glVertex3f(-.5,.5,-.5);
glVertex3f(.5,.5,-.5);
glVertex3f(.5,-.5,-.5);
// glRotatef(45,1.0,0.0,0.0);

glBegin(GL_QUADS);
glColor3f(0,1,0);//green
// glNormal3d(1,0,0);
GLfloat green[] = {0.f,1.f, 0.f, 1.f};
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, white);
//glMaterialfv(GL_FRONT, GL_SPECULAR, white);
//glNormal3d(1,0,0);
glVertex3f(.5,-.5,-.5);
glVertex3f(.5,.5,-.5);
glVertex3f(.5,.5,.5);
glVertex3f(.5,-.5,.5);
// glRotatef(45,1.0,0.0,0.0);

glEnd();

glEndList();

/*Loop to make it keep rotating on its own*/

while (1){
x=(x+10)%360;
glMatrixMode(GL_MODELVIEW);
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
// gluLookAt(.01,.01,.01,0,0,0,0,1,0);
glOrtho(-5,5,-5,5,-5,5);
// glTranslatef(0,0,1);
glRotatef(x,1.0,1.0,1.0);

glCallList(1);


if ( swapFlag )
  glXSwapBuffers( dpy, glxWin );

usleep(100000);
glFlush();


}

sleep(50);
exit( 0 );
}

((most of the commented out lines I left in were left by the person working before me on this particular one… the lines with the normals
I thought were right but seem to screw it up, and the position of the lights don’t seem to change no matter what I do are always at opposite sides of the object UNLESS I change Light0 from point to directional, as is with the lines commented out that are and point lights and not directional lights I’ve got a cube that rotates and one side is white and it gradiates to a cyan color on the other side.))

Hi there

A couple of suggestions: Maybe if you could structure your post a bit, it would make it easier for people to reply?

In a question like this your code fragments could include initialisation of the OpenGL, setting up the lights and your drawing function - in their separate functions.

You could also come up with a simpler but functional version of your code, post it in here, so people can just copy and paste it and try it out on their own.

The last paragraph, where you mention something about what you’re trying to do, or what you actually get instead, is rather confusing.

madmortigan