PocketMatrix forums

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

Using hardware accelerated 2D on iPhone

Hi! In order to get better framerates for my game, I've decided to look into the OpenGL ES renderer. So far, I've #defined EGL_USEGL before including edgemain.h and make a call to ecd.dsp->Perspective2D(480, 320, true) following the instructions of the "Mix 2D and 3D rendering" sub-section from the "3D helper functions" section at the "Using 3D and OpenGL" tutorial. I placed the call at the very beginning of the ClassMain::OnNextFrame method (don't know if this is OK, though).

I must be doing something wrong, since all I'm getting is a black screen (the game is working, since I can hear the background music). What am I missing?

Thanks in advance for your replies,

--Nacho
Hi Nacho,

Please check your code if it contains any display->buffer.xxx calls. They don't work because in OpenGL there is no backbuffer. You need to use the blitter functions from the ClassEDisplay class itself.

Please try the following small sample to see if it works:

Code:

glClearColorx(0, 0, 0, 65536);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
display->Perspective2D(320, 480, false);
display->DrawFont(2, 2, &display-;>fontinternal, "Hello World");
Hi Edge,

Thanks for your reply. I've tried the snippet you suggested but it's still not working, I get a small rectangle at the top of the screen on top of a black background.

I'm attaching a very simple sample project which includes those 4 lines of code inside the ClassMain::OnNextFrame method.

Thanks again for your reply,

--Nacho
Attachments:
helloworld_iphone.zip (14 KB)
try adding this after the Perspective2D call:
display->SetShading(E3D_TEXTURE);
Orion_ wrote:try adding this after the Perspective2D call:
display->SetShading(E3D_TEXTURE);


Hi Orion_, I've tried that and now I can see the text but it gets printed over a fuchsia rectangle. Since the DrawFont method doesn't have a way of specify, how can I get rid of that color?

I've also changed all my blt calls in order to use the dsp member variable of the ecd structure, but I'm still not seeing my sprites.

--Nacho
you should enable blending in the display init function:
Code:

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);


and for each surfaces you must upload the texture for opengl like this:
display->UploadTexture(&your;_surface);
The font is now working and I'm seeing some of my sprites :)

One question thought, where should I add the function call to UploadTexture? So far, I've been adding it after the call to CreateSurface, is that correct? I've been reading the docs but they don't explain where am I supposed to make the call.

I'm also having some troubles with the orientation: my game is supposed to run in landscape mode, so I'm using the DOR_LANDSCAPE flag inside the OnDisplayConfig method. Nonetheless, my sprites get rendered in a portrait orientation. What am I missing?

Thanks again for all your help Orion_!

--Nacho
as answered here http://www.pocketmatrix.com/forums/view ... hp?t=28969
I have the same problem, the orientation mode seems not to work using OpenGL :(
Hi Nacho,

The UploadSurface call can be made directly after loading the surface from a file. In some cases it may be desirable to postpone the UploadSurface call until some things are initialized (such as creating a mask for pixel collision detection, or setting up a font).

I've posted more information about OpenGL orientation in Orion's topic. I'm posting the temporary solution to use in OpenGL here as well:

Code:

glTranslatef(480.0f, 0, 0);
glRotatef(90.0f, 0, 0, 1.0f);