Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 12 Oct 2009
Offline Last Active Dec 20 2014 08:51 PM

Topics I've Started

Invert the y axis

23 November 2014 - 01:41 AM



I created the Orthogonal Projection with this matrix:

2.0f/(right-left)             0                            0                -((right+left)/(right-left))
       0                2.0f/(top-bottom)                  0                -((top+bottom)/(top-bottom))
       0                      0                       -2.0f/(zf-zn)             -((zf+zn)/(zf-zn))
       0                      0                            0                             1

I call the function on this way:

OrthoProjection(&projection, 0, width, height, 0, -1.0f, 1.0f);

And I want to invert the y-axis.


I'm looking for another solution because I don't want to multiply the projection matrix by scale matrix (1.0f, -1.0f, 1.0f)


How can I do it???


Thanks advance.



Correct order to multiply matrices in 2D space

20 November 2014 - 11:42 PM

Hi everybody,

What is the correct order to multiply matrices in 2D space??

When I multiply:
m = projection * translate * scale;

And finally in the vertex shader
gl_Position = m * pos;

Works perfectly.

But when I multiply:
m = projection * scale * translate;

And in the vertex shader:
gl_Position = m * pos;

Nothing is draw in the screen.

In this case scale is a matrix to invert the y axis and translate is a matrix to move a square on the screen.

Thanks advance.

Depth Buffer in OpenGL ES 2.0 on iOS

11 April 2013 - 11:26 PM



I want draw a cube with OpenGL ES 2.0 but I think that I have a problem with the depth buffer.


My cube looks that:



My setup buffers is


glGenFramebuffers(1, &defaultFramebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebuffer);
glGenRenderbuffers(1, &colorRenderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, colorRenderbuffer);
[context renderbufferStorage:GL_RENDERBUFFER fromDrawable:(CAEAGLLayer *)self.layer];
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &framebufferWidth);
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &framebufferHeight);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorRenderbuffer);
glViewport(0, 0, framebufferWidth, framebufferHeight);
glGenRenderbuffers(1, &depthRenderbuffer); 
glBindRenderbuffer(GL_RENDERBUFFER, depthRenderbuffer); 
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, framebufferWidth, framebufferHeight); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthRenderbuffer);

   NSLog(@"Failed to make complete framebuffer object %x", glCheckFramebufferStatus(GL_FRAMEBUFFER));


Can I help me??



Problem with World - View - Projection

29 March 2013 - 09:44 PM

I'm programming an app for iOS with OpenGL ES 2.0 but the application it isn't draw anything sad.png
I did my own math library for matrix and vector's operations and works good.
I compute the View Matrix like DirectX in Right Hand System
MATRIX* ComputeViewMatrixRH(MATRIX *pOut, const VECTOR3 *pEye, const VECTOR3 *pLookAt, const VECTOR3 *pUp)
	VECTOR3 zAxis = *pEye - *pLookAt;
	Vector3Normalize(&zAxis, &zAxis);

	VECTOR3 xAxis;
	Vector3Cross(&xAxis, pUp, &zAxis);
	Vector3Normalize(&xAxis, &xAxis);

	VECTOR3 yAxis;
	Vector3Cross(&yAxis, &zAxis, &xAxis);

	pOut->m[0][0] = xAxis.x; pOut->m[0][1] = yAxis.x; pOut->m[0][2] = zAxis.x; pOut->m[0][3] = 0.0f;
	pOut->m[1][0] = xAxis.y; pOut->m[1][1] = yAxis.y; pOut->m[1][2] = zAxis.y; pOut->m[1][3] = 0.0f;
	pOut->m[2][0] = xAxis.z; pOut->m[2][1] = yAxis.z; pOut->m[2][2] = zAxis.z; pOut->m[2][3] = 0.0f;

	pOut->m[3][0] = Vector3Dot(&xAxis, pEye);
	pOut->m[3][1] = Vector3Dot(&yAxis, pEye);
	pOut->m[3][2] = Vector3Dot(&zAxis, pEye);
	pOut->m[3][3] = 1.0f;

	return pOut;


The perspective Matrix I compute like DirectX in Right Hand System

MATRIX* ComputeProjectionMatrixRH(MATRIX* pOut, float fovY, float aspectRatio, float zn, float zf)
	float yScale = 1/tan(fovY/2);
	float xScale = yScale / aspectRatio;

	pOut->m[0][0] = xScale; pOut->m[0][1] = 0.0f;   pOut->m[0][2] = 0.0f;        pOut->m[0][3] =  0.0f;
	pOut->m[1][0] = 0.0f;   pOut->m[1][1] = yScale; pOut->m[1][2] = 0.0f;        pOut->m[1][3] =  0.0f;
	pOut->m[2][0] = 0.0f;   pOut->m[2][1] = 0.0f;   pOut->m[2][2] = zf/(zn-zf);  pOut->m[2][3] = -1.0f;
	pOut->m[3][0] = 0.0f;   pOut->m[3][1] = 0.0f;   pOut->m[3][2] = zn*zf/(zn-zf);pOut->m[3][3] =  0.0f;

	return pOut;


Now I'm confused with that because some books and pages in Internet show the projection matrix different. I tested all matrix but anything works.


For example other perspective projection matrix for right hand system is this:

1/tan(alpha/2)*aspect,        0        ,     0      ,   0
      0              ,   1/tan(alpha/2),     0      ,   0
      0              ,        0        ,(f+n)/(f-n) ,   1    
      0              ,        0        , 2*f*n/(n-f),   0


What's the correct matrix?? Why many matrices for perspective projection???



Best Practice for Values Return C/C++

09 March 2013 - 08:05 PM



What's is the best practice for values return in a function in C/C++ for Game Engines??



In C/C++ I can return one value with the sentence return.

Texture = LoadTexture(path);


or I can return the value on second via

LoadTexure(path, &Texture);


In both examples the variable Texture is get by the function LoadTexture.
What's is the better??