Flickering lights when animating models - Resolved

Started by
4 comments, last by Infinite_Daremo 15 years, 9 months ago
For some reason when i animate my models lights seem to flicker. There is only 2 lights active in the scene a static source light and a dynamic spotlight but im not sure theyre the issue. Heres a video, the light blue coloured blob is the dynamic spotlight i randomly created its not the problem, the problem is what seems to look like lightning flashes:
Any ideas what could be causing this? Ill provide code if needed. [Edited by - Infinite_Daremo on July 2, 2008 4:28:55 PM]
Advertisement
I think it's a hidden out-of-array-bounds error. Somewhere in your skinning (animation) code, you write to memory-space, that belongs to the lights' info variables.
Try to put some debugging code at places, where you access arrays - code, that checks what index for the array-access you'll be using.
Im gonna debug now, ill post the code here for now incase theres a more obvious error:

void CBaseModel::doRender(float posX, float posY, float posZ, int frameNum){	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);	glEnable(GL_TEXTURE_2D);	glShadeModel(GL_SMOOTH);	CVector *pointList = 0;	CVector tempVec0, tempVec1, tempVec2, normal;	pointList = &m_pModelData->pointList[ m_pModelData->numPoints * frameNum ]; // Pointer to current frame		glBindTexture( GL_TEXTURE_2D, m_pModelData->modelTex->texID );	// Render model	glBegin(GL_TRIANGLES);		for( int i = 0; i < m_pModelData->numTriangles; i++ )		{			normal = UTILITY.calculateNormal( &pointList[ m_pModelData->triIndex.meshIndex[0]], &pointList[ m_pModelData->triIndex.meshIndex[1]], &pointList[ m_pModelData->triIndex.meshIndex[2]] );			glNormal3f( normal.x, normal.y, normal.z );			// To avoid constant dereferencing			tempVec0 = pointList[ m_pModelData->triIndex.meshIndex[0]];			tempVec1 = pointList[ m_pModelData->triIndex.meshIndex[1]];			tempVec2 = pointList[ m_pModelData->triIndex.meshIndex[2]];			glTexCoord2f( m_pModelData->st[ m_pModelData->triIndex.stIndex[0]].s, m_pModelData->st[ m_pModelData->triIndex.stIndex[0]].t );			glVertex3f( tempVec0.x, tempVec0.y, tempVec0.z);			glTexCoord2f( m_pModelData->st[ m_pModelData->triIndex.stIndex[1]].s, m_pModelData->st[ m_pModelData->triIndex.stIndex[1]].t );			glVertex3f( tempVec1.x, tempVec1.y, tempVec1.z);			glTexCoord2f( m_pModelData->st[ m_pModelData->triIndex.stIndex[2]].s, m_pModelData->st[ m_pModelData->triIndex.stIndex[2]].t );			glVertex3f( tempVec2.x, tempVec2.y, tempVec2.z);		}	glEnd();}
In the vid it looks like the terrain is picking up too much shininess, a per frag shader (rather than what looks like standard vertex lighting) would eliminate the flashes.

Or you could lower the shininess, if of course that is the problem!

GLint materialShininess = 12; //try roughly in the range of 2 to 125
glMateriali( GL_FRONT, GL_SHININESS, materialShininess );
I tried rendering without the terrain as i have not bothered calculating proper normals for it yet but the problem still persists.

Also debugging at the time of the lighting errors there is no out of bound reading. Everything seems to be fine.
I cant believe i made such a dumb mistake. My normal calculation wasnt returning a reference so data it was returning was becoming jargon. All runs fine now. Thanks guys.

This topic is closed to new replies.

Advertisement