whynodd
Member
- Joined
- Sep 20, 2008
- Messages
- 262
Edit: No problem anymore. This thread is now my game development thread. I'm updating it regularly and sometimes I post interesting code sections.
Hello!
I need some serious help with this.
This is where i took most of the code: wiki
Compiled directly on pandora with:
My code:
This program fails at creating an EGL surface - so I'm stuck here.
First I noticed that the code from the wiki isn't even runnable at all, incomplete and there are instructions missing on how to actually compile and use this. Perhaps it works in Cpas' OpenGL-Emulator, but not on the real machine.
I find it extremly difficult to find a GLES2 Hello Triangle that compiles and works on my pandora.
I have a couple of questions about some things I don't quite understand:
- Is it nessecary to use SDL?
- What is the concept behind surfaces and contexts?
- Especially contexts, what is it? I dont' get it.. Can't I just give the SGX a pointer to a simple framebuffer?
- What is EGL?
- #include <GLES2/gl2.h> or #include <GLES/gl.h> (I want to use openGLES2, but where should be the difference in initialization?
- Why the hell does one need to write 200(!) lines of code for the initialization and the code for drawing a SINGLE TRIANGLE is still missing?
- Whats the shortest possible way to draw a fullscreen triangle?
- My code above compiles without -lGLESv2. Why? Isn't it needed?
Every F**N (sorry..) time I want to code something, there are millions of dumb things in the way, mostly missing documentation. I know there are tutorials but every "tutor" uses another device or uses cross compilers, uses an OpenGLES-Emulator or some weird libs to do unnessecary things (Or uses and Iphone for GLES!).
I want to do the real stuff, program shaders, a game. Please Devs, write it in the wiki how it really works. A newb has serious problems even if simple things like #include<iostream> are missing in your tutorials! Test your code on the real machine, comment the code like hell and give instructions how to compile it, explain even the simplest lines of code. I can't do it, I'm the newb here. So just hope someone can help me.
Hello!
I need some serious help with this.
This is where i took most of the code: wiki
Compiled directly on pandora with:
Code:
gcc -o opengles opengles.cpp -lEGL -lGLESv2 -Iusr/include/SDL -Lusr/lib -lSDL -lSDL_image -lstdc++ -DGLES1
My code:
Code:
#ifdef GLES1
#include <EGL/egl.h>
#include <GLES2/gl2.h>
#include <SDL/SDL_syswm.h>
#else
#include <GL/gl.h>
#include <SDL/SDL.h>
#endif
#include <iostream>
#include <SDL/SDL.h>
#ifdef GLES1
EGLDisplay g_eglDisplay = 0;
EGLConfig g_eglConfig = 0;
EGLContext g_eglContext = 0;
EGLSurface g_eglSurface = 0;
#endif
// consts
#define COLOURDEPTH_RED_SIZE 5
#define COLOURDEPTH_GREEN_SIZE 6
#define COLOURDEPTH_BLUE_SIZE 5
#define COLOURDEPTH_DEPTH_SIZE 16
#ifdef GLES1
static const EGLint g_configAttribs[] ={
EGL_RED_SIZE, COLOURDEPTH_RED_SIZE,
EGL_GREEN_SIZE, COLOURDEPTH_GREEN_SIZE,
EGL_BLUE_SIZE, COLOURDEPTH_BLUE_SIZE,
EGL_DEPTH_SIZE, COLOURDEPTH_DEPTH_SIZE,
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT,
//EGL_BIND_TO_TEXTURE_RGBA, EGL_TRUE, // fails at eglChoseConfig!
EGL_NONE
};
#endif
unsigned int xRes = 320;
unsigned int yRes = 240;
SDL_Surface* videoSurface = 0;
/*===========================================================
Initialise opengl settings. Call straight after SDL_SetVideoMode()
===========================================================*/
int initOpenGL()
{
#ifdef GLES1
// use EGL to initialise GLES
g_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
if (g_eglDisplay == EGL_NO_DISPLAY)
{
printf("Unable to initialise EGL display.\n");
return 0;
}
// Initialise egl
if (!eglInitialize(g_eglDisplay, NULL, NULL))
{
printf("Unable to initialise EGL display.\n");
return 0;
}
// Find a matching config
EGLint numConfigsOut = 0;
if (eglChooseConfig(g_eglDisplay, g_configAttribs, &g_eglConfig, 1, &numConfigsOut) != EGL_TRUE || numConfigsOut == 0)
{
fprintf(stderr, "Unable to find appropriate EGL config.\n");
return 0;
}
// Get the SDL window handle
SDL_SysWMinfo sysInfo; //Will hold our Window information
SDL_VERSION(&sysInfo.version); //Set SDL version
if(SDL_GetWMInfo(&sysInfo) <= 0)
{
printf("Unable to get window handle");
return 0;
}
g_eglSurface = eglCreateWindowSurface(g_eglDisplay, g_eglConfig, (EGLNativeWindowType)sysInfo.info.x11.window, 0);
if ( g_eglSurface == EGL_NO_SURFACE)
{
printf("Unable to create EGL surface!\n"); // <<<<<<------- SPITS THIS OUT
return 0;
}
// Bind GLES and create the context
eglBindAPI(EGL_OPENGL_ES_API);
//EGLint contextParams[] = {EGL_CONTEXT_CLIENT_VERSION, 1, EGL_NONE}; // Use GLES version 2.x
g_eglContext = eglCreateContext(g_eglDisplay, g_eglConfig, EGL_NO_CONTEXT, NULL);
if (g_eglContext == EGL_NO_CONTEXT)
{
printf("Unable to create GLES context!\n");
return 0;
}
if (eglMakeCurrent(g_eglDisplay, g_eglSurface, g_eglSurface, g_eglContext) == EGL_FALSE)
{
printf("Unable to make GLES context current\n");
return 0;
}
#else
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, COLOURDEPTH_RED_SIZE);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, COLOURDEPTH_GREEN_SIZE);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, COLOURDEPTH_BLUE_SIZE);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, COLOURDEPTH_DEPTH_SIZE);
#endif
return 1;
}
/*======================================================
* Kill off any opengl specific details
====================================================*/
void terminateOpenGL()
{
#ifdef GLES1
eglMakeCurrent(g_eglDisplay, NULL, NULL, EGL_NO_CONTEXT);
eglDestroySurface(g_eglDisplay, g_eglSurface);
eglDestroyContext(g_eglDisplay, g_eglContext);
g_eglSurface = 0;
g_eglContext = 0;
g_eglConfig = 0;
eglTerminate(g_eglDisplay);
g_eglDisplay = 0;
#endif
}
int swapBuffers()
{
#ifdef GLES1
eglSwapBuffers(g_eglDisplay, g_eglSurface);
#else
SDL_GL_SwapBuffers();
#endif
}
int initSDL()
{
// Initialize SDL and the video subsystem
SDL_Init(SDL_INIT_VIDEO);
// Set the video mode
videoSurface = SDL_SetVideoMode(xRes, yRes, 16, SDL_HWSURFACE);//SDL_DOUBLEBUF);
// Print out some information about the video surface
if (videoSurface != NULL)
{
std::cout << "The current video surface bits per pixel is " << (int)videoSurface->format->BitsPerPixel << std::endl;
}
else
{
std::cerr << "Video initialization failed: " << SDL_GetError() << std::endl;
return 0;
}
return 1;
}
int terminateSDL()
{
SDL_Quit();
}
int main( int argc, const char* argv[] )
{
initSDL();
initOpenGL();
SDL_Delay(1000);
terminateOpenGL();
terminateSDL();
}
This program fails at creating an EGL surface - so I'm stuck here.
First I noticed that the code from the wiki isn't even runnable at all, incomplete and there are instructions missing on how to actually compile and use this. Perhaps it works in Cpas' OpenGL-Emulator, but not on the real machine.
I find it extremly difficult to find a GLES2 Hello Triangle that compiles and works on my pandora.
I have a couple of questions about some things I don't quite understand:
- Is it nessecary to use SDL?
- What is the concept behind surfaces and contexts?
- Especially contexts, what is it? I dont' get it.. Can't I just give the SGX a pointer to a simple framebuffer?
- What is EGL?
- #include <GLES2/gl2.h> or #include <GLES/gl.h> (I want to use openGLES2, but where should be the difference in initialization?
- Why the hell does one need to write 200(!) lines of code for the initialization and the code for drawing a SINGLE TRIANGLE is still missing?
- Whats the shortest possible way to draw a fullscreen triangle?
- My code above compiles without -lGLESv2. Why? Isn't it needed?
Every F**N (sorry..) time I want to code something, there are millions of dumb things in the way, mostly missing documentation. I know there are tutorials but every "tutor" uses another device or uses cross compilers, uses an OpenGLES-Emulator or some weird libs to do unnessecary things (Or uses and Iphone for GLES!).
I want to do the real stuff, program shaders, a game. Please Devs, write it in the wiki how it really works. A newb has serious problems even if simple things like #include<iostream> are missing in your tutorials! Test your code on the real machine, comment the code like hell and give instructions how to compile it, explain even the simplest lines of code. I can't do it, I'm the newb here. So just hope someone can help me.