question about GML

Hey,

I am trying to read in the simple cube.obj file that is all over the internet. I am getting the cube to appear on the screen in 3D, but its being painted in all white. How do I get the cube to be painted the way its supposed to be? I also tried the f-16 from nate Robbins tutorial program with the mtl file and it’s also being painted white. Just not sure how to manage this, here is the code:

#include “glut.h”
#include <stdio.h>
#include <math.h>
#include “glm.h”
GLMmodel* pmodel = NULL;
GLfloat angle1 = 0.0;

void init(void)
{

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1, 1, -1, 1, 1, 7);
glClearColor (0.0, 0.0, 0.0, 0.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
gluLookAt(0, 3, 3,
0.0, 0.0, 0,
0.0, 1.0, 0.);
pmodel = glmReadOBJ(“cube.obj”);
glmUnitize(pmodel);
glmFacetNormals(pmodel);
glmVertexNormals(pmodel, 90);
glmDraw(pmodel, GLM_SMOOTH);
glutSwapBuffers();
}

int main(int argc, char *argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glEnable(GL_DEPTH_TEST);
glutInitWindowPosition(100,100);
glutInitWindowSize(500,500);
glutCreateWindow(“Project 2”);
glutDisplayFunc(display);
init();
glutMainLoop();
return 0; /
ANSI C requires main to return int. */
}

Have you enabled lighting?
glEnable( GL_LIGHTING );
glEnable( GL_LIGHT0 );

-Ehsan-

Thanks. I put those two commmands in, and now it displays kinda the definition of my objects but everything is in black and white. Plus, I have made it so when you push the up key, the camera moves away from the surface, and when you push down key the camera moves towards it, and when it gets right to the ground level everything turns black. Do I need to add a light source to make the color show? Sorry if this is a obvious, I’m a newbie.

GaMEFRo

Here’s the default values for light0:

	GLfloat Ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
	glLightfv( GL_LIGHT0, GL_AMBIENT, Ambient );

	GLfloat Diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
	glLightfv( GL_LIGHT0, GL_DIFFUSE, Diffuse );

	GLfloat Specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
	glLightfv( GL_LIGHT0, GL_SPECULAR, Specular );

	GLfloat Position[] = { 0.0f, 0.0f, 1.0f, 0.0 };
	glLightfv( GL_LIGHT0, GL_POSITION, Position );

	GLfloat Direction[] = { 0.0f, 0.0f, -1.0f };
	glLightfv( GL_LIGHT0, GL_SPOT_DIRECTION, Direction );

	glLightf( GL_LIGHT0, GL_SPOT_EXPONENT, 0.0f );

	glLightf( GL_LIGHT0, GL_SPOT_CUTOFF, 180.0f );

	glLightf( GL_LIGHT0, GL_CONSTANT_ATTENUATION, 1.0f );

	glLightf( GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.0f );

	glLightf( GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.0f );
 	 

You can specify the values explicitly.As an example:

	GLfloat diffuse[] = { 0.4f, 0.4f, 0.4f, 1.0f };
	GLfloat ambient[] = {0.4f, 0.4f, 0.4f, 1.0f };
	GLfloat specular[] = { 0.2f, 0.2f, 0.2f, 1.0f };
	
light0.Ambient( ambient );
light0.Diffuse( diffuse );
light0.Specular( specular );
light0.Enable();

  

Note: light0 is a C++ class in my application. You can use glLight*() in my above example.

-Ehsan-

thanks for your help