help with gl lights

Monkey Forums/Monkey Programming/help with gl lights

NoOdle(Posted 2012) [#1]
I am playing around with Mark's opengl test. I can't seem to get light 0 working properly... I assume its to do with the lack of normals for the cube.

The light is completely black until the cube rotates and then the whole thing lights up and then fades to black.

How would I go about adding normals? I have not used vbo's before and getting my head around them is tricky.

Could anyone help please?




bruZard(Posted 2012) [#2]
you need vertex normals and the corresponding pointer to that data. scale your vertex buffer to "vertex count * 2" and poke vertexX, vertexY, vertexZ, normalX, normalY, normalZ.


NoOdle(Posted 2012) [#3]
ok well i tried to write a fresh example for showing a cube with normals. Doesn't work :P




marksibly(Posted 2012) [#4]
Hi,

> glVertexPointer 3,GL_FLOAT,32,0

32 should be 24 - this is the 'stride' or 'bytes per vertex'.

Also, glNormalPointer is commented out!


NoOdle(Posted 2012) [#5]
ah yes, made a mistake with the stride. Correcting that and the cube is visible. Still an issue with the normal though.

Also, glNormalPointer is commented out!


It doesn't compile with the glNormalPointer commented out. It fails with the following error:

/Users/saferguson09/Desktop/gltest/main.build/glfw/xcode/../main.cpp:3595: error: no matching function for call to '_glNormalPointer(int, int, int)'
/Users/saferguson09/Desktop/gltest/main.build/glfw/xcode/../main.cpp:3086: note: candidates are: void _glNormalPointer(int, int, int, RamBuffer*)
/Users/saferguson09/Desktop/gltest/main.build/glfw/xcode/../main.cpp:3090: note:                 void _glNormalPointer(int, int, int, int)


TRANS Failed to execute 'xcodebuild -configuration Debug', return code=16640
** BUILD FAILED **
The following build commands failed:
	CompileC build/MonkeyGame.build/Debug/MonkeyGame.build/Objects-normal/x86_64/main.o ../main.cpp normal x86_64 c++ com.apple.compilers.llvmgcc42
(1 failure)


I am attempting to use: glNormalPointer GL_FLOAT,24,12

Also attempting to enable a light results in the app to exit immediately. Doesn't matter where I place it. This worked in another test I did but might be doing it wrong:



Cheers!


NoOdle(Posted 2012) [#6]
ah yes, made a mistake with the stride. Correcting that and the cube is visible. Still an issue with the normal though.

Also, glNormalPointer is commented out!


It doesn't compile with the glNormalPointer commented out. It fails with the following error:

/Users/saferguson09/Desktop/gltest/main.build/glfw/xcode/../main.cpp:3595: error: no matching function for call to '_glNormalPointer(int, int, int)'
/Users/saferguson09/Desktop/gltest/main.build/glfw/xcode/../main.cpp:3086: note: candidates are: void _glNormalPointer(int, int, int, RamBuffer*)
/Users/saferguson09/Desktop/gltest/main.build/glfw/xcode/../main.cpp:3090: note:                 void _glNormalPointer(int, int, int, int)


TRANS Failed to execute 'xcodebuild -configuration Debug', return code=16640
** BUILD FAILED **
The following build commands failed:
	CompileC build/MonkeyGame.build/Debug/MonkeyGame.build/Objects-normal/x86_64/main.o ../main.cpp normal x86_64 c++ com.apple.compilers.llvmgcc42
(1 failure)


I am attempting to use: glNormalPointer GL_FLOAT,24,12

Also attempting to enable a light results in the app to exit immediately. Doesn't matter where I place it. This worked in another test I did but might be doing it wrong:

		glMatrixMode( GL_MODELVIEW )
		glLoadIdentity()
		glEnable( GL_LIGHTING )
		glEnable( GL_LIGHT0 )
		glLightfv( GL_LIGHT0, GL_POSITION, [0.0, 0.0, -1.0] )


Cheers!


NoOdle(Posted 2012) [#7]
I noticed bruZard's normal fix in the forums and have added that. It now compiles and the light doesn't crash the app immediately.

The cube is however, inside out in places and still looks flat shaded. Here is the updated code:




marksibly(Posted 2012) [#8]
Hi,

glLightfv with GL_POSITION requires 4 params - the last param is 1.0 for a point light, 0.0 for a directional light.


NoOdle(Posted 2012) [#9]
Thanks for your help Mark! I had also forgtotten to set depth buffer to 32 in the config.h folder for the new test app.


NoOdle(Posted 2012) [#10]
In case anyone was following this and might find the code useful. Here is a working version with a textured cube and a light. You can also move a vertex with the up key. Don't forget like I did to enable depth buffer in the build folder.

The code is a mess and poorly coded as I was trying to get it working and didn't really know what I was doing.