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);
}
}