SDL 2.0 OpenGL ES 1.1, NDK, home bt losing the draw screen

Hey Dudes,

I’ve now decided to move onto SDL 2.0 and scrapping SDL 1.2 because of On-pause Issues and Asset-Management issues.
Since I’m doing everything in OpenGL, all I need to do is get and set the resolution and do the events, which shouldn’t be much work.
I’m hoping at the end of this assets are working fine and onPause works perfectly. Which would mean I would have 100% working base to develop.

I just got my first OPENGL window to draw on SDL 2.0!

Seems like you need this for it to draw:

// TO CREATE SCREEN
SDL_Window *win;
win = SDL_CreateWindow(“Hello World!”, 100, 100, 480, 800, SDL_WINDOW_OPENGL);

// NEEDED TO DRAW OPENGL
SDL_GLContext glcontext = SDL_GL_CreateContext(win);

//LIKE THE OLD SWAP BUUFERS FUNCTION
SDL_GL_SwapWindow(win);

It’s drawing! Which is good.
But when I press the home button on the phone Android 4.0 and then go back to it, the screen is lost. It’s all BLACK. It’s like it has no SDL_GLContext;

I need to figure this out, then move onto events to make sure they also don’t get lost. Anyone have any idea why it’s going back?

Code is below.

#include <SDL.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <GLES/gl.h>

