PDA

View Full Version : convert opengl to opengl with shader



giuseppe500
08-14-2011, 02:02 AM
hello.
I trying to convert a opengl 2.0 project without shader in a opengl 2.0 project with shader.
My problem is this:
I have


void RenderFrame()
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glMultMatrixf(&g_camera.getViewMatrix()[0][0]);//in g_camera.getViewMatrix() i have a correct view matrix with
//rotation's and orientation


RenderModel();// draw mesh
}
void RenderModel()
{
glPushMatrix();

m[3][0] = g_meshPosition.x;
m[3][1] = g_meshPosition.y;
m[3][2] = g_meshPosition.z;

glMultMatrixf(&m[0][0]);
.
.
.
glDrawElements(GL_TRIANGLES, pMesh->triangleCount * 3,
GL_UNSIGNED_INT, g_model.getIndexBuffer() + pMesh->startIndex);

glPopMatrix();
}

In my project i have only shader and for each shader a Model view matrix and projection matrix.
But the demo project first set the correct view matrix(that I have ) then set the position of the mesh(that i have) and then draw.

But how i can do this with shaders?

尘羽泯
08-14-2011, 03:00 AM
What is shader?

V-man
08-14-2011, 05:19 AM
//Vertex Shader
#version 110

void main()
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}




//Fragment Shader
#version 110

uniform vec4 MyColor;

void main()
{
gl_FragColor = MyColor;
}


and you can find more examples on the web.
Try to download RenderMonkey. It has many shader examples.

and also, there is an app for that
http://www.opengl.org/wiki/OpenGL_Shading_Language