Ok so before I just had one MVPMatrix and I set that to identity but now I have split that up into model, view and projection but I am unable to see my drawn object on the screen. I probably shouldnt use third party links but here is my code.
bool OGLESIntroducingPVRTools::InitView()
{
// Sets the clear color
glClearColor(0.6f, 0.8f, 1.0f, 1.0f);
//glEnable(GL_DEPTH_TEST);
CPVRTString pErrorStr;
glEnable(GL_DEPTH_TEST);
/
Load textures
/
if(!load_Tex(&pErrorStr))
{
PVRShellSet(prefExitMessage, pErrorStr.c_str());
return false;
}
//create skybox using the PVR function PVRTCreateSkyBox
/float sBox_Vertices;
float sBox_TexCoords;
PVRTCreateSkybox(500.0f, true, 512, &sBox_Vertices, &sBox_TexCoords);
glGenBuffers(1, &m_skyBoxVBO);
glBindBuffer(GL_ARRAY_BUFFER, m_skyBoxVBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 3 * 24, &sBox_Vertices[0], GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
PVRTDestroySkybox(sBox_Vertices, sBox_TexCoords);/
/
Compiles the shaders.
First we use CPVRTResourceFile to load a file into memory. After construction with a
file name, we just have to check whether the file is open or an error occured.
We load both source and binary shaders, then try the binary shader first.
The data of a CPVRTResourceFile will always be terminated with a 0 byte so it can
safely be used as a C string.
/
loadWatershader();
loadSkyShader();
// Store the location of uniforms for later use
for (int i = 0; i < eNumUniforms; ++i)
{
m_ShaderProgram.auiLoc = glGetUniformLocation(m_ShaderProgram.uiId, g_aszUniformNames);
}
//store skybox uniform
for (int i = 0; i < eSkyUniforms; ++i)
{
skyShaderProgram.auiLoc = glGetUniformLocation(skyShaderProgram.uiId, skyUniformNames);
}
glUniform1i(glGetUniformLocation(m_ShaderProgram.uiId, “sTexture”), 0);
glUniform1i(glGetUniformLocation(m_ShaderProgram.uiId, “sTexture2”), 1);
// Create VBO for the triangle from our data
// Interleaved vertex data
GLfloat sqVert[] = {
0.5f,0.5f,0.0f,
1.0f, 1.0f,//UV
-0.5f,0.5f,0.0f,
0.0f, 1.0f,//UV
0.5f,-0.5f,0.0f, //postions
1.0f, 0.0f, //UV
-0.5f, -0.5f, 0.0f,
0.0f, 0.0f,//UV
-0.5f,0.5f,0.0f,
0.0f, 1.0f,//UV
0.5f,-0.5f,0.0f,
1.0f, 0.0f //UV
};
glGenBuffers(1, &m_ui32Vbo);
m_ui32VertexStride = 5 * sizeof(GLfloat); // 3 floats for the pos, 2 for the UVs
// Bind the VBO
glBindBuffer(GL_ARRAY_BUFFER, m_ui32Vbo);
// Set the buffer’s data
glBufferData(GL_ARRAY_BUFFER, 6 * m_ui32VertexStride, sqVert, GL_STATIC_DRAW);
// Unbind the VBO
glBindBuffer(GL_ARRAY_BUFFER, 0);
return true;
//set projection matrix
bool bRotate = PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen);
p_Matrix = PVRTMat4::PerspectiveFovRH(60.0f, (float) PVRShellGet(prefWidth) / (float) PVRShellGet(prefHeight), 0.1, 1000.0f, PVRTMat4::OGL, bRotate);
v_Matrix = PVRTMat4::LookAtLH(PVRTVec3(0.0f, 0.0f, -3.0f), PVRTVec3(0.0f, 0.0f, 0.0f), PVRTVec3(0.0f, 1.0f, 0.0f));
p_Time = PVRShellGetTime();
}
bool OGLESIntroducingPVRTools::RenderScene()
{
// Clears the color and depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Binds the loaded texture
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_uiTexture[0]);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m_uiTexture[1]);
// Use the loaded shader program
glUseProgram(m_ShaderProgram.uiId);
m_Matrix = PVRTMat4::RotationX(45);
if(PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen)) // If the screen is rotated
v_Matrix = PVRTMat4::RotationZ(-1.57f);
/
Pass this matrix to the shader.
The .m field of a PVRTMat4 contains the array of float used to
communicate with OpenGL ES.
/
glUniformMatrix4fv(m_ShaderProgram.auiLoc[eMMatrix], 1, GL_FALSE, m_Matrix.ptr());
glUniformMatrix4fv(m_ShaderProgram.auiLoc[eVMatrix], 1, GL_FALSE, v_Matrix.ptr());
glUniformMatrix4fv(m_ShaderProgram.auiLoc[ePMatrix], 1, GL_FALSE, p_Matrix.ptr());
//DrawSkybox();
// Bind the VBO
glBindBuffer(GL_ARRAY_BUFFER, m_ui32Vbo);
// Pass the vertex data
glEnableVertexAttribArray(VERTEX_ARRAY);
glVertexAttribPointer(VERTEX_ARRAY, 3, GL_FLOAT, GL_FALSE, m_ui32VertexStride, 0);
// Pass the texture coordinates data
glEnableVertexAttribArray(TEXCOORD_ARRAY);
glVertexAttribPointer(TEXCOORD_ARRAY, 2, GL_FLOAT, GL_FALSE, m_ui32VertexStride, (void) (sizeof(GLfloat) * 3) / Uvs start after the position /);
// Pass the second texture coordinates data
glEnableVertexAttribArray(TEXCOORD_ARRAY2);
glVertexAttribPointer(TEXCOORD_ARRAY2, 2, GL_FLOAT, GL_FALSE, m_ui32VertexStride, (void) (sizeof(GLfloat) * 3) /* Uvs start after the position */);
// Draws a non-indexed triangle array
glDrawArrays(GL_TRIANGLES, 0, 6);
// Unbind the VBO
glBindBuffer(GL_ARRAY_BUFFER, 0);
return true;
}
and my vertex shader
//works with object
attribute highp vec4 inVertex;
attribute mediump vec3 inNormal;
attribute mediump vec2 inTexCoord;
//matrix for scene
uniform mediump mat4 model_matrix;
uniform mediump mat4 projection_matrix;
uniform mediump mat4 view_matrix;
//needed to pass tex coords to frag shader to operate on.
varying mediump vec2 TexCoord;
void main()
{
mat4 modelview = view_matrix * model_matrix;
mat4 MVPMatrix = projection_matrix * modelview;
gl_Position = MVPMatrix * inVertex;
TexCoord = inTexCoord;
}
it s pretty hard to read html code
but :
in the render , define the view properly :
1 / mView = PVRTMat4::LookAtRH(vFrom, vTo, vUp);
2/ mProjection (matrix in your case )
3/ Set up the View Projection Matrix and Set up shader uniforms
PVRTMat4 mViewProjection;<br />
mViewProjection = mProjection * mView;
```<br />
because in the vertext shader :<br />
gl_Position = ViewProjMatrix * position;<br />
<br />
if you define a world position for your node then<br />
PVRTMat4 mModelViewProj;
mModelViewProj = mViewProjection * mWorld;
and setup your shader with it<br />
<br />
david