Mockarutan

Members
  • Content count

    35
  • Joined

  • Last visited

Community Reputation

122 Neutral

About Mockarutan

  • Rank
    Member
  1. 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. [code] //================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"); [/code] Thanks in advance! EDIT: I just solved it, I had to put the position of the floatbuffer that holds the matrix to 0.
  2. [quote name='V-man' timestamp='1299269106' post='4781855'] [quote name='Mockarutan' timestamp='1299267556' post='4781846'] I can't figure out how to do normal alpha testing in openGL ES 2.0 on the android platform. I have tried to setup the blending factors exactly like in ES 1.1 where i get it to work, but in 2.0 it doesn't do a difference. I know that ES 2.0 is completely shader based and you are suppose to achieve many blending effects in the shader, but from what i have understood you can only to fully transparent stuff with the "discard" syntax in the shader. (unless you use multi texturing and blend the two textures together with some formula, but thats not blending with the render target.). So what am i missing here? Thanx for any help! //Tobias [/quote] Isn't there glEnable(GL_BLEND) and glBlendFunc in OpenGL ES? [/quote] It works.... I'm embarrassed xD I guess i misunderstood a text a reed in an openGL ES 2.0 book: [quote] Alpha test and LogicOp are no longer part of the per-fragment operations stage. These two stages exist in OpenGL 2.0 and OpenGL ES 1.x. The alpha test stage is no longer needed because the fragment shader can discard fragments and therefore the alpha test can be performed in the fragment shader. In addition, LogicOp is removed as it is very infrequently used by applications and the OpenGL ES working group did not get requests from independent software vendors (ISVs) to support this feature in OpenGL ES 2.0. [/quote] Thanx!
  3. I can't figure out how to do normal alpha testing in openGL ES 2.0 on the android platform. I have tried to setup the blending factors exactly like in ES 1.1 where i get it to work, but in 2.0 it doesn't do a difference. I know that ES 2.0 is completely shader based and you are suppose to achieve many blending effects in the shader, but from what i have understood you can only to fully transparent stuff with the "discard" syntax in the shader. (unless you use multi texturing and blend the two textures together with some formula, but thats not blending with the render target.). So what am i missing here? Thanx for any help! //Tobias
  4. [size="2"]So I'm currently researching how to optimize my graphics code on the android platform, running on a Legend. I'm right now trying to[font="Arial, Helvetica, sans-serif"] determine which of the two techniques are the faster for drawing sprites that is changing in position and texture coordinates almost every frame. Using a VBO and calling glBufferData to copy new data to the VRAM every frame, or just filling in a FloatBuffer and setting the vertex pointer to that buffer every frame. In my benchmarks i didn't notice any big change in frame rate. Is there even a difference? I mean in the end everything comes down to the transfer between the RAM and VRAM. Right?[/font] [font="Arial, Helvetica, sans-serif"] [/font] [font="Arial, Helvetica, sans-serif"]So which one should i go with?[/font] [font="Arial, Helvetica, sans-serif"] [/font] [font="Arial, Helvetica, sans-serif"]//Tobias [/font][/size]
  5. [quote name='V-man' timestamp='1296504832' post='4767636'] The things that could effect color is texture and lighting. So disable texturing and lighting. [/quote] Did not work, thanks for the tip though... Edit: I cracked it! It was the texturing Thanks!
  6. I have tried everything now. The closest i get is to draw the points black at the correct position, but they should be red. [code] //------------sets up the color array----------------- ByteBuffer cbb = ByteBuffer.allocateDirect((int)MAXQUADS * 4 * 4); cbb.order(ByteOrder.nativeOrder()); mColorArray = cbb.asFloatBuffer(); float[] temp = {0.0f, 0.0f, 0.0f, 1.0f}; for(int i = 0; i < MAXQUADS; i++) mColorArray.put(temp); //-------------render func-------------------------- gl.glClearColor(mR, mG, mB, 1.0f); gl.glClear(GL10.GL_COLOR_BUFFER_BIT); mVertexBuffer.position(0); int error; gl11.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY); gl11.glEnable(GL11.GL_POINT_SMOOTH); gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, vertexBufferIndex2); gl11.glVertexPointer(3, GL11.GL_FLOAT, 0, 0); error = gl11.glGetError(); if(error == GL11.GL_INVALID_ENUM) Log.i(TAG, "Invalid enum1"); else if(error == GL11.GL_INVALID_VALUE) Log.i(TAG, "Invalid value1"); else if(error == GL11.GL_INVALID_OPERATION) Log.i(TAG, "Invalid operation1"); gl11.glEnableClientState(GL10.GL_COLOR_ARRAY); gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, 0); gl11.glColorPointer(4, GL10.GL_FLOAT, 0, mColorArray); error = gl11.glGetError(); if(error == GL11.GL_INVALID_ENUM) Log.i(TAG, "Invalid enum2"); else if(error == GL11.GL_INVALID_VALUE) Log.i(TAG, "Invalid value2"); else if(error == GL11.GL_INVALID_OPERATION) Log.i(TAG, "Invalid operation2"); error = gl11.glGetError(); if(error == GL11.GL_INVALID_ENUM) Log.i(TAG, "Invalid enum3"); else if(error == GL11.GL_INVALID_VALUE) Log.i(TAG, "Invalid value3"); else if(error == GL11.GL_INVALID_OPERATION) Log.i(TAG, "Invalid operation3"); gl.glPushMatrix(); gl.glTranslatef(5, 1.0f * 5, 0f); gl11.glDrawArrays(GL11.GL_POINTS, 0, 4); gl.glPopMatrix(); error = gl11.glGetError(); if(error == GL11.GL_INVALID_ENUM) Log.i(TAG, "Invalid enum4"); else if(error == GL11.GL_INVALID_VALUE) Log.i(TAG, "Invalid value4"); else if(error == GL11.GL_INVALID_OPERATION) Log.i(TAG, "Invalid operation4"); gl.glDisableClientState(GL10.GL_COLOR_ARRAY); gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY); [/code] I'm very greatful for any help. Been stuck on this crap for 2 days now
  7. Can somebody show me code that works for drawing points? Even if it doesn't use VBO's...
  8. [quote name='karwosts' timestamp='1296420569' post='4767154'] Can you narrow down which line gives you the error? [/quote] gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, vertexBufferIndex2); gl11.glVertexPointer(3, GL11.GL_FLOAT, 0, 0); error = gl11.glGetError(); This gives me invalid operation.. but my enum problem has disappeared...
  9. I have i problem with opengl ES on android. I am trying to draw some simple points from a VBO with and a color array that a guess is a VBO too in a way? The thing is that this doesn't work at all... I know that the VBO (vertexBufferIndex2) is correct, because i normaly use it to draw quads, but i'm not so sure about the color array... so can you see any problem with this code? I'm testing it on a legend btw... [code] //-------------setup stuff in another funtion----------- ByteBuffer cbb = ByteBuffer.allocateDirect((int)MAXQUADS * 4 * 3); cbb.order(ByteOrder.nativeOrder()); mColorArray = cbb.asFloatBuffer(); float[] temp = {1.0f, 0.0f, 0.0f}; for(int i = 0; i < MAXQUADS; i++) mColorArray.put(temp); mColorArray.position(0); gl11.glGenBuffers(1, buffer, 0); colorArrayIndex = buffer[0]; gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, colorArrayIndex); gl11.glBufferData(GL11.GL_ARRAY_BUFFER, (int) (MAXQUADS * 4 * 3), mColorArray, GL11.GL_STATIC_DRAW); //-----------end of setup func---------- //-----------the following code is inside the draw func in openGL-------------- gl11.glEnableClientState(GL10.GL_COLOR_ARRAY); gl11.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY); gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, vertexBufferIndex2); gl11.glVertexPointer(3, GL11.GL_FLOAT, 0, 0); gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, colorArrayIndex); gl11.glColorPointer(3, GL11.GL_FLOAT, 0, 0); gl.glPushMatrix(); gl.glTranslatef(temp, 1.0f * (float)i, 0f); gl11.glDrawArrays(GL11.GL_POINTS, 0, 4); int error = gl11.glGetError(); if(error == GL11.GL_INVALID_ENUM) Log.i(TAG, "Invalid enum"); else if(error == GL11.GL_INVALID_VALUE) Log.i(TAG, "Invalid value"); else if(error == GL11.GL_INVALID_OPERATION) Log.i(TAG, "Invalid operation"); gl.glPopMatrix(); //--------------- [/code] The glGetError gives me Invalis enum and invalid operation...