1

Android で NDK プラットフォームを介して C++ ベースのプログラムを実行しようとすると、「gl.h」および「glext.h」ヘッダー ファイルが見つからないというエラーがコンパイルで発生します。これは、両方のヘッダー ファイルを C++ コードに含めたためです。M は android-ndk-r8 を使用し、Cygwin でコンパイルします。

here s my code:   
**ANDROID.MK**

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := NDK1
FILE_LIST := $(wildcard $(LOCAL_PATH)/*.cpp) 
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%) 

include $(BUILD_SHARED_LIBRARY)

---
**APPLICATION.MK**

APP_STL := stlport_static
APP_ABI := armeabi armeabi-v7a 
APP_PLATFORM := android-3

---
**Viewer.cpp**

#include <iostream>

#import "OpenGLES/ES2/gl.h"
#import "OpenGLES/ES2/glext.h"

//#import <GLKit/GLKEffects.h>
#import <GLKit/GLKMath.h>

#include "Viewer.h"

void Viewer::render() {
    glClearColor(0.65f, 0.65f, 0.65f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glBindVertexArrayOES( _vertexArray[0]);

    // Render the object with GLKit


    glDrawArrays(GL_TRIANGLES, 0, 36);

    /////////
    glBindVertexArrayOES(_vertexArray[1]);

    // Render the object with GLKit
    //[self.effect prepareToDraw];

    glDrawArrays(GL_TRIANGLES, 0, 36);
}

void Viewer::initialize() {
    sceneObj.constructDemoScene();

    glEnable( GL_DEPTH_TEST);

    ///////////////////////////////////
    glGenVertexArraysOES(1, &_vertexArray[0]);
    glBindVertexArrayOES( _vertexArray[0]);

    glGenBuffers(1, &_vertexBuffer[0]);
    glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer[0]);
    H3DModel * model = sceneObj.get3DModel(0);
    float * vertices = model->vertexBuffObj.getVertices();
    for (int c = 0; c < 216; c++)
        printf("%f\t", vertices[c]);
    glBufferData(GL_ARRAY_BUFFER, 216 * 4, vertices, GL_STATIC_DRAW);

    glEnableVertexAttribArray( EVertexAttribPosition);
    glVertexAttribPointer(EVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, 24,
            (void*) offsetof(Vertex, position));
    glEnableVertexAttribArray( EVertexAttribNormal);
    glVertexAttribPointer(EVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, 24,
            (void*) offsetof(Vertex, normal));

    ///////////////////////////////////

    glGenVertexArraysOES(2, &_vertexArray[1]);
    glBindVertexArrayOES(_vertexArray[1]);

    glGenBuffers(2, &_vertexBuffer[1]);
    glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer[1]);
    H3DModel * model1 = sceneObj.get3DModel(1);
    float * vertices1 = model1->vertexBuffObj.getVertices();
    for (int c = 0; c < 216; c++)
        printf("%f\t", vertices[c]);
    glBufferData(GL_ARRAY_BUFFER, 216 * 4, vertices1, GL_STATIC_DRAW);

    glEnableVertexAttribArray(EVertexAttribPosition);
    glVertexAttribPointer(EVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, 24,
            (void*) offsetof(Vertex, position));
    glEnableVertexAttribArray(EVertexAttribNormal);
    glVertexAttribPointer(EVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, 24,
            (void*) offsetof(Vertex, normal));

    glBindVertexArrayOES(0);
}

void Viewer::unInitialize() {
    glDeleteBuffers(1, &_vertexBuffer[0]);
    glDeleteBuffers(2, &_vertexBuffer[1]);
    glDeleteVertexArraysOES(1, &_vertexArray[0]);
    glDeleteVertexArraysOES(2, &_vertexArray[1]);

    if (_program) {
        glDeleteProgram( _program);
        _program = 0;
    }
}

GLKMatrix4 Viewer::update() {
    GLKMatrix4 baseModelViewMatrix = GLKMatrix4MakeTranslation(0.0f, 0.0f,
            -4.0f);
    baseModelViewMatrix = GLKMatrix4Rotate(baseModelViewMatrix, _rotation,
            0.0f, 1.0f, 0.0f);

    // Compute the model view matrix for the object rendered with GLKit
    //GLKMatrix4 modelViewMatrix = GLKMatrix4MakeTranslation(0.0f, 0.0f, -1.5f);
    //modelViewMatrix = GLKMatrix4Rotate(modelViewMatrix, _rotation, 1.0f, 1.0f, 1.0f);
    //modelViewMatrix = GLKMatrix4Multiply(baseModelViewMatrix, modelViewMatrix);

    //self.effect.transform.modelviewMatrix = baseModelViewMatrix;

    /*// Compute the model view matrix for the object rendered with ES2
     modelViewMatrix = GLKMatrix4MakeTranslation(0.0f, 0.0f, 1.5f);
     modelViewMatrix = GLKMatrix4Rotate(modelViewMatrix, _rotation, 1.0f, 1.0f, 1.0f);
     modelViewMatrix = GLKMatrix4Multiply(baseModelViewMatrix, modelViewMatrix);

     _normalMatrix = GLKMatrix3InvertAndTranspose(GLKMatrix4GetMatrix3(modelViewMatrix), NULL);

     _modelViewProjectionMatrix = GLKMatrix4Multiply(projectionMatrix, modelViewMatrix);*/

    _rotation += 0.04f;
    return baseModelViewMatrix;
}

前もって感謝します.. Android ndkでOPENGL ESを使用する方法を知りたいです!!

4

4 に答える 4

5

よくわかりませんが、google ndk が提供するサンプル コードを調べてみると、大きな助けになると思います。

にあるサンプルコード

    android-ndk-r7b\samples\hello-gl2\jni\gl_code.cpp

Android.mk を比較すると、

    LOCAL_LDLIBS    := -llog -lGLESv2

不足している。Google が提供する Android.mk は次のようになります。

    LOCAL_PATH:= $(call my-dir)

    include $(CLEAR_VARS)

    LOCAL_MODULE    := libgl2jni
    LOCAL_CFLAGS    := -Werror
    LOCAL_SRC_FILES := gl_code.cpp
    LOCAL_LDLIBS    := -llog -lGLESv2

    include $(BUILD_SHARED_LIBRARY)

また、cpp ソース コードでは、Android は以下を使用しています。

    #include <GLES2/gl2.h>
    #include <GLES2/gl2ext.h>
于 2012-05-29T11:51:44.900 に答える
1

#importC/C++のようなものはありません。また、レベルを上げる必要がありAPP_PLATFORMます。OpenGL ES 1 は からのみ入手できandroid-4、OpenGL ES 2 は から入手できますandroid-5。それはすべて documentation:docs/STABLE-APIS.htmlファイルにあります。

于 2012-05-29T15:35:22.583 に答える
1

jni ディレクトリにビルドしようとしていたと思います。Android プロジェクトのルート ディレクトリで再試行してください。

于 2012-11-05T13:27:59.313 に答える
0

この問題がまだ一般的かどうかはわかりません。私はちょうどこの問題を抱えていて、1つの解決策を見つけました。「jni」ディレクトリに「Application.mk」というファイルが必要であることがわかりました。

これは私の「Application.mk」です:

APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi armeabi-v7a
APP_PLATFORM := android-14

「APP_PLATFORM := android-14」は、Android に Opengl ES の使用を通知したと思います。実際、「APP_PLATFORM := android-5」は OpenGL 2.x の最小要件です。

于 2014-05-28T02:25:25.870 に答える