首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

Android 3D与JNI组合的小例子【转】

2012-09-01 
Android 3D与JNI结合的小例子【转】?? ?? ???#include jni.h? ?? ???#include android/log.h? ?? ???#in

Android 3D与JNI结合的小例子【转】

Android 3D与JNI组合的小例子【转】Android 3D与JNI组合的小例子【转】Android 3D与JNI组合的小例子【转】Android 3D与JNI组合的小例子【转】?

    ? ?? ???#include <jni.h>
    ? ?? ???#include <android/log.h>

    ? ?? ???#include <GLES2/gl2.h>
    ? ?? ???#include <GLES2/gl2ext.h>
    ? ?? ???#include <GLES/gl.h>

    ? ?? ???#include <stdio.h>
    ? ?? ???#include <stdlib.h>
    ? ?? ???#include <math.h>


    ? ?? ???const GLfloat gTriangleVertices[] = {
    ? ?? ?? ?? ?? ? -0.5f, -0.5f, 0.5f,
    ? ?? ?? ?? ?? ? 0.5f, -0.5f,0.5f,
    ? ?? ?? ?? ?? ? 0.0f,-0.5f, 1.0f,
    ? ?? ?? ?? ?? ? 0.0f, 0.0f, 0.5f,
    ? ?? ???};

    ? ?? ???const GLfloat _colorArray[] = {
    ? ?? ?? ?? ?? ?? ?? ?? ?1.0f,0.0f,0.0f,1.0f,
    ? ?? ?? ?? ?? ?? ?? ?? ?0.0f,1.0f,0.0f,1.0f,
    ? ?? ?? ?? ?? ?? ?? ?? ?0.0f,0.0f,1.0f,1.0f,
    ? ?? ?? ?? ?? ?? ?? ?? ?1.0f,1.0f,1.0f,1.0f,
    ? ?? ?? ? };

    ? ?? ???const GLbyte _indexArray[] = {
    ? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? 0,1,3,
    ? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? 0,2,1,
    ? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? 0,3,2,
    ? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? 1,2,3,
    ? ?? ???};

    ? ?? ?? ?GLfloat _xAngle = 0.0f;
    ? ?? ?? ?GLfloat _yAngle = 0.0f;

    ? ?? ???extern "C" {
    ? ?? ?? ?? ?? ? JNIEXPORT void JNICALL Java_com_geolo_android_MyRenderer_nativeSurfaceCreated(JNIEnv * env, jobject obj);
    ? ?? ?? ?? ?? ? JNIEXPORT void JNICALL Java_com_geolo_android_MyRenderer_nativeSurfaceChanged(JNIEnv * env, jobject obj,??jint width, jint height);
    ? ?? ?? ?? ?? ? JNIEXPORT void JNICALL Java_com_geolo_android_MyRenderer_nativeDrawFrame(JNIEnv * env, jobject obj);
    ? ?? ?? ?? ?? ? JNIEXPORT void JNICALL Java_com_geolo_android_MyGLSurfaceView_setXYangle(JNIEnv * env, jobject obj,jfloat x , jfloat y);
    ? ?? ???};

    ? ?? ???JNIEXPORT void JNICALL Java_com_geolo_android_MyRenderer_nativeSurfaceCreated(JNIEnv * env, jobject obj){
    ? ?? ?? ?? ?? ??
    ? ?? ???}

    ? ?? ???JNIEXPORT void JNICALL Java_com_geolo_android_MyRenderer_nativeSurfaceChanged(JNIEnv * env, jobject obj,jint w,jint h){

    ? ?? ???}

    ? ?? ???JNIEXPORT void JNICALL Java_com_geolo_android_MyRenderer_nativeDrawFrame(JNIEnv * env, jobject obj){
    ? ?? ?? ?? ?? ? glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    ? ?? ?? ?? ?? ? //glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
    ? ?? ?? ???// glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, 0, gTriangleVertices);
    ? ?? ?? ???// glColorAttribPointer(4 , GL_FLOAT , 0, _colorArray );
    ? ?? ?? ???// glDrawArrays(GL_TRIANGLES, 0, 3);

    ? ?? ?? ???glClear(GL_COLOR_BUFFER_BIT);
    ? ?? ? //glLoadIdentity();

    ? ?? ?? ???glRotatef(_xAngle, 0.5f, 0.0f, 0.0f);
    ? ?? ?? ???glRotatef(_yAngle, 0.0f, 0.5f, 0.0f);

    ? ?? ?? ???//顶点
    ? ?? ?? ???glVertexPointer(3, GL_FLOAT, 0, gTriangleVertices);

    ? ?? ?? ???//顶点颜色
    ? ?? ?? ???glColorPointer(4, GL_FLOAT, 0, _colorArray);


    ? ?? ?? ???glDrawElements(GL_TRIANGLES, 12, GL_UNSIGNED_BYTE, _indexArray);
    ? ?? ???}

    ? ?? ???JNIEXPORT void JNICALL Java_com_geolo_android_MyGLSurfaceView_setXYangle(JNIEnv * env, jobject obj,jfloat x , jfloat y){
    ? ?? ?? ???_xAngle = x;
    ? ?? ? _yAngle = y;
    ? ?? ???}
复制代码


第二重要的部分是:Android.mk


view plaincopy to clipboardprint?


  • # Copyright (C) 2009 The Android Open Source Project
  • #
  • # Licensed under the Apache License, Version 2.0 (the "License");
  • # you may not use this file except in compliance with the License.
  • # You may obtain a copy of the License at
  • #
  • #? ?? ?http://www.apache.org/licenses/LICENSE-2.0
  • #
  • # Unless required by applicable law or agreed to in writing, software
  • # distributed under the License is distributed on an "AS IS" BASIS,
  • # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • # See the License for the specific language governing permissions and
  • # limitations under the License.
  • #
  • LOCAL_PATH:= $(call my-dir)??
  • include $(CLEAR_VARS)??
  • LOCAL_MODULE? ? := Geolo3D??
  • LOCAL_CFLAGS? ? := -Werror??
  • LOCAL_SRC_FILES := NativeRenderer.cpp??
  • LOCAL_LDLIBS? ? := -llog -lGLESv2 -lGLESv1_CM -ldl??
  • include $(BUILD_SHARED_LIBRARY)??


    其中Android.mk重要的部分是:LOCAL_LDLIBS? ? := -llog -lGLESv2 -lGLESv1_CM -ldl

    比如,如果没有-ldl 是不能在C/C++中调用? ?glVertexPointer(3, GL_FLOAT, 0, gTriangleVertices);和

    glColorPointer(4, GL_FLOAT, 0, _colorArray);

    -ldl是个函数库,我没有这方面的资料文档,如果那个哥们有这些文档,请发给我,geolo@vip.qq.com。谢谢。。。




    Android 3D与JNI组合的小例子【转】?geolo.OpenGL.JNI.rar?(73.9 KB, 下载次数: 23)?

热点排行