Jump to content
  • Advertisement
Sign in to follow this  
AnujKalia

OpenGL Vertes Shader: No texture

This topic is 2478 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! I'm using Cal3D and they have given a nice vertex shader for animation in the hardware.

The animation's working fine. However, the models are appearing blank, i.e. no texture. The code only has a vertex shader (in GLSL assembly I guess).

I'm new to this. Could someone please help. I've attached some code:

/*VERTEX SHADER IN ASSEMBLY*/
char vertexProgramStr[]=
"!!ARBvp1.0\n"\
"PARAM constant = { 1, 3, 0, 0 };\n"\
"TEMP R0, R1, R2, R3, R4, R5;\n"\
"ADDRESS A0;\n"\
"ATTRIB texCoord = vertex.attrib[4];\n"\
"ATTRIB normal = vertex.attrib[2];\n"\
"ATTRIB index = vertex.attrib[3];\n"\
"ATTRIB weight = vertex.attrib[1];\n"\
"ATTRIB position = vertex.attrib[0];\n"\
"PARAM worldViewProjMatrix[4] = { state.matrix.mvp };\n"\
"PARAM diffuse = state.material.diffuse;\n"\
"PARAM ambient = state.material.ambient;\n"\
"PARAM lightDir = state.light[0].position;\n"\
"PARAM matrix[87] = { program.local[0..86] };\n"\
"\n"\
"MOV result.texcoord[0].xy, texCoord.xyxx; \n"\
"\n"\
"MUL R4, index, constant.y; \n"\
"\n"\
"ARL A0.x, R4.y;\n"\
"DP3 R0.x, matrix[A0.x].xyzx, normal.xyzx;\n"\
"DP3 R0.y, matrix[A0.x + 1].xyzx, normal.xyzx;\n"\
"DP3 R0.z, matrix[A0.x + 2].xyzx, normal.xyzx;\n"\
"MUL R1.yzw, R0.xxyz, weight.y;\n"\
"\n"\
"ARL A0.x, R4.x;\n"\
"DP3 R0.x, matrix[A0.x].xyzx, normal.xyzx;\n"\
"DP3 R0.y, matrix[A0.x + 1].xyzx, normal.xyzx;\n"\
"DP3 R0.z, matrix[A0.x + 2].xyzx, normal.xyzx;\n"\
"MAD R1.yzw, R0.xxyz, weight.x, R1.yyzw;\n"\
"\n"\
"DP3 R0.x, R1.yzwy, R1.yzwy;\n"\
"RSQ R0.x, R0.x;\n"\
"MUL R0.xyz, R0.x, R1.yzwy;\n"\
"DP3 R1.x, lightDir.xyzx, lightDir.xyzx;\n"\
"RSQ R1.x, R1.x;\n"\
"MUL R2.xyz, R1.x, lightDir.xyzx;\n"\
"DP3 R0.x, R0.xyzx, R2.xyzx;\n"\
"MAX R0.x, R0.x, constant.z;\n"\
"ADD R0, R0.x, ambient;\n"\
"MUL result.color.front.primary, R0, diffuse;\n"\
"\n"\
"ARL A0.x, R4.w;\n"\
"DPH R0.x, position.xyzx, matrix[A0.x];\n"\
"DPH R0.y, position.xyzx, matrix[A0.x + 1];\n"\
"DPH R0.z, position.xyzx, matrix[A0.x + 2];\n"\
"\n"\
"ARL A0.x, R4.z;\n"\
"DPH R3.x, position.xyzx, matrix[A0.x];\n"\
"DPH R3.y, position.xyzx, matrix[A0.x + 1];\n"\
"DPH R3.z, position.xyzx, matrix[A0.x + 2];\n"\
"\n"\
"ARL A0.x, R4.y;\n"\
"DPH R1.y, position.xyzx, matrix[A0.x];\n"\
"DPH R1.z, position.xyzx, matrix[A0.x + 1];\n"\
"DPH R1.w, position.xyzx, matrix[A0.x + 2];\n"\
"MUL R2.xyz, R1.yzwy, weight.y;\n"\
"\n"\
"ARL A0.x, R4.x;\n"\
"DPH R1.x, position.xyzx, matrix[A0.x];\n"\
"DPH R1.y, position.xyzx, matrix[A0.x + 1];\n"\
"DPH R1.z, position.xyzx, matrix[A0.x + 2];\n"\
"\n"\
"MAD R1.xyz, R1.xyzx, weight.x, R2.xyzx;\n"\
"MAD R1.xyz, R3.xyzx, weight.z, R1.xyzx;\n"\
"MAD R0.xyz, R0.xyzx, weight.w, R1.xyzx;\n"\
"\n"\
"DPH result.position.x, R0.xyzx, worldViewProjMatrix[0];\n"\
"DPH result.position.y, R0.xyzx, worldViewProjMatrix[1];\n"\
"DPH result.position.z, R0.xyzx, worldViewProjMatrix[2];\n"\
"DPH result.position.w, R0.xyzx, worldViewProjMatrix[3];\n"\
"END\n";




