Hello,
Ive recently been asked to add shader functionality to a small project, and i must admit im a bit lost when it comes to shaders. Currently i have 2 functions for rendering:
renderWithShaders()
renderWithoutShaders()
the core render() call works out if shaders are being used and then uses the correct function…
This is where my problem comes in, ive got a basic cube that i use for testing everything but when i use CG shaders it doesn’t display, although im not sure if its down to the matrix, the position or me not writing it correctly…
Im just testing what i thought was a basic shader, and it wont work, where i send over position/color and want to just display it on the screen, however it wont…
Here is a quick code example of what im doing in both methods…
- Without Shaders -
gl.glPushMatrix();
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glTranslatef(vPosition.fX, vPosition.fY, vPosition.fZ);
gl.glBegin(gl.GL_QUADS);
gl.glColor3f(0.0f,1.0f,0.0f);
gl.glVertex3f(vVerts[0].fX, vVerts[0].fY, vVerts[0].fZ); // Top Right Of The Quad (Top)
gl.glVertex3f(vVerts[1].fX, vVerts[1].fY, vVerts[1].fZ); // Top Left Of The Quad (Top)
gl.glVertex3f(vVerts[2].fX, vVerts[2].fY, vVerts[2].fZ); // Bottom Left Of The Quad (Top)
gl.glVertex3f(vVerts[3].fX, vVerts[3].fY, vVerts[3].fZ); // Bottom Right Of The Quad (Top)
gl.glEnd();
gl.glDisable(GL.GL_DEPTH_TEST);
gl.glPopMatrix();
- With Shaders -
CgGL.cgGLEnableProfile(jlRenderer.getVertexShaderProfile());
jlRenderer.CheckCgError();
CgGL.cgGLBindProgram(cgpVertexProgram);
jlRenderer.CheckCgError();
if(ModelViewProjParam != null)
{
CgGL.cgGLSetStateMatrixParameter(ModelViewProjParam,
CgGL.CG_GL_MODELVIEW_PROJECTION_MATRIX, CgGL.CG_GL_MATRIX_IDENTITY);
jlRenderer.CheckCgError();
}
gl.glPushMatrix();
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glTranslatef(vPosition.fX, vPosition.fY, vPosition.fZ);
gl.glBegin(GL.GL_QUADS);
CgGL.cgGLSetParameter3f(VertColor, 0.0f,1.0f,0.0f);
gl.glVertex3f(vVerts[0].fX, vVerts[0].fY, vVerts[0].fZ); // Top Right Of The Quad (Top)
gl.glVertex3f(vVerts[1].fX, vVerts[1].fY, vVerts[1].fZ); // Top Left Of The Quad (Top)
gl.glVertex3f(vVerts[2].fX, vVerts[2].fY, vVerts[2].fZ); // Bottom Left Of The Quad (Top)
gl.glVertex3f(vVerts[3].fX, vVerts[3].fY, vVerts[3].fZ); // Bottom Right Of The Quad (Top)
gl.glEnd();
gl.glDisable(GL.GL_DEPTH_TEST);
gl.glPopMatrix();
CgGL.cgGLDisableProfile(jlRenderer.getVertexShaderProfile());
jlRenderer.CheckCgError();
- Shader File -
// input vertex
struct VertIn {
float4 position : POSITION;
float4 color : COLOR0;
};
// output vertex
struct VertOut {
float4 position : POSITION;
float4 color : COLOR0;
};
// vertex shader main entry
VertOut main(VertIn IN, uniform float4x4 modelViewProj)
{
VertOut OUT;
OUT.position = mul(modelViewProj,IN.position);
OUT.color = IN.color;
return OUT;
}
Any help would be great, im a tad confused as it if CG gets the position var from the glVertex3f() call or if i have to manually pass over the parameter like done with the colour. I just want a shader for now that emulates the normal renderWithoutShader(), so it basically renders the data via CG and not OGL, i dont want any fancy effects for now…
Thanks for any help,
Grofit