Jump to content

  • Log In with Google      Sign In   
  • Create Account


Mockarutan

Member Since 04 Aug 2008
Offline Last Active Apr 10 2011 12:27 PM

Topics I've Started

Problem with projection matrix on openGL ES 2.0

03 April 2011 - 02:33 PM

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.

Half transparent textures in openGL ES 2.0?

04 March 2011 - 01:39 PM

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

Which is the faster one?

06 February 2011 - 01:13 PM

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 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?


So which one should i go with?


//Tobias

Problem with glDrawArray(GL10.GL_POINT, 0, 0) in opengl ES

30 January 2011 - 02:45 PM

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...


//-------------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();

//---------------

The glGetError gives me Invalis enum and invalid operation...

Unresolved external symbol...

10 May 2010 - 07:33 AM

Hi, i was just about to compile a DX9 project after I had reinstalled window7. I'm not a beginner (reading gameprogremming in school) but a got a problem that i just can't understand... When i try to comple the DX9 proj. visual studio complains about Unresolved external symbols, all of them are D3DX calls. Look at the code that includes the libs, it's correct because it have been working before:
#include "d3d9.h"
#include "d3dx9.h"

#ifdef _DEBUG
#   pragma comment(lib, "d3dx9d.lib")
#else
#   pragma comment(lib, "d3dx9.lib")
#endif

#pragma comment(lib, "d3d9.lib")
Error:
Error	1	error LNK2019: unresolved external symbol _Direct3DCreate9@4 referenced in function "public: bool __thiscall GraphicsImp::initGraphics(int,int,bool,bool,float,bool)" (?initGraphics@GraphicsImp@@QAE_NHH_N0M0@Z)	Graphics.obj

Error	2	error LNK2019: unresolved external symbol _D3DXCreateEffectFromFileA@32 referenced in function "public: bool __thiscall GraphicsImp::initShader(void)" (?initShader@GraphicsImp@@QAE_NXZ)	Graphics.obj

Error	3	error LNK2019: unresolved external symbol _D3DXMatrixMultiply@12 referenced in function "public: struct D3DXMATRIX __thiscall D3DXMATRIX::operator*(struct D3DXMATRIX const &)const " (??DD3DXMATRIX@@QBE?AU0@ABU0@@Z)	Graphics.obj

Error	4	error LNK2019: unresolved external symbol _D3DXMatrixLookAtLH@16 referenced in function "private: void __thiscall GraphicsImp::configCamera(void)" (?configCamera@GraphicsImp@@AAEXXZ)	Graphics.obj

Error	5	error LNK2001: unresolved external symbol _D3DXMatrixLookAtLH@16	Camera.obj

Error	6	error LNK2019: unresolved external symbol _D3DXMatrixPerspectiveFovLH@20 referenced in function "private: void __thiscall GraphicsImp::configProjection(void)" (?configProjection@GraphicsImp@@AAEXXZ)	Graphics.obj

Error	7	error LNK2019: unresolved external symbol _D3DXMatrixTranslation@16 referenced in function "private: void __thiscall GraphicsImp::configStdPresentValues(void)" (?configStdPresentValues@GraphicsImp@@AAEXXZ)	Graphics.obj

Error	8	error LNK2019: unresolved external symbol _D3DXMatrixScaling@16 referenced in function "private: void __thiscall GraphicsImp::configStdPresentValues(void)" (?configStdPresentValues@GraphicsImp@@AAEXXZ)	Graphics.obj

Error	9	error LNK2019: unresolved external symbol _D3DXMatrixRotationY@8 referenced in function "private: void __thiscall GraphicsImp::configStdPresentValues(void)" (?configStdPresentValues@GraphicsImp@@AAEXXZ)	Graphics.obj

Error	10	error LNK2019: unresolved external symbol _D3DXMatrixRotationX@8 referenced in function "private: void __thiscall GraphicsImp::configStdPresentValues(void)" (?configStdPresentValues@GraphicsImp@@AAEXXZ)	Graphics.obj

Error	11	error LNK2019: unresolved external symbol _D3DXCreateFontA@48 referenced in function "private: void __thiscall GraphicsImp::configFpsCounter(void)" (?configFpsCounter@GraphicsImp@@AAEXXZ)	Graphics.obj

Error	12	error LNK2019: unresolved external symbol _D3DXMatrixRotationZ@8 referenced in function "public: void __thiscall GraphicsImp::renderObjects(class std::list<class Entity *,class std::allocator<
class Entity *> >)" (?renderObjects@GraphicsImp@@QAEXV?$list@PAVEntity@@V?$allocator@PAVEntity@@@std@@@std@@@Z)	Graphics.obj

Error	13	error LNK2019: unresolved external symbol _D3DXCreateTextureFromFileA@12 referenced in function "public: bool __thiscall GraphicsImp::setBackground(class std::basic_string<
char,struct std::char_traits<char>,class std::allocator<char> >)" (?setBackground@GraphicsImp@@QAE_NV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)	Graphics.obj

Error	14	error LNK2019: unresolved external symbol _D3DXVec2Normalize@8 referenced in function "public: void __thiscall Entity::tractor(class Entity *)" (?tractor@Entity@@QAEXPAV1@@Z)	Entity.obj

Error	15	error LNK2001: unresolved external symbol _D3DXVec2Normalize@8	Ship.obj

Error	16	fatal error LNK1120: 13 unresolved externals
I know that this problem is caused be the linker, when it can't link a function call to it's defenition. But I got all the DX9 lib files included in VC++ Direcories, i even placed the required lib files inside the proj. folder... What have a missed? Thanks in advanced!

PARTNERS