Lighting sparse meshes

Started by
25 comments, last by PrestoChung 13 years, 4 months ago
Since I can't use ftransform() I think I am not getting the Projection and Modelview Matrix to my shader properly.

I added this code before linking with:
glLinkProgramARB(Shader_Program)
GLfloat modelview[16]; glGetFloatv(GL_MODELVIEW_MATRIX, modelview); GLfloat projection[16]; glGetFloatv(GL_PROJECTION_MATRIX, projection); GLuint loc;GLuint loc2;loc = glGetUniformLocationARB(Component::Shader_Program,"ModelViewMatrix");glUniform4fvARB(loc,4,modelview);loc2 = glGetUniformLocationARB(Component::Shader_Program,"ProjectionMatrix");glUniform4fvARB(loc2,4,projection);
Now I think I'll have to call some of these functions every frame if the view has changed? This is all a bit new to me as before I just called
gluLookAt()
and never had to touch the matrices directly.

This changes the vert shader to:
#version 150uniform mat4 ProjectionMatrix;uniform mat4 ModelviewMatrix;in vec4 inVertex;in vec2 inTexCoord0;out vec2 outTexCoord0;void main(){	gl_Position = ProjectionMatrix * ModelviewMatrix * inVertex;	outTexCoord0 = inTexCoord0;} 
Advertisement
I suggest you upconvert your GL_UNSIGNED_BYTE to GL_UNSIGNED_SHORT. The reason is that I suspect it is not hw accelerated.
This page has the basic problems to avoid. It doesn't list about your case.


http://www.opengl.org/wiki/Common_Mistakes

Your case is here
http://www.opengl.org/wiki/Vertex_Arrays

and at the bottom it says, Use 16 bit integer.
I'll update the Common Mistakes page.

For your
gluLookAt()
glTranslatef()
and all that shit, you can use a library such as my glhlib
http://glhlib.sourceforge.net

but that's Windows 32 bit only.

There are others such as the GLM
and many others over at
http://www.gamedev.net/community/forums/topic.asp?topic_id=339189

My own glhlib looks like GL
		float Matrix_3DNoiseTexture[16];		glhLoadIdentityf2(Matrix_3DNoiseTexture);		glhTranslatef2(Matrix_3DNoiseTexture, Translate3DNoiseTexture[0], Translate3DNoiseTexture[1], Translate3DNoiseTexture[2]);		glhRotateAboutZf2(Matrix_3DNoiseTexture, Rotate3DNoiseTexture[2]);		glhRotateAboutYf2(Matrix_3DNoiseTexture, Rotate3DNoiseTexture[1]);		glhRotateAboutXf2(Matrix_3DNoiseTexture, Rotate3DNoiseTexture[0]);		glhScalef2(Matrix_3DNoiseTexture, Scale3DNoiseTexture, Scale3DNoiseTexture, Scale3DNoiseTexture);


All the functions are there. There are also the SSE versions for mass data processing.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Why would I want to get rid of glLookAt()?

I did change the indices to GLushort s but nothing happens still. They were working before.

Is this what I should call after updating the viewpoint?
CameraUpdate(){        glLoadIdentity();	gluLookAt( Pos_.X(), Pos_.Y(), Pos_.Z(),	           Loo_.X(), Loo_.Y(), Loo_.Z(),	           Up_.X(), Up_.Y(), Up_.Z() );        GLfloat modelview[16]; 	glGetFloatv(GL_MODELVIEW_MATRIX, modelview); 	GLfloat projection[16]; 	glGetFloatv(GL_PROJECTION_MATRIX, projection); 	GLuint loc;	GLuint loc2;	loc = glGetUniformLocationARB(Component::Shader_Program,"ModelViewMatrix");	glUniform4fvARB(loc,4,modelview);	loc2 = glGetUniformLocationARB(Component::Shader_Program,"ProjectionMatrix");	glUniform4fvARB(loc2,4,projection);}
I noticed I have
glEnableClientState( GL_VERTEX_ARRAY );glEnableClientState( GL_TEXTURE_COORD_ARRAY );
before rendering and
glDisableClientState(GL_VERTEX_ARRAY);glDisableClientState(GL_TEXTURE_COORD_ARRAY);
after rendering.

Should these be removed if I am trying to use generic vertex attributes?
One thing I noticed is a glGetError 1280 (invalid enum) that occurs after this line
glGetProgramivARB(Component::Shader_Program, GL_LINK_STATUS, &linked);
This would seem to indicate that GL_LINK_STATUS is not a valid enum for this function. Is there an ARB version of this enum? If so, what is it? GL_LINK_STATUS_ARB seems to be invalid.
So it appears that checking the link status with
GLint linked;glGetProgramivARB(Component::Shader_Program, GL_LINK_STATUS, &linked);	if( linked ){	std::cout << "GLSL Program linked successfully" << std::endl << std::endl;	glUseProgramObjectARB(Component::Shader_Program);}else{	std::cout << "GLSL Program not linked" << std::endl << std::endl;}


Was no good because GLint linked was not initialized to false. When I change it to
GLint linked=false;glGetProgramivARB(Component::Shader_Program, GL_LINK_STATUS, &linked);	if( linked ){	std::cout << "GLSL Program linked successfully" << std::endl << std::endl;	glUseProgramObjectARB(Component::Shader_Program);}else{	std::cout << "GLSL Program not linked" << std::endl << std::endl;}

It returns false. So I assume that means the glLinkProgramARB call is failing to link the program. How can I troubleshoot this? There are no errors in the infolog.
Okay back in business. Turned out the main problem was with this section
GLfloat modelview[16]; 	glGetFloatv(GL_MODELVIEW_MATRIX, modelview); 	GLfloat projection[16]; 	glGetFloatv(GL_PROJECTION_MATRIX, projection); 	GLuint loc;	GLuint loc2;	loc = glGetUniformLocationARB(Component::Shader_Program,"ModelviewMatrix");	glUniformMatrix4fvARB(loc,1,GL_FALSE,modelview);	loc2 = glGetUniformLocationARB(Component::Shader_Program,"ProjectionMatrix");	glUniformMatrix4fvARB(loc2,1,GL_FALSE,projection);
It was capitalization error on "ModelviewMatrix" (duh :)) and using the wrong version of glUniform-- must use glUniformMatrix.

Ahh so relieved :).

This topic is closed to new replies.

Advertisement