Clone of mesa.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // Simple BeOS GLView demo
  2. // Written by Brian Paul
  3. // Changes by Philippe Houdoin
  4. // This file is in the public domain.
  5. #include <stdio.h>
  6. #include <Application.h>
  7. #include <Window.h>
  8. #include <GLView.h>
  9. class MyGL : public BGLView
  10. {
  11. public:
  12. MyGL(BRect rect, char *name, ulong options);
  13. virtual void AttachedToWindow();
  14. virtual void Pulse();
  15. virtual void FrameResized(float w, float h);
  16. private:
  17. void Render();
  18. void Reshape(float w, float h);
  19. float mAngle;
  20. };
  21. class MyWindow : public BWindow
  22. {
  23. public:
  24. MyWindow(BRect frame);
  25. virtual bool QuitRequested();
  26. };
  27. MyWindow::MyWindow(BRect frame)
  28. : BWindow(frame, "demo", B_TITLED_WINDOW, B_NOT_ZOOMABLE)
  29. {
  30. // Make OpenGL view and put it in the window
  31. BRect r = Bounds();
  32. r.InsetBy(5, 5);
  33. MyGL *gl = new MyGL(r, "GL", BGL_RGB | BGL_DOUBLE);
  34. AddChild(gl);
  35. SetPulseRate(1000000 / 30);
  36. }
  37. bool MyWindow::QuitRequested()
  38. {
  39. be_app->PostMessage(B_QUIT_REQUESTED);
  40. return true;
  41. }
  42. MyGL::MyGL(BRect rect, char *name, ulong options)
  43. : BGLView(rect, name, B_FOLLOW_ALL_SIDES, B_PULSE_NEEDED, options)
  44. {
  45. mAngle = 0.0;
  46. }
  47. void MyGL::AttachedToWindow()
  48. {
  49. BGLView::AttachedToWindow();
  50. LockGL();
  51. glClearColor(0.7, 0.7, 0, 0);
  52. Reshape(Bounds().Width(), Bounds().Height());
  53. UnlockGL();
  54. }
  55. void MyGL::FrameResized(float w, float h)
  56. {
  57. BGLView::FrameResized(w, h);
  58. LockGL();
  59. Reshape(w, h);
  60. UnlockGL();
  61. Render();
  62. }
  63. void MyGL::Pulse()
  64. {
  65. mAngle += 1.0;
  66. Render();
  67. }
  68. void MyGL::Render()
  69. {
  70. LockGL();
  71. glClear(GL_COLOR_BUFFER_BIT);
  72. glPushMatrix();
  73. glRotated(mAngle, 0, 0, 1);
  74. glColor3f(0, 0, 1);
  75. glBegin(GL_POLYGON);
  76. glVertex2f(-1, -1);
  77. glVertex2f( 1, -1);
  78. glVertex2f( 1, 1);
  79. glVertex2f(-1, 1);
  80. glEnd();
  81. glPopMatrix();
  82. SwapBuffers();
  83. UnlockGL();
  84. }
  85. void MyGL::Reshape(float w, float h)
  86. {
  87. glViewport(0, 0, (int) (w + 1), (int) (h + 1));
  88. glMatrixMode(GL_PROJECTION);
  89. glLoadIdentity();
  90. glFrustum(-1, 1, -1, 1, 10, 30);
  91. glMatrixMode(GL_MODELVIEW);
  92. glLoadIdentity();
  93. glTranslatef(0, 0, -18);
  94. }
  95. int main(int argc, char *argv[])
  96. {
  97. BApplication *app = new BApplication("application/demo");
  98. // make top-level window
  99. MyWindow *win = new MyWindow(BRect(100, 100, 500, 500));
  100. win->Show();
  101. app->Run();
  102. delete app;
  103. return 0;
  104. }