Results 1 to 5 of 5

Thread: Only render on 1/4 of screen

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2011
    Posts
    2

    Only render on 1/4 of screen

    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:

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

  2. #2
    Newbie OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,789

    Re: Only render on 1/4 of screen

    You need an off-center ortho projection for this, so try:
    Code :
    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:
    Code :
    int bottom = height / 2;
    int top = -bottom;

  3. #3
    Junior Member Newbie
    Join Date
    Apr 2011
    Posts
    2

    Re: Only render on 1/4 of screen

    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:

    [img]http://img18.imageshack.us/i/99458990.png/[/img]

  4. #4
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: Only render on 1/4 of screen

    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.

  5. #5
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,161

    Re: Only render on 1/4 of screen

    Quote Originally Posted by mhagain
    You need an off-center ortho projection for this, so try:
    Code :
    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:
    Code :
    int bottom = height / 2;
    int top = -bottom;
    Dude, the result of Right - Left is Width so you have calculated exactly what was originally posted!

Similar Threads

  1. render text to the screen
    By saman_artorious in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 11-17-2013, 05:58 AM
  2. Render an .OBJ file to the screen
    By Dako300 in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 10-21-2013, 03:18 PM
  3. Is it possible to render a texture on screen?
    By SagoO in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-13-2011, 12:25 PM
  4. render to screen and file
    By christus in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 05-18-2007, 11:29 PM
  5. Out of screen render
    By arieb in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 07-09-2001, 03:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean