PocketMatrix forums

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

EDGELib try for iPhone

Hello,

I'm currently trying EDGELib before buying it for an iPhone game project.
I've some troubles with the sound engine, using hekkus on PC with VC++2008 I've a delay of 1 second before the sound actually plays using ecd.snd->PlaySound(0);
On the iPhone side I've 2 malloc/free error showing in the console when exiting the application whenever I use the ecd.snd->Open(); function and even if I do not call ecd.snd->Close(); (The error is about freeing not aligned pointers)
Also, I've a question about 2DSurface, Is there any function or trick to use paletted surfaces and with the ability to dynamically change or swap some colors of the palette ?

Thanks.
Hi Orion,

If Hekkus doesn't work for you, I recommend using OpenAL. Also, your PC build will be more similar to the iPhone version (that also uses OpenAL) this way. You can remove the memory error by editing the OpenAL wrapper. Remove these lines (they are in ESound_Close and ESound_FreeDriver):

Code:

delete driver;
delete ctx;



For paletted surfaces you can do several things. The first is running into a simulated palette display mode (which can be slow on the iPhone, also you can't use OpenGL).

Another method is by loading surfaces as palette, and another temporary surface in true color mode. When blitting the loaded surface to the temporary surface, it will do a color conversion and read the display palette. You can alter the display palette by using ClassEDisplay :: SetPalette.
Thank you !

That fixed all my problems :)
Hi again,
Finally I've switched to OpenGL ES because the palette mode or even the default framebuffer mode was too slow on iPhone.
So, my question is, how can I do some realtime tint or color change with BltFast with OpenGL ES ?
Or something like that for the DrawFont function for example, the default edgelib internal font is White, how can I draw text using another color ? I tried glColor3f but it does nothing :/

edit: Another question, is there any function to unload a texture uploaded with display->UploadTexture function ? can my_surface.Free(); do the job ?

edit2: I noticed that the orientation flag doesn't work in OpenGL mode. Do you plan to implement it ?

Thanks.
Hi Orion,

Using the OpenGL function glColor3f is the correct way to handle this. You also need to change the texture drawing mode with the following function:

Code:

glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);


This will blend the texture with the OpenGL color value. Don't forget to change it back afterwards, otherwise the rest of the rendering could go wrong.

Regarding your other questions:
- Yes, when freeing the surface it also de-uploads it from OpenGL
- Changing orientation in OpenGL is planned for one of the upcoming EDGELIB releases
I tried glTexEnvx and it doesn't work, at least on PC using glTexEnvi

My code is like this:
Code:


in OnDisplayInit:

display->CreateSurface(...
display->UploadTexture(...

#if defined(DEVICE_IPHONE)
glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
#else
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
#endif

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


in OnNextFrame:

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
display->Perspective2D(SCREEN_WIDTH, SCREEN_HEIGHT, false);
display->SetShading(E3D_TEXTURE);

display->BltFast(...

glColor3ub(0, 255, 0);
display->DrawFont(16, 400, &display-;>fontinternal, "test");


either glColor3ub/glColor3i/glColor3f or specifying glTexEnvi before the createsurface/uploadtexture, doesn't change anything to the render :(

can you tell me around when the next release of edgelib with opengl orientation support will be released ?
because this option is really useful and would save me a lots of time, else I would have to do it myself :/
Hi Orion,

Please try the following sample for colored blending. It works in our applications:

Code:

#if defined(EGL_USEGL)
#if defined(DEVICE_DESKTOP)
glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
#else
glColor4x(65536, 0, 0, 65536);
glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
#endif
#endif
display->DrawFont(0, 0, &display-;>fontinternal, "Hello");
#if defined(EGL_USEGL)
#if defined(DEVICE_DESKTOP)
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
#else
glColor4x(65536, 65536, 65536, 65536);
glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
#endif
#endif


The orientation fix will probably be added in EDGELIB 4.0. Unfortunately, we can't give an estimate on the release date (first a 3.96 version will be released soon). In the meantime, it's best to handle the display rotation in OpenGL directly using the following sample:

Code:

glTranslatef(480.0f, 0, 0);
glRotatef(90.0f, 0, 0, 1.0f);
Just a quick question, I was surprised that all the graphics I was displaying on iPhone device with edgelib was converted to 16bits, I thought that the iPhone screen was actually 16bits, then I tried to draw a texture using native iPhone SDK code and the graphics appeared smooth like if it was 24bits, so I found a flag to change in EDGELib to get the same result, and it worked but I don't know if it's the right way to do it and if it's not getting slower because of this flag (even if it's rendered using OpenGL)
here is what I used in the OnDisplayConfig function:
config->emulvideotype = EDSP_TRUE32;
config->videotype = EDSP_TRUE32; // not sure if this one is effective
Hi Orion,

The best solution to force your textures in a specific color format, is to specify it in the CreateSurface call. Pass EST_DSPTRUE32_INV as the flag parameter.

Using EST_DSPTRUE32_INV is faster than EST_DSPTRUE32, because it swaps the red and blue color channels when loading the image (to make it in the same internal format as OpenGL).