triangle.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #include "Crown.h"
  2. #include "OS.h"
  3. #include <jni.h>
  4. #include <GLES/gl.h>
  5. namespace crown
  6. {
  7. extern "C"
  8. {
  9. JNIEXPORT bool JNICALL Java_crown_android_CrownLib_init(JNIEnv* env, jobject obj);
  10. JNIEXPORT bool JNICALL Java_crown_android_CrownLib_frame(JNIEnv* env, jobject obj);
  11. JNIEXPORT bool JNICALL Java_crown_android_CrownLib_shutdown(JNIEnv* env, jobject obj);
  12. };
  13. void draw_triangle()
  14. {
  15. static GLfloat vertices[] = { -1.0f, -1.0f, -2.0f,
  16. 1.0f, -1.0f, -2.0f,
  17. 0.0f, 1.0f, -2.0f};
  18. GetDevice()->GetRenderer()->SetMatrix(MT_MODEL, Mat4::IDENTITY);
  19. Mat4 projection;
  20. projection.build_projection_perspective_rh(90.0f, 800.0f/480.0f, 0.1f, 100.0f);
  21. GetDevice()->GetRenderer()->SetMatrix(MT_PROJECTION, projection);
  22. GetDevice()->GetRenderer()->SetClearColor(Color4::RED);
  23. glEnableClientState(GL_VERTEX_ARRAY);
  24. glVertexPointer(3, GL_FLOAT, 0, vertices);
  25. glDrawArrays(GL_TRIANGLES, 0, 9);
  26. glDisableClientState(GL_VERTEX_ARRAY);
  27. }
  28. void init()
  29. {
  30. Device* mDevice = GetDevice();
  31. if (!mDevice->Init(0, NULL))
  32. {
  33. return;
  34. }
  35. }
  36. void frame()
  37. {
  38. Device* mDevice = GetDevice();
  39. os::event_loop();
  40. GetInputManager()->EventLoop();
  41. GetDevice()->GetRenderer()->_BeginFrame();
  42. draw_triangle();
  43. GetDevice()->GetRenderer()->_EndFrame();
  44. os::swap_buffers();
  45. }
  46. void shutdown()
  47. {
  48. GetDevice()->Shutdown();
  49. }
  50. JNIEXPORT bool JNICALL Java_crown_android_CrownLib_init(JNIEnv* env, jobject obj)
  51. {
  52. Log::I("Crown initialized.");
  53. init();
  54. }
  55. JNIEXPORT bool JNICALL Java_crown_android_CrownLib_frame(JNIEnv* env, jobject obj)
  56. {
  57. Log::I("Render frame.");
  58. frame();
  59. }
  60. JNIEXPORT bool JNICALL Java_crown_android_CrownLib_shutdown(JNIEnv* env, jobject obj)
  61. {
  62. Log::I("Shutdown Crown.");
  63. shutdown();
  64. }
  65. } // namespace crown