M-HT
Very Active Member
I was particularly interested in GL_OES_draw_texture, ...
I have never succeed in using GL_OES_draw_texture. It never draw anything for me. That's a shame, because it sound simple to use, but I always get nothing...
I tried using GL_OES_draw_texture and it works. You need to use correct coordinate system - the screen coordinate 0,0 is in the bottom left corner.
Here is a working simplified example (using EGLPort library):
Code:
#include <GLES/gl.h>
#include <GLES/glext.h>
#include <EGL/egl.h>
#include "eglport.h"
#include <SDL/SDL.h>
#include <stdint.h>
#include <memory.h>
uint8_t *texdata;
GLuint texture[1];
PFNGLDRAWTEXIOESPROC glDrawTexiOES;
static void prepareTexture(void) {
int i, j;
texdata = (uint8_t *) malloc(256*256*3);
for (i = 0; i <= 255; i++) {
for (j = 0; j <= 255; j++) {
texdata[3 * 256 * i + 3 * j + 0] = (i + j) / 2;
texdata[3 * 256 * i + 3 * j + 1] = (i + j) / 2;
texdata[3 * 256 * i + 3 * j + 2] = (i + j) / 2;
}
}
glGenTextures(1, &texture[0]);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, texdata);
}
static void DrawGLScene(void) {
glClear(GL_COLOR_BUFFER_BIT);
glBindTexture(GL_TEXTURE_2D, texture[0]);
GLint coords [] = {50, 50, 200, 164};
glTexParameteriv( GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, coords );
glDrawTexiOES( 200, 280, 0, 300, 200 );
EGL_SwapBuffers();
}
int main(int argc, char **argv) {
int done;
SDL_Event event;
SDL_Init(SDL_INIT_VIDEO);
SDL_SetVideoMode(800, 480, 0, SDL_FULLSCREEN);
EGL_Open(800, 480);
glEnable(GL_TEXTURE_2D);
// should check first if "GL_OES_draw_texture" extension is available
glDrawTexiOES = (PFNGLDRAWTEXIOESPROC) eglGetProcAddress("glDrawTexiOES");
prepareTexture();
done = 0;
while ( ! done ) {
DrawGLScene();
while ( SDL_PollEvent(&event) ) {
if ( event.type == SDL_QUIT ) done = 1;
if ( event.type == SDL_KEYDOWN ) {
if ( event.key.keysym.sym == SDLK_ESCAPE ) done = 1;
}
}
}
EGL_Close();
SDL_Quit();
return 0;
}