Hello. I'm just getting started with my Wiz but I'm having problems with OpenGL.
The program crashes at the call to eglCreateContext. Below is my source code.
I'm printing a bunch of debug messages, and "4" is reached but then the output
stops. Help would be appreciated
.
[edit] I fixed it by linking to the shared version of libwizGLES, using the static
version doesn't work because that symbol gets excluded since it's not used.
CODE
#include <GL/nanogl.h>
#include <wizGLES.h>
#include <GLES/egl.h>
#include <GLES/gl.h>
#include <cstdio>
#include <unistd.h>
#include <string>
#include <cstdarg>
EGLDisplay glDisplay;
EGLConfig glConfig;
EGLContext glContext;
EGLSurface glSurface;
NativeWindowType hNativeWnd = 0;
const char *gl_vendor;
const char *gl_renderer;
const char *gl_version;
const char *gl_extensions;
EGLint attrib_list_fsaa[] =
{
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_BUFFER_SIZE, 0,
EGL_DEPTH_SIZE, 16,
EGL_SAMPLE_BUFFERS, 1,
EGL_SAMPLES, 4,
EGL_NONE
};
EGLint attrib_list[] =
{
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_BUFFER_SIZE, 0,
EGL_DEPTH_SIZE, 16,
EGL_NONE
};
static void get_ortho_matrix(float w, float h, GLfloat *m)
{
float left = 0.0f;
float right = w;
float top = 0.0f;
float bottom = h;
float neer = -1.0f;
float farr = 1.0f;
m[1+4*0] = 0.0f;
m[2+4*0] = 0.0f;
m[0+4*1] = 0.0f;
m[2+4*1] = 0.0f;
m[0+4*2] = 0.0f;
m[1+4*2] = 0.0f;
m[0+4*3] = 0.0f;
m[1+4*3] = 0.0f;
m[2+4*3] = 0.0f;
m[0+4*0] = 2.0f / (right - left);
m[1+4*1] = 2.0f / (top - bottom);
m[2+4*2] = 2.0f / (farr - neer);
m[3+4*0] = -((right+left)/(right-left));
m[3+4*1] = -((top+bottom)/(top-bottom));
m[3+4*2] = -((farr+neer)/(farr-neer));
m[3+4*3] = 1.0f;
}
void debug_message(const std::string fmt, ...)
{
va_list ap;
char msg[1000];
va_start(ap, fmt);
vsnprintf(msg, (sizeof(msg)/sizeof(*msg))-1, fmt.c_str(), ap);
FILE *f = fopen("/mnt/sd/glout.txt", "a");
if (f) {
fprintf(f, "%s", msg);
fclose(f);
}
}
int main(void)
{
EGLint numConfigs;
EGLint majorVersion;
EGLint minorVersion;
debug_message("Starting --------------------------------------\n");
nanoGL_Init();
// Create native window.
debug_message( "VID_Init: Creating the window\n" );
hNativeWnd = OS_CreateWindow();
if(!hNativeWnd)
debug_message( "VID_Init: OS_CreateWindow Failed\n" );
debug_message("1\n");
glDisplay = eglGetDisplay( (NativeDisplayType)0 );
if( glDisplay == EGL_NO_DISPLAY )
{
debug_message( "GL No Display failed\n" );
}
debug_message("2\n");
if( !eglInitialize( glDisplay, &majorVersion, &minorVersion ) )
{
debug_message( "GL Init failed\n" );
}
debug_message("3\n");
if( !eglChooseConfig( glDisplay, attrib_list, &glConfig, 1, &numConfigs ) )
{
debug_message( "GL Config failed\n" );
}
debug_message("4\n");
glContext = eglCreateContext( glDisplay, glConfig, EGL_NO_CONTEXT, NULL );
if( glContext==EGL_NO_CONTEXT )
{
debug_message( "GL Context failed\n" );
}
debug_message("5\n");
glSurface = eglCreateWindowSurface( glDisplay, glConfig, hNativeWnd, NULL );
if( glSurface==0 )
{
debug_message( "GL Surface failed\n" );
}
debug_message( "EGL Init Completed\n" );
eglMakeCurrent( glDisplay, glSurface, glSurface, glContext );
gl_vendor = (const char*)glGetString (GL_VENDOR);
debug_message("GL_VENDOR: %s\n", gl_vendor);
gl_renderer = (const char*)glGetString (GL_RENDERER);
debug_message("GL_RENDERER: %s\n", gl_renderer);
gl_version = (const char*)glGetString (GL_VERSION);
debug_message("GL_VERSION: %s\n", gl_version);
gl_extensions = (const char*)glGetString (GL_EXTENSIONS);
debug_message("GL_EXTENSIONS: %s\n", gl_extensions);
GLfloat m[16];
get_ortho_matrix(320, 240, m);
glMatrixMode(GL_PROJECTION);
glLoadMatrixf(m);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDepthMask(GL_FALSE);
GLfloat verts[] = { 0, 0, -5, 160, 240, -5, 320, 0, -5 };
GLfloat colors[] = { 1.0, 0, 0, 0, 1.0, 0, 0, 0, 1.0 };
GLushort indices[] = { 0, 1, 2 };
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glColorPointer(3, GL_FLOAT, 0, colors);
glVertexPointer(3, GL_FLOAT, 0, verts);
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_SHORT, indices);
//glDrawArrays(GL_TRIANGLES, 0, 3);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
eglSwapBuffers(glDisplay,glSurface);
usleep(1000000*3);
nanoGL_Destroy();
}