int main(int argc, char** argv)
{
if (SDL_Init(SDL_INIT_EVERYTHING) == -1)
{
}

int SCREEN_WIDTH = 480;
int SCREEN_HEIGHT = 800;

unsigned int iTexture[1];

SDL_Window *win;
win = SDL_CreateWindow("Hello World!", 100, 100, 480, 800, SDL_WINDOW_OPENGL);

SDL_GLContext glcontext = SDL_GL_CreateContext(win);

glViewport( 0.f, 0.f, SCREEN_WIDTH, SCREEN_HEIGHT );
//Initialize Projection Matrix
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrthof( 0.0, SCREEN_WIDTH, SCREEN_HEIGHT, 0.0, 0.0, 1.0 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();

float fXpos = 200;
float fYpos = 200;

GLfloat box[] = {
   0, 0,
   0, 64,
   64, 0,
   64, 64};

GLfloat tex[] = {0, 0,
				 0, 1,
				 1, 0,
				 1, 1};


		bool bGame = true;

		int i = 0;


		//glGenTextures(1, &iTexture[0]);            // generate texture object
		//glBindTexture(GL_TEXTURE_2D, iTexture[0]);       // enable our texture object
		//glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
		//glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
		//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, player->pixels);

		int iDeg;

		while (bGame == true)
		{
			box[0] = fXpos - 64;
			box[1] = fYpos - 64;
			box[2] = fXpos - 64;
			box[3] = fYpos + 64;
			box[4] = fXpos + 64;
			box[5] = fYpos - 64;
			box[6] = fXpos + 64;
			box[7] = fYpos + 64;

			glLoadIdentity();

			glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

			glEnableClientState(GL_VERTEX_ARRAY);
			glVertexPointer(2, GL_FLOAT, 0, box);

			glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

			glDisableClientState(GL_VERTEX_ARRAY);

			SDL_GL_SwapWindow(win);
			}

}

screen
Message-ID: <1368066013.m2f.37020 at forums.libsdl.org>
Content-Type: text/plain; charset=“iso-8859-1”

Hey Dudes,

I’ve now decided to move onto SDL 2.0 and scrapping SDL 1.2 because of
On-pause Issues and Asset-Management issues.
Since I’m doing everything in OpenGL, all I need to do is get and set the
resolution and do the events, which shouldn’t be much work.
I’m hoping at the end of this assets are working fine and onPause works
perfectly. Which would mean I would have 100% working base to develop.

I just got my first OPENGL window to draw on SDL 2.0!

Seems like you need this for it to draw:

// TO CREATE SCREEN
SDL_Window *win;
win = SDL_CreateWindow(“Hello World!”, 100, 100, 480, 800,
SDL_WINDOW_OPENGL);

// NEEDED TO DRAW OPENGL
SDL_GLContext glcontext = SDL_GL_CreateContext(win);

//LIKE THE OLD SWAP BUUFERS FUNCTION
SDL_GL_SwapWindow(win);

It’s drawing! Which is good.
But when I press the home button on the phone Android 4.0 and then go back
to it, the screen is lost. It’s all BLACK. It’s like it has no
SDL_GLContext;

I need to figure this out, then move onto events to make sure they also
don’t get lost. Anyone have any idea why it’s going back?

Code is below.

Some platforms destroy the OpenGL context (or it’s textures, or…)
when the current window loses focus. I don’t know that Android is one
of these, but I think it might be, and I know that this specifically
happens on some of the smart-phone OSes. The solution is to keep an
eye out for certain events, and when they happen, set a flag so that
the program will know to reinitialize part or all of it’s OpenGL
configuration the next time that it makes a render pass. As a result,
I’d suggest starting on events, and just stick a note somewhere in the
event loop to remind yourself of this later on.> Date: Wed, 08 May 2013 19:20:14 -0700

From: “Timodor”
To: sdl at lists.libsdl.org
Subject: [SDL] SDL 2.0 OpenGL ES 1.1, NDK, home bt losing the draw

I was trying that last night with the event, but how does one know the application is on-pause? How does the event determine that?

I also think I’m using an old version base version SDL 1.2 and SDL 2.0, maybe that’s why on pause is also not working.

I’m not sure what is supposed recreated, which parts of OpenGL need to be reloaded.

screen
Message-ID: <1368140072.m2f.37024 at forums.libsdl.org>
Content-Type: text/plain; charset=“iso-8859-1”

I was trying that last night with the event, but how does one know the
application is on-pause? How does the event determine that?

I also think I’m using an old version base version SDL 1.2 and SDL 2.0,
maybe that’s why on pause is also not working.

I’m not sure what is supposed recreated, which parts of OpenGL need to be
reloaded.

I believe this is all buried in the mailing list archives. I’ll try to
look it up later, but I don’t have time at the moment.> Date: Thu, 09 May 2013 15:54:33 -0700

From: “Timodor”
To: sdl at lists.libsdl.org
Subject: Re: [SDL] SDL 2.0 OpenGL ES 1.1, NDK, home bt losing the draw

screen
Message-ID:
<CABXS6_m_5nfLeaRX2=Uax-w7jZ_8ZCDxBdEAHzE7Acd4xocGzg at mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

screen
Message-ID: <1368140072.m2f.37024 at forums.libsdl.org>
Content-Type: text/plain; charset=“iso-8859-1”

I was trying that last night with the event, but how does one know the
application is on-pause? How does the event determine that?

I also think I’m using an old version base version SDL 1.2 and SDL 2.0,
maybe that’s why on pause is also not working.

I’m not sure what is supposed recreated, which parts of OpenGL need to be
reloaded.

I believe this is all buried in the mailing list archives. I’ll try to
look it up later, but I don’t have time at the moment.

Not certain that I’ve found the right stuff, but I didn’t want to
leave this TOO long. It’s mostly my hope that this will give you the
references that you need to find the info you actually want.

Firstly, make certain that you understand the “Pause / Resume
behaviour” portion of README.android … unfortunately, I don’t know
whether it’s fully up to date. Why isn’t anyone that currently
compiles for Android chiming in on the events/needed actions?

Next, a set of mailing list archive messages. Note that some iOS
support is relevant here. I’ve basically tried to just grab all of the
relevant conversations, instead of specific posts, so you’ll want to
browse a little.
http://lists.libsdl.org/pipermail/sdl-libsdl.org/2012-April/084358.html
http://lists.libsdl.org/pipermail/sdl-libsdl.org/2012-April/084369.html
http://lists.libsdl.org/pipermail/sdl-libsdl.org/2012-April/084445.html
http://lists.libsdl.org/pipermail/sdl-libsdl.org/2012-May/084743.html
http://lists.libsdl.org/pipermail/sdl-libsdl.org/2012-June/084935.html
http://lists.libsdl.org/pipermail/sdl-libsdl.org/2012-July/084998.html
http://lists.libsdl.org/pipermail/sdl-libsdl.org/2012-August/085378.html
http://lists.libsdl.org/pipermail/sdl-libsdl.org/2012-August/085380.html

Finally, two forum posts:
http://forums.libsdl.org/viewtopic.php?t=7926
http://forums.libsdl.org/viewtopic.php?t=7990&sid=85572573f88be2948c3f1b55be16e519

In all of that, I noticed that SDL2 is supposed to deal with this
stuff itself, but that on some versions of Android that apparently
doesn’t actually work. Did you mention your Android version? Have you
checked inside the Android files for SDL2 to see what Android-specific
events and window messages are specified? What events are you actually
getting leading up to, and following, an application pause? The more
information you can provide, the more likely we are to figure out the
problem.> Date: Fri, 10 May 2013 13:04:53 -0500

From: Jared Maddox <@Jared_Maddox>
To: sdl at lists.libsdl.org
Subject: Re: [SDL] SDL 2.0 OpenGL ES 1.1, NDK, home bt losing the draw

Date: Thu, 09 May 2013 15:54:33 -0700
From: “Timodor”
To: sdl at lists.libsdl.org
Subject: Re: [SDL] SDL 2.0 OpenGL ES 1.1, NDK, home bt losing the draw

Hey Jared

Thanks for taking the time to look up that information for me.

But you know what I finally fixed it all. I suspect I was using an old version of SDL 2.0 which id downloaded from internet (which was android eclipse project) before the on pause was fixed.
Not only that assets now load from APK!!!, on pause works totally fine now. goes in and out.
The game is still running, but still there must be some type of event issue to pause the game, if no events with in 5 seconds pause game or something.
I downloaded latest SDL 2.0 Source today and complied them. I’ve come to the conclusion SDL 2.0 is the way to go for android. I literally jumped from SDL 1.2 to SDL 2.0 with like 5 lines of code, which was all the setting of the screen and OpenGL context. Everything else, events, mouse still using the old 1.2 commands :slight_smile:

If your using OpenGL moving from SDL 1.2 and SDL 2.0 is like 5 lines of code. Which is pretty amazing.

I’ve had a good day today.

I guess now I need to figure out how to dodual touch. I suspect maybe it’s the right mouse button instead of the left?

Not certain that I’ve found the right stuff, but I didn’t want to

leave this TOO long. It’s mostly my hope that this will give you the
references that you need to find the info you actually want.

Firstly, make certain that you understand the “Pause / Resume
behaviour” portion of README.android … unfortunately, I don’t know
whether it’s fully up to date. Why isn’t anyone that currently
compiles for Android chiming in on the events/needed actions?

I haven’t because most of this stuff has already been discussed and is
readily available via the forum search or Google.

In all of that, I noticed that SDL2 is supposed to deal with this
stuff itself, but that on some versions of Android that apparently
doesn’t actually work.

It does work AFAIK. If it doesn’t, that’s a bug worth reporting! ;)–
Gabriel.