PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

opengl zoom

I'm putting together a game where all the graphics must be drawn into 240x208 pixels. Depending on my platform, I'd like to be able to zoom into that space so it fits the width of the screen.

I looked at the PinchZoom demo where it looks like zooming is achieved by blit scaling the edgelib logo. I considered drawing my graphics onto such a surface and scaling it to achieve the desired effect, but then I'd have to upload the surface on each frame, which would impact performance. Would it be possible to adjust the zoom by changing the openGL/view settings instead, while retaining the blending I noticed in the PinchZoom approach?
Hi,

The function you need is glViewport, it changes the dimension of the viewport and scales up graphics.

Alternatively, you can also use Perspective2D with your resolution (use 240x208 as parameters). This only works if you're using 2D graphics however.
Thanks, that works great! I'm running into an issue now though where changes to my surface aren't being reflected the second time I Upload it to OpenGL.

Code:
surface->FillRect(NULL, ECOLOR_RED);
display->UploadTexture(surface, false);
display->Blt(0, 0, surface, NULL, 0, 65535);
//...
surface->FillRect(NULL, ECOLOR_BLUE);
display->UploadTexture(surface, false);
display->Blt(0, 0, surface, NULL, 0, 65535);


The second time I Blit, my surface should be blue, but it still appears are red. Are there any other steps I need to take for the change to be reflected on screen?
Hi,

If you're using a normal E2DSurface, make sure the third parameter to UploadTexture is used as well. This cleardata parameter should be set to false to keep the texture data (so you can reupload it).

If you're using an RGBA texture, the ECOLOR_ macro's don't work (these doesn't contain the alpha channel which is needed for those surfaces).
I noticed that when I set glViewport, the screen appears choppy, and I get unwanted artifacts/lines on my screen. When I take a screenshot of my demo running with glViewport not set, blt the screenshot at 0,0 in a test program, and set glViewport the same way I'm doing in my actual game, it looks smooth.

Game running without setting glViewport:
Image

Game running after setting glViewport:
Image

Test program blitting first screenshot with glViewport set:
Image

Here's the code I'm using to configure openGL in both cases:
Code:

// In framework header
#define EGL_POWERVR
#define EGL_USEGL
#define EGL_USEGLES

// OnDisplayInit
#if defined(EGL_USEGL)
#if defined(EGL_USEGLES)
glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
#else
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
#endif
#endif

double scaleFactor = (320 * 65536)/240;
glViewport(0, -240, (320 * scaleFactor)/65535, (480 * scaleFactor)/65536);
display->SetShading(E3D_TEXTURE);


Any thoughts as to how I can correct this?
Hi,

The choppiness could be explained by the scaling factor. When scaling 150%, sometimes the character walks 1 pixel, and then 2 pixels. The lines appear because of internal rounding errors in OpenGL.

I'm affraid there is little you can do about this. The recommended approach is to scale up graphics and modify your routine so your entities move properly over the increased tile size. You could also show more of the game area (because more tiles fit on the larger resolution).