Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jshmrsn

macrumors member
Original poster
Jul 26, 2008
43
0
My implementation of OpenGL displays ambient light normally while running in the iPhone OS simulator, but acts as if ambient light color was 0,0,0 on the device.

I activate lighting like so:
Code:
        glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);     	     

	GLfloat ambient[] = {0.6, 0.6, 0.6, 1.0 };
	GLfloat diffuse[] = { 1, 1, 1, 1 };
	GLfloat specular[] = { 0,0, 0, 1.0 };

	glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
	glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
	glLightfv( GL_LIGHT0, GL_SPECULAR, specular);

	GLfloat position[] = { direction.x, direction.y, direction.z, 0.0 };
	glLightfv(GL_LIGHT0, GL_POSITION, position);

Code:
		GLfloat amb[] = { 1,1, 1, 1.0 };
		GLfloat diffuse[] = { 1, 1, 1, 1.0 }; 	
		glMaterialfv(GL_FRONT, GL_AMBIENT, amb);
		glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);

Working...



Not working...




Thanks for any help/ideas.

-Josh Rosen
 

SqueegyX

macrumors regular
Mar 24, 2008
108
1
I have seen this exact same thing. Is the iphone incapable of ambient light in lighting rendering? That seems like it would be crazy.
 

jshmrsn

macrumors member
Original poster
Jul 26, 2008
43
0
Well I'm not exactly sure what fixed it, but by strictly following this tutorial I was able to get ambient lighting to work.

http://www.zeuscmd.com/tutorials/opengles/15-Lighting.php

my code is now:

Code:
	float lightAmbient[] = { 0.3f, 0.3f, 0.3f, 1.0f };
	float lightDiffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };

	float matAmbient[] = { 0.6f, 0.6f, 0.6f, 1.0f };
	float matDiffuse[] = { 0.6f, 0.6f, 0.6f, 1.0f };

	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);     	     

	glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, matAmbient);
	glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, matDiffuse);

	glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient);
	glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse);


	//using my vector class
	direction.unit();	
	GLfloat position[] = { direction.x, direction.y, direction.z, 0.0 };
	glLightfv(GL_LIGHT0, GL_POSITION, position);
 

SqueegyX

macrumors regular
Mar 24, 2008
108
1
I think its the GL_FRONT_AND_BACK that makes it work. I used to just have GL_FRONT.
 

Frogblast

macrumors newbie
Sep 17, 2008
4
0
If you had been checking for errors, an OpenGL ES implementation should reject the GL_FRONT value with a GL_INVALID_ENUM error.

Always use glGetError() to debug these kind of problems.
 

SqueegyX

macrumors regular
Mar 24, 2008
108
1
Yeah but its weird because it works great because it works great in the simulator. Is the simulator OpenGL, not OpenGLES?
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
Yeah but its weird because it works great because it works great in the simulator. Is the simulator OpenGL, not OpenGLES?

Lots of things work in the simulator that don't work on a real device. This is because the simulator has access to the full-on Mac OSX libraries rather than the limited Mobile OSX ones...
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.