// Render the mesh of the model
void Model::renderMesh( bool bLight)
{
glBindProgramARB( GL_VERTEX_PROGRAM_ARB, m_vertexProgramId );
glEnableVertexAttribArrayARB(0);
glEnableVertexAttribArrayARB(1);
glEnableVertexAttribArrayARB(2);
glEnableVertexAttribArrayARB(3);
glEnableVertexAttribArrayARB(4);
glEnable(GL_TEXTURE_2D);
// set global OpenGL states
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_VERTEX_PROGRAM_ARB);

glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_bufferObject[0]);
glVertexAttribPointerARB(0, 3 , GL_FLOAT, false, 0, NULL);

glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_bufferObject[1]);
glVertexAttribPointerARB(1, 4 , GL_FLOAT, false, 0, NULL);

glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_bufferObject[2]);
glVertexAttribPointerARB(2, 3 , GL_FLOAT, false, 0, NULL);

glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_bufferObject[3]);
glVertexAttribPointerARB(3, 4 , GL_FLOAT, false, 0, NULL);

glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_bufferObject[4]);
glVertexAttribPointerARB(4, 2 , GL_FLOAT, false, 0, NULL);

glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, m_bufferObject[5]);

int hardwareMeshId;
for(hardwareMeshId=0;hardwareMeshId<m_calHardwareModel->getHardwareMeshCount() ; hardwareMeshId++)
{
m_calHardwareModel->selectHardwareMesh(hardwareMeshId);
unsigned char meshColor[4];
float materialColor[4];
/* set the material ambient color
m_calHardwareModel->getAmbientColor(&meshColor[0]);
materialColor[0] = meshColor[0] / 255.0f; materialColor[1] = meshColor[1] / 255.0f; materialColor[2] = meshColor[2] / 255.0f; materialColor[3] = meshColor[3] / 255.0f;
glMaterialfv(GL_FRONT, GL_AMBIENT, materialColor);

// set the material diffuse color
m_calHardwareModel->getDiffuseColor(&meshColor[0]);
materialColor[0] = meshColor[0] / 255.0f; materialColor[1] = meshColor[1] / 255.0f; materialColor[2] = meshColor[2] / 255.0f; materialColor[3] = meshColor[3] / 255.0f;
glMaterialfv(GL_FRONT, GL_DIFFUSE, materialColor);

// set the material specular color
m_calHardwareModel->getSpecularColor(&meshColor[0]);
materialColor[0] = meshColor[0] / 255.0f; materialColor[1] = meshColor[1] / 255.0f; materialColor[2] = meshColor[2] / 255.0f; materialColor[3] = meshColor[3] / 255.0f;
glMaterialfv(GL_FRONT, GL_SPECULAR, materialColor);

// set the material shininess factor
float shininess;
shininess = 50.0f; //m_calHardwareModel->getShininess();
glMaterialfv(GL_FRONT, GL_SHININESS, &shininess);*/

int boneId;
for(boneId = 0; boneId < m_calHardwareModel->getBoneCount(); boneId++)
{
CalQuaternion rotationBoneSpace = m_calHardwareModel->getRotationBoneSpace(boneId, m_calModel->getSkeleton());
CalVector translationBoneSpace = m_calHardwareModel->getTranslationBoneSpace(boneId, m_calModel->getSkeleton());
CalMatrix rotationMatrix = rotationBoneSpace;

float transformation[12];

transformation[0]=rotationMatrix.dxdx;transformation[1]=rotationMatrix.dxdy;transformation[2]=rotationMatrix.dxdz;transformation[3]=translationBoneSpace.x;
transformation[4]=rotationMatrix.dydx;transformation[5]=rotationMatrix.dydy;transformation[6]=rotationMatrix.dydz;transformation[7]=translationBoneSpace.y;
transformation[8]=rotationMatrix.dzdx;transformation[9]=rotationMatrix.dzdy;transformation[10]=rotationMatrix.dzdz;transformation[11]=translationBoneSpace.z;

glProgramLocalParameter4fvARB(GL_VERTEX_PROGRAM_ARB,boneId*3,&transformation[0]);
glProgramLocalParameter4fvARB(GL_VERTEX_PROGRAM_ARB,boneId*3+1,&transformation[4]);
glProgramLocalParameter4fvARB(GL_VERTEX_PROGRAM_ARB,boneId*3+2,&transformation[8]);

// set the texture id we stored in the map user data
glBindTexture(GL_TEXTURE_2D, 1);//(GLuint)m_calHardwareModel->getMapUserData(0));
}
if(sizeof(CalIndex)==2)
glDrawElements(GL_TRIANGLES, m_calHardwareModel->getFaceCount() * 3, GL_UNSIGNED_SHORT, (((CalIndex *)NULL)+ m_calHardwareModel->getStartIndex()));
else
glDrawElements(GL_TRIANGLES, m_calHardwareModel->getFaceCount() * 3, GL_UNSIGNED_INT, (((CalIndex *)NULL)+ m_calHardwareModel->getStartIndex()));
}

// clear vertex array state

glDisableVertexAttribArrayARB(0);
glDisableVertexAttribArrayARB(1);
glDisableVertexAttribArrayARB(2);
glDisableVertexAttribArrayARB(3);
glDisableVertexAttribArrayARB(4);

glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);

glDisable(GL_VERTEX_PROGRAM_ARB);
glBindProgramARB( GL_VERTEX_PROGRAM_ARB, 0 );
}

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!