OpenGL functions not resolving

Even if I included cocos2d.h and use using namespace cocos2d;, I keep getting undefined reference to glColor4f. I’m using eclipse for this.

glColor4f() is an api of opengles, you could include gl.h

you can reference to cocos2dx/platform/CCGL.h

sorry, but it still won’t work.

`RongHong it can’t find gl.h

`Walzer I tried #include “CCGL.h”. It compiled, but still couldn’t find glColor4f when it was linking the object files.

Could you find the following codes in CCGL.h

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
#include <GLES/gl.h>
#include <GLES/glext.h>
#endif

If so , you could open gl.h, and you could find the declaration
GL_API void GL_APIENTRY glColor4f (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);

BTW, could you run Helloworld successfully?

There is no glColor4f in OpenGL ES, just like the rest of immediate mode doesn’t exist in ES. It was left away for speed ~~-~~and- for implementation size .

You can use glColorPointer instead . It’s a bit more work, but it works the same as on normal OpenGL.

Please ignore, this information is invalid :slight_smile:

glEnable() won’t work either. Unlike glColor4f(), I really need glEnable() to work. I need anti-aliasing cause the lines I draw are too jagged.

`Strawberrry Milkshake awesome name. On a more serious note, I can’t get glEnable() to work, and that one’s more important cause I need anti-aliasing. Or is there another function I should be using?

RongHong Yes, I can find those. I even tried ctrl+clicking in eclipse and it managed to find the functions, but even then, it won’t work. I tried adding#include “CCGL.h”`, but it still didn’t resolve. It says the functions are not defined.

@Walzer I tried that too, but it couldn’t find that. I’m still using the directory created by the create-android-project.bat script, and the only thing i’ve changed in the folder so far has been the android.mk file in the jni folder. I didn’t delete anything, I just included the new classes I made.

Hmm, I was wrong. glColor4f does seem to exist for GLES :blush: (I thought it was part of the left out immediate mode, but it seems to be one of the few exceptions here). Sorry for giving false information.

Maybe you could upload a sample project that doesn’t work for you? If it does work for others, you will at least know for sure that the problem is somewhere with your compiler configuration and not the code.

Are you using the official NDK with Cygwin?

ps. Thanks :slight_smile:

Sorry this is late. I made a new android project named OpenGL_Test, and set it to be compatible with android-2.1update1. In HelloWorldScene::init(), I put in the following lines:

    glEnable(GL_LINE_SMOOTH);
    ccDrawLine(ccp(0, 0), ccp(400, 400));

In eclipse, I got the following errors:

