Problem with projection matrix on openGL ES 2.0

Started by
-1 comments, last by Mockarutan 13 years ago
I have a problem with a projection matrix that does not work, I'm developing the code to Android. The thing is that it has worked before, when i wrote it in native code ©, but now when i have converted the code to java (in the GDX lib) it does not work and cant see the problem. But if a render it without the project matrix used, it works and the "screenspace" becomes -1.0 -> 1.0 in both x and y, and that's what i dont want... So below i have the code related to the matrix stuff, (if you need all the code, i can give you that too, but o don't think is necessary), and just so you know, I'm able to locate all the attributes correctly.


//================startup code================


private final String gVertexShader =
"attribute vec4 vPosition; \n"+
"attribute vec2 vTexCoord; \n"+
"varying vec2 v_texCoord; \n"+
"uniform mat4 m_projectionMat; \n"+
"void main() { \n"+
" vec4 position = vec4(vPosition.x, vPosition.y, -1., 1.);\n"+
" gl_Position = vPosition * m_projectionMat; \n"+
" v_texCoord = vTexCoord; \n"+
"} \n";

//............

private final short indecisData [] = { 0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7 };
private final float staticQuadData[] = { -10.0f, -10.0f, // Position 0
-10.0f, 10.0f,// Position 1
10.0f, 10.0f, // Position 2
10.0f, -10.0f, // Position 3 };


private final float projMatrixData[] = {2.0f/mSpaceW, 0.0f, 0.0f, 0.0f,
0.0f, 2.0f/(mSpaceW / mScnR), 0.0f, 0.0f,
0.0f, 0.0f, -2.0f, -1.0f,
0.0f, 0.0f, 0.0f, 1.0f };


//.........


ByteBuffer vbb = ByteBuffer.allocateDirect(64);
vbb.order(ByteOrder.nativeOrder());
mProjMatrix = vbb.asFloatBuffer();

mProjMatrix.put(projMatrixData);

//.........

// ==================The render function========================


Gdx.gl.glClear(Gdx.gl20.GL_COLOR_BUFFER_BIT);
checkGlError("glClear");

Gdx.gl20.glUseProgram(gProgram);
checkGlError("glUseProgram");
Gdx.gl20.glBlendFunc(Gdx.gl20.GL_SRC_ALPHA, Gdx.gl20.GL_ONE_MINUS_SRC_ALPHA);

Gdx.gl20.glUniformMatrix4fv(mS1ProjMatrixHandle, 1, false, mProjMatrix);

Gdx.gl20.glBindBuffer(Gdx.gl20.GL_ARRAY_BUFFER, mQuadVBO);
checkGlError("glBindBuffer");
Gdx.gl20.glEnableVertexAttribArray(mS1PosHandle);
checkGlError("glEnableVertexAttribArray");

Gdx.gl20.glVertexAttribPointer(mS1PosHandle, 2, Gdx.gl20.GL_FLOAT, false, 0, 0);
checkGlError("glVertexAttribPointer");

Gdx.gl20.glDrawElements(Gdx.gl20.GL_TRIANGLES, 6, Gdx.gl20.GL_UNSIGNED_SHORT, tempShortBuf);
checkGlError("glDrawArrays");


Thanks in advance!

EDIT: I just solved it, I had to put the position of the floatbuffer that holds the matrix to 0.

This topic is closed to new replies.

Advertisement