GL Modelview, 2D Sprites and GL ES 2.0 woes :) Please help!!!

Apprentice
Posts: 9
Joined: 2010.04
Post: #1
Hiya Guys Wow

First Lemme introduce myself!

My name is Ivan, I have been a long time fan of iDevGames. I used to read this page from the time the site development was exclusive to the mac as a platform so im an old guy Rasp

I used to be a full blown game developer but moved on to a managerial position a few years back. I used to work with opengl 1.4 a long time ago Smile The advent of shaders did not hit me until recenlty

I am excited as heck to be back at development but I am completely stuck on the new way of doing things in gles that is, the not having all those fixed function pipeline commands I used to work with!

Right now by myself I taught myself how to load geometry on screen using vertexpointers and draw them using a basic shader...

I am stuck with the concept of the ModelView and Projection Matrix but on GLES 2.0
This is what I understand so far... (please correct me if im wrong)
I know the modelview is the matrix of the geometry itself; it what you basically used when did all those gltrans,glrotates and glscales back in the day.

Code:
matrix4 m_Modelview;
m_Modelview.rotate(somevector);
m_Modelview.translate(somevector);
m_Modelview.rotate(somevector);

The camera is the projection matrix I believe and the way to accurately display a model is via multiplication of the projection matrix by the modelview in order to accurately display the model on the screen taking into consideration where the projection is...

Code:
m_Projection * m_Modelview  = mMVP

Feed the matrix to the shader
glUniformMatrix4fv(m_pShaderPrograms[0].auiLoc[0], 1, GL_FALSE, mMVP.f)


I think this makes sense, but im stuck at the sprite part of the deal now...

I need to draw a nice hud but I do not know how to switch modes in order to display the hud on the screen.

I downloaded apple's own GLSprite Sample Code but that is working on GLES 1.1 so im out of luck there. I looked at their code abit and have tried to reinterpret the code into gles2 so far I got

Code:
//-- Their Code
    // Sets up matrices and transforms for OpenGL ES
    glViewport(0, 0, backingWidth, backingHeight);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrthof(-1.0f, 1.0f, -1.5f, 1.5f, -1.0f, 1.0f);
    glMatrixMode(GL_MODELVIEW);

// which would mean?
    Matrix4 result;
        glViewport(0, 0, backingWidth, backingHeight);
        m_CurrentProjection = Matrix4::Identity();
        Matrix4 m_Ortho = func(Run my ortho matrix creation routine here)
        result = m_CurrentProjection * m_Ortho;

        then finally feed into shader
        Feed the matrix to the shader
        glUniformMatrix4fv(m_pShaderPrograms[0].auiLoc[0], 1, GL_FALSE, mMVP.f)

m_pShaderPrograms[0].auiLoc[0] is basically:
Code:
glGetUniformLocation(m_pShaderPrograms[0].uiId, "myMVPMatrix");

My vertex shader code is (based on the pvr sdk for displaying text)

Code:
attribute highp vec4    myVertex;
attribute mediump vec2    myUV;

uniform highp mat4        myMVPMatrix;
varying mediump vec2    texCoord;
void main()
{
    gl_Position = myMVPMatrix * myVertex;
    texCoord = myUV.st;
}

So to finish telling you about my problem; my Current Rendering Code is the following: (again I am using PVRTools for their great matrix and vector stuff)

