Hi, I'm working on a game that uses opengl 1.1. I hope to use opengl
to print a texture directly to the screen in 2D. I'm only just getting
started. I'm following a blog post at this location:

http://quirkygba.blogspot.com/2010/10/android-native-coding-in-c.html

I cannot get it to work, though. Enclosed is a large piece of code
that should print something to the screen. Anything would be good. Now
it just prints black. If I uncomment the 'glClearColor' and 'glClear'
lines I can get a color to the screen, so I know that I can call an
opengl command and have it work. It's almost as if 'glDrawTexiOES'
doesn't work. I'm using ndk 7b and I've tested on the emulator as well
as a 2.2 and 2.3 device. Any help would be appreciated.

// Android.mk file ////////////////////////

LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := something
LOCAL_CFLAGS    := -Werror
LOCAL_SRC_FILES := something.c
LOCAL_LDLIBS    := -llog -lGLESv1_CM

include $(BUILD_SHARED_LIBRARY)

// something.c ////////////////////////////////


//some other includes here.
#include <GLES/gl.h>
#include <GLES/glext.h>


#define  LOG_TAG              "something-jni"
#define  LOGI(...)
__android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
#define  LOGE(...)
__android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
#define RGB565(r, g, b)  (((r) << (5+6)) | ((g) << 6) | (b))

#define TRUE 1
#define FALSE 0

#define TEX_WIDTH   256
#define TEX_HEIGHT  256

#define TEX_DIMENSION   256

static uint16_t *pixbuf = NULL;
static GLuint   texture;
static int screen_width, screen_height;

static void check_gl_error(const char* op)
{
        GLint error;
        for (error = glGetError(); error; error = glGetError())
        LOGE("after %s() glError (0x%x)\n", op, error);
}



void init(void)
{
        int i;
        int tex_width, tex_height;


        tex_width = TEX_WIDTH;
        tex_height = TEX_HEIGHT;

        GLint crop[4] = { 0, tex_height, tex_width, - tex_height };

        pixbuf = malloc(tex_width * tex_height * 2);
                for (i = 0; i < TEX_DIMENSION * TEX_DIMENSION ; i ++ ) {
                pixbuf[i] = 0xffff;//RGB565(0xf,0,0);
        }

        glEnable(GL_TEXTURE_2D);

        glGenTextures(1, &texture);
        glBindTexture(GL_TEXTURE_2D, texture);

        glTexParameterf( GL_TEXTURE_2D,
                        GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        check_gl_error("glTexParameteri");

        glTexParameterf( GL_TEXTURE_2D,
                        GL_TEXTURE_MAG_FILTER, GL_LINEAR);

        check_gl_error("glTexParameteri");

        glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
        check_gl_error("glTexParameteriv");

        glShadeModel(GL_FLAT);
        check_gl_error("glShadeModel");

        glTexImage2D(GL_TEXTURE_2D, 0,
                GL_RGB,
                tex_width, tex_height,
                0,
                GL_RGB,
                GL_UNSIGNED_SHORT_5_6_5,
                pixbuf);
        check_gl_error("glTexImage2D");


        glDisable(GL_BLEND);
        glDisable(GL_DITHER);
        glDisable(GL_DEPTH_TEST);
        glDisable(GL_FOG);
        glDisable(GL_LIGHTING);
        glDisable(GL_ALPHA_TEST);
        glDisable(GL_COLOR_LOGIC_OP);
        glDisable(GL_COLOR_MATERIAL);
        glDisable(GL_STENCIL_TEST);

        glDepthMask(GL_FALSE);
        check_gl_error("glDepthMask");

        glDisable(GL_CULL_FACE);
        check_gl_error("glDisable");

        //glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
        //glClear(GL_COLOR_BUFFER_BIT);
        glDrawTexiOES(0, 0, 0, screen_width, screen_height);

        check_gl_error("glDrawTexiOES");

}

// JNI methods for something.c ////////////////


JNIEXPORT void JNICALL Java_org_..._Panel_JNIinit(JNIEnv * env,
jobject  obj, jint w, jint h)
{
        //screen_width = w;
        //screen_height = h;
        init();

}
// END /////////////////////////

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to