Sign in to follow this  
jake_Ghost

Rendering to a part of the screen

Recommended Posts

I have a map in my game and I wanted to know how to render to a part of the screen instead of the full thing. Currently, thats what I do and I don't want to do that , I just want it to be rendered to the top right corner for example. How might I go about doing this? Jake

Share this post


Link to post
Share on other sites
my best suggestion would be to research glScissor

try this:
render your entire scene
glScissor(x, y, width, height);
glEnable(GL_SCISSOR_TEST);
glClear(GL_COLOR_BUFFER_BIT); //this clears the area inside of the scissor region
draw what you want inside of that box
glDisable(GL_SCISSOR_TEST);

easy enough?

Share this post


Link to post
Share on other sites
Quote:
Original post by jake_Ghost
I have a map in my game and I wanted to know how to render to a part of the screen instead of the full thing. Currently, thats what I do and I don't want to do that , I just want it to be rendered to the top right corner for example. How might I go about doing this?

Jake
Assuming you are using an orthographic projection with the origin at the bottom-left and (width,height) at the top-right, for a fullscreen quad you would do something like...
glBegin(GL_QUADS);
glVertex2f(0.0f, 0.0f);
glVertex2f(width, 0.0f);
glVertex2f(width, height);
glVertex2f(0.0f, height);
glEnd();
Which you said you know already. So for a quad that's the top-right quarter of the screen it's the same thing except you start at the center of the screen (width/2, height/2) instead of the bottom-left, go to center-right, then top-right, and finally top-center like so...
glBegin(GL_QUADS);
glVertex2f(width/2.0f, height/2.0f);
glVertex2f(width, height/2.0f);
glVertex2f(width, height);
glVertex2f(width/2.0f, height);
glEnd();
Simple as that.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this