How to run OpenGL ES commands from native code?

702 views
Skip to first unread message

Atul Prakash

unread,
Apr 26, 2011, 3:42:49 AM4/26/11
to android-ndk
Hello Folks,

I am trying to load demo 3D model using Android NDK from .CPP files &
I am following the program structure just like San Angeles demo
application.

I am having doubt about including the OpenGL ES header files in
my .CPP files i.e. when I write:

# include <GLES/gl.h>

It is showing warning: Unresolved inclusion <GLES/gl.h>

None of my GL command is running, although I have successfully
compiled the native code. I have created importgl.cpp & importgl.h
also, just like San Angeles.

Can somebody tell me how to include OpenGL files in native code & how
these importgl.c & importgl.h are implemented in the San Angeles Demo?
Any ideas...

Thanks in advance.

Atul Prakash Singh

mic _

unread,
Apr 26, 2011, 4:12:34 AM4/26/11
to andro...@googlegroups.com
You should take a look at the hello-gl2 example that comes with the NDK. It does OpenGL ES calls from native code.

/Michael


--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.


Atul Prakash

unread,
Apr 26, 2011, 5:26:16 AM4/26/11
to android-ndk
Dear Michael,

I have studied hello-gl2 example too, but this example is not running
on Android Emulator as it uses OpenGL ES 2.0 apis. Is there exits any
solution to make this hello-gl2 example to run on Android Emulator
i.e. by deleting the OpenGL ES 2.0 specific code. If it exists, kindly
guide me...

Regards,

Atul Prakash Singh

On Apr 26, 1:12 pm, mic _ <micol...@gmail.com> wrote:
> You should take a look at the hello-gl2 example that comes with the NDK. It
> does OpenGL ES calls from native code.
>
> /Michael
>

mic _

unread,
Apr 26, 2011, 6:00:48 AM4/26/11
to andro...@googlegroups.com
I can't verify it as I don't have the NDK set up on this computer, but I don't see why that wouldn't work. Just replace the gl2 headers with gl, change the gles library that is linked against in the makefile, and remove the shader stuff in the source code. You might have to add a call glColor in the render method before you draw the vertices, since the color is set in the fragment shader in the gles 2.0 version.

/Michael

Atul Prakash

unread,
Apr 26, 2011, 7:03:11 AM4/26/11
to android-ndk
I tried according to your advice but when I compiled my native code
using Cygwin, I got errors like below:

