PDA

View Full Version : Only render on 1/4 of screen



jongleur
04-02-2011, 02:32 PM
So I have taken the plunge over to OpenGL ES 2.0 development, and I'm trying to set up a orthographic projection covering the entire screen, (320,480) in this case.

For some reason I only manage to get it to render in the upper right corner; i.e. it's the full viewport - but in upper right quadrant of screen.

This is what I'm doing:



glViewport(0, 0, width, height);

float M[16] = {
1.0/width, 0, 0, 0,
0, 1.0/height, 0, 0,
0, 0, -1, 0,
0, 0, 0, 1
};

GLint proj = glGetUniformLocation(m_shader, "mProj");
glUniformMatrix4fv(proj, 1, 0, &M[0]);



In shader it's as normal, gl_Position = mProj * pos;

I can't get my head around it; I'm guessing the projection matrix is wrong, but can't see how?

mhagain
04-02-2011, 04:33 PM
You need an off-center ortho projection for this, so try:
int right = width / 2;
int left = -right;
int top = height / 2;
int bottom = -top;

float M[16] =
{
1 / (float) (right - left), 0, 0, 0,
0, 1 / (float) (top - bottom), 0, 0,
0, 0, -1, 0,
0, 0, 0, 1
};
Depending on the orientation you use this might be upside-down; if so just substitute this for your top/bottom calcs:
int bottom = height / 2;
int top = -bottom;

jongleur
04-03-2011, 04:08 AM
Ah, of course; that makes sense.

However; even doing so I get the same result - see attached picture. It seems it's all rendered in full resolution but in top right quadrant. Could it be the way the viewport, or rendering context is set up perhaps?

This is what it looks like:

http://img18.imageshack.us/i/99458990.png/

ZbuffeR
04-03-2011, 04:25 AM
What happens if you replace your viewport call by glViewport(0, 0, width , width*2); ?
Check actual values at runtime for width and height, they may not be what you expect.

BionicBytes
04-03-2011, 04:32 AM
You need an off-center ortho projection for this, so try:
int right = width / 2;
int left = -right;
int top = height / 2;
int bottom = -top;

float M[16] =
{
1 / (float) (right - left), 0, 0, 0,
0, 1 / (float) (top - bottom), 0, 0,
0, 0, -1, 0,
0, 0, 0, 1
};
Depending on the orientation you use this might be upside-down; if so just substitute this for your top/bottom calcs:
int bottom = height / 2;
int top = -bottom;

Dude, the result of Right - Left is Width so you have calculated exactly what was originally posted!