...
Install        : libcocos2d.so => libs/armeabi/libcocos2d.so
Compile++ thumb  : cocosdenshion <= SimpleAudioEngine.cpp
Compile++ thumb  : cocosdenshion <= SimpleAudioEngineJni.cpp
SharedLibrary  : libcocosdenshion.so
Install        : libcocosdenshion.so => libs/armeabi/libcocosdenshion.so
Compile++ thumb  : game <= main.cpp
Compile++ thumb  : game <= AppDelegate.cpp
Compile++ thumb  : game <= HelloWorldScene.cpp
SharedLibrary  : libgame.so
C:/workspace/cocos2d-x/OpenGL_Test/android/obj/local/armeabi/objs-debug/game/../../../Classes/HelloWorldScene.o: In function `HelloWorld::init()':
C:/workspace/cocos2d-x/OpenGL_Test/android/jni/helloworld/../../../Classes/HelloWorldScene.cpp:72: undefined reference to `glEnable'
collect2: ld returned 1 exit status
make[1]: Leaving directory `/cygdrive/c/workspace/cocos2d-x/OpenGL_Test/android'
make[1]: *** [/cygdrive/c/workspace/cocos2d-x/OpenGL_Test/android/obj/local/armeabi/libgame.so] Error 1
make: *** [all] Error 2

Because the link order is: libGLESv1_CM.so > libcocos2d.so> libgame.so
Your game itself doesn’t link to libGLESv1_CM directly.
To resolve this, plese add

~~lGLESv1_CM
to MyGame/android/jni/helloworld/Android.mk
<pre>
LOCAL_LDLIBS :=~~L$(call host-path, $(LOCAL_PATH)/…/…/libs/armeabi) lcocos2dllog ~~lcocosdenshion ~~L$(call host-path, $(LOCAL_PATH)/…/…/…/…/cocos2dx/platform/third_party/android/libraries) ~~lcurl
~~lGLESv1_CM

thanks. that fixed it.

@Walzer Wang : I am also facing same issue, how to do the same for Xcode - cocos2dx?

Thanks and after adding “~~lGLESv1_CM" I was able to compile, but my executable increases by about 4mb in size. Can I statically link that library to avoid blowing up the size so much? If I updated to a newer version can I use a blend function to add alpha to a sprite I’m drawing on a tilemap with cc_vertexz and remove the "~~lGLESv1_CM”? I’m currently using 0.11x

Jeff

Gdbserver : [arm-linux-androideabi-4.4.3] libs/armeabi/gdbserver
Gdbsetup : libs/armeabi/gdb.setup
Compile*+ thumb : game_shared <= main.cpp
Compile*+ thumb : game_shared <= AppDelegate.cpp
Compile*+ thumb : game_shared <= MyContactListener.cpp
Compile*+ thumb : game_shared <= GLES-Render.cpp
jni/…/…/Classes/GLES-Render.cpp: In member function ‘virtual void GLESDebugDra
w::DrawPolygon(const b2Vec2**, int, const b2Color&)’:
jni/…/…/Classes/GLES-Render.cpp:26: error: ’glColor4f’ was not declared in thi
s scope
jni/…/…/Classes/GLES-Render.cpp:27: error: ’glVertexPointer’ was not declared
in this scope
jni/…/…/Classes/GLES-Render.cpp: In member function ’virtual void GLESDebugDra
w::DrawSolidPolygon’:
jni/…/…/Classes/GLES-Render.cpp:41: error: ’glVertexPointer’ was not declared
in this scope
jni/…/…/Classes/GLES-Render.cpp:43: error: ’glColor4f’ was not declared in thi
s scope
jni/…/…/Classes/GLES-Render.cpp: In member function ’virtual void GLESDebugDra
w::DrawCircle’:
jni/…/…/Classes/GLES-Render.cpp:69: error: ’glColor4f’ was not declared in thi
s scope
jni/…/…/Classes/GLES-Render.cpp:70: error: ’glVertexPointer’ was not declared
in this scope
jni/…/…/Classes/GLES-Render.cpp: In member function ’virtual void GLESDebugDra
w::DrawSolidCircle’:
jni/…/…/Classes/GLES-Render.cpp:94: error: ’glColor4f’ was not declared in thi
s scope
jni/…/…/Classes/GLES-Render.cpp:95: error: ’glVertexPointer’ was not declared
in this scope
jni/…/…/Classes/GLES-Render.cpp: In member function ’virtual void GLESDebugDra
w::DrawSegment’:
jni/…/…/Classes/GLES-Render.cpp:108: error: ’glColor4f’ was not declared in th
is scope
jni/…/…/Classes/GLES-Render.cpp:114: error: ’glVertexPointer’ was not declared
in this scope
jni/…/…/Classes/GLES-Render.cpp: In member function ’virtual void GLESDebugDra
w::DrawPoint’:
jni/…/…/Classes/GLES-Render.cpp:132: error: ’glColor4f’ was not declared in th
is scope
jni/…/…/Classes/GLES-Render.cpp:133: error: ’glPointSize’ was not declared in
this scope
jni/…/…/Classes/GLES-Render.cpp:137: error: ’glVertexPointer’ was not declared
in this scope
jni/…/…/Classes/GLES-Render.cpp: In member function ’virtual void GLESDebugDra
w::DrawAABB’:
jni/…/…/Classes/GLES-Render.cpp:151: error: ’glColor4f’ was not declared in th
is scope
jni/…/…/Classes/GLES-Render.cpp:159: error: ’glVertexPointer’ was not declared
in this scope
make:**** [obj/local/armeabi/objs-debug/game_shared///Classes/GLES-Render.o]
Error 1
make: Leaving directory `/cygdrive/A/cocos2d-2.0-x-2.0.4/simpleBox2d/proj.androi
d’