MYPC@MYPC-PC /cygdrive/c/android-ndk-r5b/samples/hello-gl2
$ ndk-build
Compile++ thumb : gl2jni <= gl_code.cpp
C:/android-ndk-r5b/samples/hello-gl2/jni/gl_code.cpp: In function
'GLuint loadShader(GLenum, const char*)':
C:/android-ndk-r5b/samples/hello-gl2/jni/gl_code.cpp:58: error:
'glCreateShader' was not declared in this scope
C:/android-ndk-r5b/samples/hello-gl2/jni/gl_code.cpp:60: error:
'glShaderSource' was not declared in this scope
C:/android-ndk-r5b/samples/hello-gl2/jni/gl_code.cpp:61: error:
'glCompileShader' was not declared in this scope
C:/android-ndk-r5b/samples/hello-gl2/jni/gl_code.cpp:63: error:
'GL_COMPILE_STATUS' was not declared in this scope
C:/android-ndk-r5b/samples/hello-gl2/jni/gl_code.cpp:63: error:
'glGetShaderiv' was not declared in this scope
C:/android-ndk-r5b/samples/hello-gl2/jni/gl_code.cpp:66: error:
'GL_INFO_LOG_LENGTH' was not declared in this scope
C:/android-ndk-r5b/samples/hello-gl2/jni/gl_code.cpp:70: error:
'glGetShaderInfoLog' was not declared in this scope
C:/android-ndk-r5b/samples/hello-gl2/jni/gl_code.cpp:75: error:
'glDeleteShader' was not declared in this scope
C:/android-ndk-r5b/samples/hello-gl2/jni/gl_code.cpp: In function
'GLuint createProgram(const char*, const char*)':
C:/android-ndk-r5b/samples/hello-gl2/jni/gl_code.cpp:84: error:
'GL_VERTEX_SHADER' was not declared in this scope
C:/android-ndk-r5b/samples/hello-gl2/jni/gl_code.cpp:89: error:
'GL_FRAGMENT_SHADER' was not declared in this scope
C:/android-ndk-r5b/samples/hello-gl2/jni/gl_code.cpp:94: error:
'glCreateProgram' was not declared in this scope
C:/android-ndk-r5b/samples/hello-gl2/jni/gl_code.cpp:96: error:
'glAttachShader' was not declared in this scope
C:/android-ndk-r5b/samples/hello-gl2/jni/gl_code.cpp:100: error:
'glLinkProgram' was not declared in this scope
C:/android-ndk-r5b/samples/hello-gl2/jni/gl_code.cpp:102: error:
'GL_LINK_STATUS' was not declared in this scope
C:/android-ndk-r5b/samples/hello-gl2/jni/gl_code.cpp:102: error:
'glGetProgramiv' was not declared in this scope
C:/android-ndk-r5b/samples/hello-gl2/jni/gl_code.cpp:105: error:
'GL_INFO_LOG_LENGTH' was not declared in this scope
C:/android-ndk-r5b/samples/hello-gl2/jni/gl_code.cpp:109: error:
'glGetProgramInfoLog' was not declared in this scope
C:/android-ndk-r5b/samples/hello-gl2/jni/gl_code.cpp:114: error:
'glDeleteProgram' was not declared in this scope
C:/android-ndk-r5b/samples/hello-gl2/jni/gl_code.cpp: In function
'bool setupGraphics(int, int)':
C:/android-ndk-r5b/samples/hello-gl2/jni/gl_code.cpp:136: error:
'glGetAttribLocation' was not declared in this scope
C:/android-ndk-r5b/samples/hello-gl2/jni/gl_code.cpp: In function
'void renderFrame()':
C:/android-ndk-r5b/samples/hello-gl2/jni/gl_code.cpp:160: error:
'glUseProgram' was not declared in this scope
C:/android-ndk-r5b/samples/hello-gl2/jni/gl_code.cpp:163: error:
'glVertexAttribPointer' was not declared in this scope
C:/android-ndk-r5b/samples/hello-gl2/jni/gl_code.cpp:165: error:
'glEnableVertexAttribArray' was not declared in this scope
make: *** [/cygdrive/c/android-ndk-r5b/samples/hello-gl2/obj/local/
armeabi/objs/gl2jni/gl_code.o] Error 1
-----------------------------------------------------------------------------------------------------------------------------------------------------

I have replaced the gl2 headers with gl & in Android.mk file, I
changed the gles library as below:

LOCAL_LDLIBS := -llog -lGLESv1

But still all my efforts goes in vain..

Rgds/ Atul Prakash Singh

On Apr 26, 3:00 pm, mic _ <micol...@gmail.com> wrote:
> I can't verify it as I don't have the NDK set up on this computer, but I
> don't see why that wouldn't work. Just replace the gl2 headers with gl,
> change the gles library that is linked against in the makefile, and remove
> the shader stuff in the source code. You might have to add a call glColor in
> the render method before you draw the vertices, since the color is set in
> the fragment shader in the gles 2.0 version.
>
> /Michael
>

mic _

unread,
Apr 26, 2011, 7:10:47 AM4/26/11
to andro...@googlegroups.com
>>I have replaced the gl2 headers with gl & in Android.mk file, I
changed the gles library as below:

>>>> ...and remove the shader stuff in the source code

By that I meant that you should remove everything from the code that has to do with shaders, as OpenGL ES 1.1 doesn't support them.

/Michael

RLScott

unread,
Apr 26, 2011, 2:17:12 PM4/26/11
to android-ndk
I don't want to use OpenGL ES, but I want to do very primitive
graphics from the JNI side. What API besides OpenGL is available to
me?

mic _

unread,
Apr 26, 2011, 3:00:12 PM4/26/11
to andro...@googlegroups.com
Take a look at the bitmap-plasma example that comes with the NDK:  "a simple application that demonstrates how to access the pixel buffers of Android Bitmap objects from native code"
It requires Android 2.2 or later.

/Michael


--
Reply all
Reply to author
Forward
0 new messages