Reply
Thread Tools
aStrike's Avatar
Posts: 80 | Thanked: 225 times | Joined on Sep 2012
#1
Hi,
I recently got a n950 from the 2012 Coding Competition by nominating a game I developed for the n900 which was programmed in C++, sdl1.2 and opengl es2.0. I am trying to port the game to n9/n950.

I downloaded easy-chroot and a SDK image to develop on the n950 itself. The game compiled fine, but when I try to launch the game it crashes I get an error saying that glCreateShader returned 0 and in my debug file I see that all vertex buffer object also returned 0.

My guess is that something is wrong with the initialization of SDL and opengl es2.0, maybe with creating a context and a window. I tried to make a simple test to check how to initialize sdl and opengl es2.0 and set a working window up, but due to lack of documentations I couldn't find a good example how to set a window up.

Could anyone post a working code snippet/small example (like the test HERE) of the initialization of sdl1.2 and ogles2.0 for the harmattan platform(n950)?

The init code I currently have is this:
SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 2 );
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 24 );
screen = SDL_SetVideoMode( 0, 0, 16, SDL_OPENGLES | SDL_ FULLSCREEN );
( The SDL_GLES_CreateContext() and SDL_GLES_MakeCurrent(...) are missing because the are not supported in the harmattan port of libsdl1.2 and maybe this is the problem)

Thanks!

EDIT: Figured it out!
Here is the port of the maemo (n900) gles2 test to n950 harmattan if anyone is interested:

Remove the ".txt" from the attached file and compile with this command:
gcc `sdl-config --cflags --libs` -o gles2 sdl_gles2_harmattan_test.c -lSDL -lEGL -lGLESv2
/* gles2 - a simple SDL_gles OpenGL|ES 2.0 sample for meego harmattan ( n9/n950 )
*
* This file is in the public domain, furnished "as is", without technical
* support, and with no warranty, express or implied, as to its usefulness for
* any purpose.
*/

/**
** I commented the lines that are not needed as SDL/SDL_opengles.h is no
** longer included in the harmattan port of SDL1.2, and added a little info.
** */

#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <assert.h>
#include <iostream>

#include <SDL.h>
//#include <SDL/SDL_opengles.h>
//#include <SDL_gles.h>

#include <EGL/egl.h>
#include <GLES2/gl2.h>

static SDL_Surface *screen;
//static SDL_GLES_Context *context;
//SDL_GL_Context* context;

static GLuint program;
static bool fullscreen = false;

static GLuint compile_shader(GLenum type, const char *src)
{
GLuint shader = glCreateShader(type);
GLint compiled;

std::cout << shader << std::endl;

assert(shader != 0),
glShaderSource(shader, 1, &src, NULL);
glCompileShader(shader);
glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
assert(compiled);

return shader;
}

static void init()
{
const char vertex_shader_src[] =
"attribute vec4 pos;\n"
"void main()\n"
"{\n"
" gl_Position = pos;\n"
"}\n";

const char fragment_shader_src[] =
"precision mediump float;\n"
"void main()\n"
"{\n"
" gl_FragColor = vec4 ( 1.0, 1.0, 0.0, 1.0 );\n"
"}\n";

GLuint vertex_shader = compile_shader(GL_VERTEX_SHADER, vertex_shader_src);
GLuint fragment_shader = compile_shader(GL_FRAGMENT_SHADER, fragment_shader_src);

program = glCreateProgram();
assert(program);

glAttachShader(program, vertex_shader);
glAttachShader(program, fragment_shader);

glBindAttribLocation(program, 0, "pos");

GLint linked;
glLinkProgram(program);
glGetProgramiv(program, GL_LINK_STATUS, &linked);
assert(linked);

glClearColor(0.0f, 0.2f, 0.0f, 0.0f);
}

static void render()
{
GLfloat tri_v[] = {0.0f, 0.5f, 0.0f,
-0.5f, -0.5f, 0.0f,
0.5f, -0.5f, 0.0f};

glViewport(0, 0, screen->w, screen->h);
glClear(GL_COLOR_BUFFER_BIT);
glUseProgram(program);

glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, tri_v);
glEnableVertexAttribArray(0);

glDrawArrays(GL_TRIANGLES, 0, 3);

// SDL_GLES_SwapBuffers();
SDL_GL_SwapBuffers();
}

// The toggle_fullscreen() function is not needed, harmattan SDL1.2 making all windows fullscreen.
/*
static void toggle_fullscreen()
{
int res;

fullscreen = !fullscreen;

screen = SDL_SetVideoMode(0, 0, 16, SDL_SWSURFACE | (fullscreen ? SDL_FULLSCREEN : 0)); // The falgs argument must have the "SDL_OPENGLES" flag in it or a context for opengl will NOT be created.
assert(screen);

// res = SDL_GLES_SetVideoMode();
// if (res != 0) puts(SDL_GetError());
// assert(res == 0);

render();
}
*/

int main()
{
int res;
res = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);
assert(res == 0);

SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
// res = SDL_GLES_Init(SDL_GLES_VERSION_2_0);
assert(res == 0);

screen = SDL_SetVideoMode( 0, 0, 16, SDL_OPENGLES|SDL_FULLSCREEN );
// screen = SDL_SetVideoMode(0, 0, 16, SDL_SWSURFACE);
assert(screen);

SDL_WM_SetCaption("SDLgles v2 test", "SDLgles v2 test");
SDL_ShowCursor(SDL_DISABLE);

// context = SDL_GLES_CreateContext();
// context = SDL_GL_CreateContext();
// assert(context);

// res = SDL_GLES_MakeCurrent(context);
// res = SDL_GL_MakeCurrent(context);
// assert(res == 0);

init();
render();

SDL_Event event;
while (SDL_WaitEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
goto quit;
case SDL_MOUSEBUTTONDOWN:
// toggle_fullscreen();
break;
}
}

quit:
// SDL_GL_DeleteContext(context);

// SDL_GLES_Quit();
SDL_Quit();

return 0;
}
Attached Files
File Type: txt sdl_gles2_harmattan_test.c.txt (3.7 KB, 125 views)
__________________
Check My Game, Alpha Strike V1.1.0-2 Now in Extras-devel.
Alpha Strike (v1.0.0-2) gameplay video: HERE!

Last edited by aStrike; 2012-11-18 at 23:43.
 

The Following User Says Thank You to aStrike For This Useful Post:
Reply

Thread Tools

 
Forum Jump


All times are GMT. The time now is 01:49.