Code:
- (void) initialize{
   // initialize stuff....
   // also this the geometry i want to display:
   /*
    GLfloat basicGeometry[8];    
    GLshort basicTexcoord[8];

        basicGeometry[0] = -0.5f;
        basicGeometry[1] = -0.5f;
        basicGeometry[2] =  0.5f;
        basicGeometry[3] = -0.5f;
        basicGeometry[4] = -0.5f;
        basicGeometry[5] =  0.5f;
        basicGeometry[6] =  0.5f;
        basicGeometry[7] =  0.5f;

        
        basicTexcoord[0] = 0;
        basicTexcoord[1] = 0;
        basicTexcoord[2] = 1;
        basicTexcoord[3] = 0;
        basicTexcoord[4] = 0;
        basicTexcoord[5] = 1;
        basicTexcoord[6] = 1;
        basicTexcoord[7] = 1;

       the above would be the same as :

         const GLfloat spriteVertices[] = {
                    -0.5f, -0.5f,
                      0.5f, -0.5f,
                    -0.5f,  0.5f,
                      0.5f,  0.5f,
                };

// Sets up an array of values for the texture coordinates.
const GLshort spriteTexcoords[] = {
0, 0,
1, 0,
0, 1,
1, 1,
};

*/

      [self loadshaders];
      [self loadtextures];

     //finally load geometry data
    glGenBuffers(1, &vbo);
    
    // Load vertex index data into buffer object
    
    // Bind the VBO
    glBindBuffer(GL_ARRAY_BUFFER, vbo);
        glBufferData(GL_ARRAY_BUFFER, sizeof(basicGeometry), basicGeometry, GL_STATIC_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER, 0);

}
- (void) render{
glUseProgram(m_pShaderProgram.uiId);

PVRTMat4 finalMatrix,mModelView,mMVP;
    
finalMatrix = PVRTMat4::Identity();
    
finalMatrix = finalMatrix * [[CameraManager sharedInstance] getProjectionMatrix];
finalMatrix = finalMatrix * [[CameraManager sharedInstance] getOrthogonalFrame];
glUniformMatrix4fv(m_pShaderProgram.auiLoc[0], 1, GL_FALSE, finalMatrix.f);    

    glBindTexture(GL_TEXTURE_2D, texture);
    glBindBuffer(GL_ARRAY_BUFFER, vbo);
    // Enable the vertex attribute arrays
    glEnableVertexAttribArray(0);
    glEnableVertexAttribArray(1);

    glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, basicGeometry);
    glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, basicTexcoord);

    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

    glDisableVertexAttribArray(0);
    glDisableVertexAttribArray(1);

}


I have not been able to get anything on screen and I really dont know what to do to continue Blush

If you can give me hand I would really appreciate it Grin!
Also, If you know of a good tutorial on gles 2.0 transformations please post the link; I only find bits and piece scattered on the internet Sad

I found this page and it has helped a lot Smile

http://www.songho.ca/opengl/gl_transform.html

but I still need help!

Thanks a lot for your attention
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #2
Hi Ivan, glad you finally joined in! Grin

There's a lot of stuff in your post and I'm a wee limited on time, but I caught this:

jeckil Wrote:This is what I understand so far... (please correct me if im wrong)
I know the modelview is the matrix of the geometry itself; it what you basically used when did all those gltrans,glrotates and glscales back in the day.
Yeah, pretty much.

jeckil Wrote:The camera is the projection matrix I believe...
No. There is no "camera" in OpenGL. The concept of the projection matrix being there throws off everyone at first (including me). You don't touch the projection matrix for anything other than the projection. The modelview matrix is used for the "camera" instead. The "camera" if you were to say there was one, is always pointing down the negative Z axis. It never moves. Right, the "camera" never moves. Instead, what you do is translate and rotate the entire scene in reverse at the beginning of your frame so that everything in the scene is moved around the camera. This seems totally counterintuitive at first, but it really does make sense after you think about it long enough Wink

Personally, I haven't jumped into ES 2 yet, so I can't really address any specifics with that.
Quote this message in a reply
Member
Posts: 166
Joined: 2009.04
Post: #3
if you have Img Tech's tools installed then you should have their example apps for GLES 2.0 which contain just about everything you would want ( they have an example of a triangle rendered in normalized viewport coordinates)
Quote this message in a reply
Apprentice
Posts: 9
Joined: 2010.04
Post: #4
warmi Wrote:if you have Img Tech's tools installed then you should have their example apps for GLES 2.0 which contain just about everything you would want ( they have an example of a triangle rendered in normalized viewport coordinates)

Oh really?? I did not notice this Rasp hmm Ill have to check it out with more detail.
Quote this message in a reply
Apprentice
Posts: 9
Joined: 2010.04
Post: #5
omg im such a moron Rasp

The first sample has all I need Rasp hahah Thanks for pointing this out!
Quote this message in a reply
Member
Posts: 241
Joined: 2008.07
Post: #6
jeckil Wrote:Oh really?? I did not notice this Rasp hmm Ill have to check it out with more detail.

Could I get a link to said tools please?
Quote this message in a reply
Member
Posts: 166
Joined: 2009.04
Post: #7
bmantzey Wrote:Could I get a link to said tools please?

http://www.imgtec.com/powervr/insider/powervr-sdk.asp
Quote this message in a reply
Post Reply