Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

demo.cpp 2.3KB

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