Draw OGL Screen Saved Texture On Different Dimension Screen?

Draw OGL Screen Saved Texture On Different Dimension Screen?

Hi,

I am trying to draw an OpenGL screen that was saved as a 1024x1024 texture.

When the game’s window is at default dimensional values of 640x480
then it works without problems.

When I resize the game’s window, then I have problems.

Here is relevant source code:

Code:
glPushMatrix();
glViewport(0, 0, 1024, 1024);
glBindTexture(GL_TEXTURE_2D, SavedGameScreen);
glCopyTexImage2D(GL_TEXTURE_2D,0,GL_RGB,0,0,1024,1024,0);
glPopMatrix();

glViewport(0, 0, visuals->ScreenWidth, visuals->ScreenHeight);

}
//-------------------------------------------------------------------------------------------------
void Screens::DisplaySavedGameScreen(void)
{
glPushMatrix();

glViewport(0, 0, 1024, 1024);

glBindTexture(GL_TEXTURE_2D, SavedGameScreen);
glEnable(GL_TEXTURE_2D);

glTranslatef(320.0f, 240.0f, 0.0f);

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

glBegin( GL_QUADS );
    glTexCoord2i(1, 0);
    glVertex3f( 0+(visuals->ScreenWidth/2), 0+(visuals->ScreenHeight/2), 0 );

    glTexCoord2i(0, 0);
    glVertex3f( 0-(visuals->ScreenWidth/2), 0+(visuals->ScreenHeight/2), 0 );

    glTexCoord2i(0, 1);
    glVertex3f( 0-(visuals->ScreenWidth/2), 0-(visuals->ScreenHeight/2), 0 );

    glTexCoord2i(1, 1);
    glVertex3f( 0+(visuals->ScreenWidth/2), 0-(visuals->ScreenHeight/2), 0 );
glEnd();

glPopMatrix();

glViewport(0, 0, visuals->ScreenWidth, visuals->ScreenHeight);

}
//-------------------------------------------------------------------------------------------------

Here are some screenshots:
Normal Window:
[Image: http://16bitsoft.com/images/beta/LF2-OGL-DisplayIssue03.png ]
Smaller Window:
[Image: http://16bitsoft.com/images/beta/LF2-OGL-DisplayIssue01.png ]
Larger Window:
[Image: http://16bitsoft.com/images/beta/LF2-OGL-DisplayIssue02.png ]

Hoping someone knows how to fix this issue.
Thanks!------------------------
JeZ+Lee
JessePalser <AT> Gmail <DOT> com
16BitSoft®
Video Game Design Studio
www.16BitSoft.com

[…]

First question would be, what’s actually in that 1024x1024 texture? A 640x480
image?

As to rendering 2D stuff on the screen, I tend to use two different methods,
depending on what I’m after:

1. Vertex coordinates as native pixels, for rendering text
   and other stuff at 1:1 pixel resolution, regardless of
   screen/window size.

2. Vertex coordinates as "virtual" pixels, for rendering
   anything that should be scaled to fit the screen/window.
   It's probably a good idea to maintain a 1:1 aspect ratio
   in most cases!

Here’s some EEL code from my latest project:

For 1 (copyright, fps display etc; fixed size in pixels):

[...]

MatrixMode(PROJECTION);
PushMatrix();
LoadIdentity();
Ortho(0, screen.w, 0, screen.h, 0, 10);
MatrixMode(MODELVIEW);
PushMatrix();
LoadIdentity();

[...render stuff using native pixels as unit for glVertex()...]

For 2 (title screen, game screen etc):

[...]

// Set up an ortho display where
//	* 1 unit <==> native pixel
//	* (0, 0) is center of the screen
MatrixMode(PROJECTION);
LoadIdentity();
if w > h
	local ow, local oh = w / h, 1;
else
	ow, oh = 1, h / w;
local cx = floor(w / 2);
local cy = floor(h / 2);
Ortho(-cx, w - cx, -cy, h - cy, 0, 10);

// Pick a nice scale factor depending on screen size.
MatrixMode(MODELVIEW);
LoadIdentity();
if w / 1080 < h / 800
	local s = w / 1080;
else
	s = h / 800;
Scale(s, s, 1);

[...render stuff as if the display was always 1080x800]

The weird 1080x800 “virtual” screen size here is for layout reasons with 16:10
and 16:9 screens and stuff like that. Also note that depending on the
screen/window aspect ratio, the actual drawing area may extend way outside
this “virtual” display area!

Unless you’re into dynamic screen layouts, you should probably just stay away
form that area, or even set up the viewport to a 4:3 (or whatever) area
centered in the window/screen. Then you can just set the scale to
virtual_width / actual_width and be done with it.

Hope that helps - and either way, this is pure OpenGL stuff, not specifically
related to SDL. ;-)On Saturday 16 October 2010, at 15.10.22, “JeZ-l-Lee” wrote:

Draw OGL Screen Saved Texture On Different Dimension Screen?

Hi,

I am trying to draw an OpenGL screen that was saved as a 1024x1024 texture.

When the game’s window is at default dimensional values of 640x480
then it works without problems.

When I resize the game’s window, then I have problems.

//David Olofson - Consultant, Developer, Artist, Open Source Advocate

.— Games, examples, libraries, scripting, sound, music, graphics —.
| http://olofson.net http://olofsonarcade.com http://kobodeluxe.com |
’---------------------------------------------------------------------’

Hi,

Also consider that when a SDL window is resized, the OpenGL context attached
to it is screwed up. Textures, VBOs, etc. will get screwed up also. Try
"resizing" the window to the same size, and see if you have problems
(although the screenshots did not seem to be attached, so the nature of the
problem is difficult to determine).

Ian

Hi,

I posted this to the SDL forums
and it automatically was sent to the mailing list.

View the original forum post (with screenshots) here:
http://forums.libsdl.org/viewtopic.php?t=6631&sid=fe386b130f334bb1a897c54e0ccda794

Thanks!

JesseOn 10/16/2010 01:39 PM, Ian Mallett wrote:

Hi,

Also consider that when a SDL window is resized, the OpenGL context
attached to it is screwed up. Textures, VBOs, etc. will get screwed
up also. Try “resizing” the window to the same size, and see if you
have problems (although the screenshots did not seem to be attached,
so the nature of the problem is difficult to determine).

Ian


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Not showing up on the forums either.On 16 October 2010 14:13, Jesse Palser wrote:

I posted this to the SDL forums
and it automatically was sent to the mailing list.

View the original forum post (with screenshots) here:
http://forums.libsdl.org/viewtopic.php?t=6631&sid=fe386b130f334bb1a897c54e0ccda794

Not showing up on the forums either.

I see it.

It may be possible that you are not clearing the screen before each frame,
or you’re not drawing over the whole thing.

In its most usual form:
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

IanOn Sat, Oct 16, 2010 at 2:43 PM, Kenneth Bull wrote: