Q: I am trying to bind a texture and display the same using egl. I am not able to see the display,
could any one let me know if I am doing something wrong here.
I use the vincent 3D implementation of OpenGL ES
<code>
#include <GLES/gl.h>
#include <GLES/glext.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <assert.h>
#include <string.h>
#include <unistd.h>
#include “egl.h”
/* Declaration */
EGLDisplay egldisplay;
EGLConfig eglconfig;
EGLSurface eglsurface;
EGLContext eglcontext;
EGLint numconfigs;
//Main function call of the application
int main(void)
{
static const EGLint s_configAttribs[] =
{
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, 0,
EGL_LUMINANCE_SIZE, EGL_DONT_CARE,
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT,
EGL_NONE
};
unsigned int * raw_bitmap;
int height = 320;
int width = 240;
int depth = 4;
char *file_name = "redhand.png";
EGLint numconfigs;
structNativePixmapI natpix;
FILE *file;
if ((file = fopen(file_name, "rb"))==NULL)
{
printf("File Not Found : %s/n",file_name);
exit (1);
}
raw_bitmap = (unsigned int *)malloc(width * height * depth * (sizeof(unsigned int)));
if (raw_bitmap == NULL)
{
printf ("Cannot allocate memory for texture/n");
fclose (file);
exit (1);
}
fread (raw_bitmap , width * height * depth, 1 , file);
fclose (file);
printf("Bind API of GLES is called
");
eglBindAPI(EGL_OPENGL_ES_API);
egldisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
eglInitialize(egldisplay, NULL, NULL);
eglChooseConfig(egldisplay, s_configAttribs, &eglconfig, 1, &numconfigs);
eglsurface = eglCreateWindowSurface(egldisplay, eglconfig,0, NULL);
eglcontext = eglCreateContext(egldisplay, eglconfig, NULL, NULL);
eglMakeCurrent(egldisplay, eglsurface, eglsurface, eglcontext);
printf("GLES operation started
“);
int handle;
glEnable( GL_TEXTURE_2D );
glGenTextures (1, &handle);
glBindTexture (GL_TEXTURE_2D, handle);
printf (” handle %d
",handle);
glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);//GL_NEAREST_MIPMAP_NEAREST GL_LINEAR_MIPMAP_NEAREST
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA,
256,512, 0, GL_RGBA, GL_UNSIGNED_BYTE, raw_bitmap);
eglSwapBuffers(egldisplay, eglsurface);
//De Associating the context
eglMakeCurrent(egldisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
eglDestroySurface(egldisplay,eglsurface);
eglTerminate(egldisplay);
}