Skip to main content
gamedev.net
🔒 Locked

multiple viewport?

Started by TeSsL 7 replies 1.8k views
Original Post
TeSsL
TeSsL
How should i do to get a smaller version of my scene in a smaller window on the upper left of my screen? Like those commonly see in games like warcraft where they display the map.
scarypajamas
scarypajamas
There are a few ways to do this.

google FBO (frame buffer object) and glCopyTexImage2D

You can use the Frame Buffer (access it via the extension GL_EXT_framebuffer_object) to take an "screenshot" of the current view port and turn it into a texture. Then, you can manipulate that texture however you want, such as shrinking it and putting it in a corner of the screen.

You can also use glCopyTexImage2D command which does the same thing as the Frame Buffer except it is slower. The reason you would want to use glCopyTexImage2D, is so if GL_EXT_framebuffer_object extension is unsupported, you can fall back on it.

What I've done in my engine is implement both. I use GL_EXT_framebuffer_object for newer and faster GPU's but still allow glCopyTexImage2D for older cards as well.

EDIT

I believe gamedev has an article discussing how to use the frame buffer here:
http://www.gamedev.net/reference/articles/article2331.asp

And another here:
http://www.gamedev.net/reference/programming/features/fbo2/
TeSsL
TeSsL
Thanks thanks this help=D
Trurl
Trurl
There's another, more straightforward approach. After you've rendered your usual scene to the entire screen, use glViewport and glScissor to select the subset of the screen for the inset view. Then render the inset scene normally. This works with an arbitrary number of subwindows.
TeSsL
TeSsL
Quote:
Original post by Trurl
There's another, more straightforward approach. After you've rendered your usual scene to the entire screen, use glViewport and glScissor to select the subset of the screen for the inset view. Then render the inset scene normally. This works with an arbitrary number of subwindows.


hmm. is there any tutorials or examples on this? Cause rather new to viewport thingy.. Does that mean that have to render twice?
TeSsL
TeSsL
eh. Does the size of my frame that i am copying affect glCopytaxImage2D??
Cause i am not getting the texture.
If i did not understand wrongly, the below code should save a texture with the screenshot of my screen in my video card?
Then i just have to map textureId[0] to my viewport? This is how i do, did i make any misunderstanding anywhere?
					    gl.glGenTextures(1, textureId, 0);gl.glBindTexture(GL.GL_TEXTURE_2D, textureId[0]);gl.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE);gl.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE);gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR_MIPMAP_LINEAR);gl.glCopyTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, 0, 0, glDrawable.getWidth(), glDrawable.getHeight(), 1);


Thanks
scarypajamas
scarypajamas
They way I do it in my app:

/* first, re-size the viewport. What that does is set the size of the of what your image will be.  In other words, 512x512 is how bit the screenshot texture will be */glViewport( 0, 0, 512, 512 );/* draw your 3d/2d scene here */DrawScene();/* bind the image you want */glBindTexture(GL_TEXTURE_2D, img);/* copy viewport to the texture... */glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 0, 0, 512, 512, 0);/* clear the screen */	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	/* reset the viewport to the original screen width/height you had original */glViewport(0, 0, Screen_W, Screen_H);	To draw:glEnable(GL_TEXTURE_2D);glBindTexture(GL_TEXTURE_2D, img);glColor3f(1.0f, 1.0f, 1.0f);/* NOTE: make sure your in 2d drawing mode before you do this.  The x_Pos and y_Pos is the x and y position on the screen you want to draw to. */glBegin(GL_QUADS);	glTexCoord2f( 0.0,  1.0 );	//top left		glVertex2i( x_Pos, y_Pos );	glTexCoord2f( 1.0,   1.0 );	//top right 1.0 0	glVertex2i( Screen_W,   x_Pos );						glTexCoord2f( 1.0,  0.0 );	//bottom right 1.0 1.0	glVertex2i( Screen_W,  Screen_H );	glTexCoord2f( 0.0,  0.0 );	//bottom left 0 1.0	glVertex2i( x_Pos,  Screen_H );glEnd();
TeSsL
TeSsL
Quote:
Original post by scarypajamas
They way I do it in my app:

*** Source Snippet Removed ***


Sry sry i dun quite get it.
some qns i would like to clarify:
1. So if i wan the whole screen to be my texture, i do not have to change my viewport right? Or i still need gl.glviewport(0,0,glDrawable.getWidth,glDrawable.getHeight)?
2. What does the "bind the image you want" means? What do i need for my image? Cause what i want is my current screen as my texture. So how to i get the img?

Thanks thanks
TeSsL
TeSsL
eh.. and another question.. If i have 2 renderer class, is it possible to share the texture which have been uploaded previously? Meaning i have uploaded a texture and been using it in my first renderer class, So i just pass the index and apply it in the 2nd class does it still work? i tried but it doesn't, wondering if is because it doesn't work this way or is just that i made some mistake.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.