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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. // $Id: demo.cpp,v 1.1 1999/08/19 00:55:40 jtg Exp $
  2. // Simple BeOS GLView demo
  3. // Written by Brian Paul
  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 MyWindow : public BWindow
  10. {
  11. public:
  12. MyWindow(BRect frame);
  13. virtual bool QuitRequested();
  14. };
  15. MyWindow::MyWindow(BRect frame)
  16. : BWindow(frame, "demo", B_TITLED_WINDOW, B_NOT_ZOOMABLE)
  17. {
  18. // no-op
  19. }
  20. bool MyWindow::QuitRequested()
  21. {
  22. be_app->PostMessage(B_QUIT_REQUESTED);
  23. return true;
  24. }
  25. class MyGL : public BGLView
  26. {
  27. public:
  28. MyGL(BRect rect, char *name, ulong options);
  29. // virtual void AttachedToWindow();
  30. virtual void Draw(BRect updateRect);
  31. virtual void Pulse();
  32. virtual void FrameResized(float w, float h);
  33. private:
  34. float mAngle;
  35. };
  36. MyGL::MyGL(BRect rect, char *name, ulong options)
  37. : BGLView(rect, name, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP_BOTTOM, 0, options)
  38. {
  39. mAngle = 0.0;
  40. }
  41. #if 0
  42. void MyGL::AttachedToWindow()
  43. {
  44. BGLView::AttachedToWindow();
  45. LockGL();
  46. glClearColor(.7, .7, 0, 0);
  47. UnlockGL();
  48. }
  49. #endif
  50. void MyGL::FrameResized(float w, float h)
  51. {
  52. BGLView::FrameResized(w, h);
  53. printf("FrameResized\n");
  54. LockGL();
  55. BGLView::FrameResized(w,h);
  56. glViewport(0, 0, (int) (w + 1), (int) (h + 1));
  57. glMatrixMode(GL_PROJECTION);
  58. glLoadIdentity();
  59. glFrustum(-1, 1, -1, 1, 10, 30);
  60. glMatrixMode(GL_MODELVIEW);
  61. glLoadIdentity();
  62. glTranslatef(0, 0, -18);
  63. UnlockGL();
  64. }
  65. void MyGL::Draw(BRect r)
  66. {
  67. printf("MyGL::Draw\n");
  68. BGLView::Draw(r);
  69. LockGL();
  70. glClear(GL_COLOR_BUFFER_BIT);
  71. glPushMatrix();
  72. glRotatef(mAngle, 0, 0, 1);
  73. glColor3f(0, 0, 1);
  74. glBegin(GL_POLYGON);
  75. glVertex2f(-1, -1);
  76. glVertex2f( 1, -1);
  77. glVertex2f( 1, 1);
  78. glVertex2f(-1, 1);
  79. glEnd();
  80. SwapBuffers();
  81. UnlockGL();
  82. }
  83. void MyGL::Pulse()
  84. {
  85. printf("pulse\n");
  86. BGLView::Pulse();
  87. mAngle += 1.0;
  88. LockGL();
  89. glClear(GL_COLOR_BUFFER_BIT);
  90. glPushMatrix();
  91. glRotatef(mAngle, 0, 0, 1);
  92. glColor3f(0, 0, 1);
  93. glBegin(GL_POLYGON);
  94. glVertex2f(-1, -1);
  95. glVertex2f( 1, -1);
  96. glVertex2f( 1, 1);
  97. glVertex2f(-1, 1);
  98. glEnd();
  99. SwapBuffers();
  100. UnlockGL();
  101. }
  102. int main(int argc, char *argv[])
  103. {
  104. BApplication *app = new BApplication("application/demo");
  105. // make top-level window
  106. int x = 500, y = 500;
  107. int w = 400, h = 400;
  108. MyWindow *win = new MyWindow(BRect(x, y, x + w, y + h));
  109. // win->Lock();
  110. // win->Unlock();
  111. win->Show();
  112. // Make OpenGL view and put it in the window
  113. MyGL *gl = new MyGL(BRect(5, 5, w-10, h-10), "GL", BGL_RGB | BGL_DOUBLE);
  114. // MyGL *gl = new MyGL(BRect(5, 5, w-10, h-10), "GL", BGL_RGB );
  115. win->AddChild(gl);
  116. printf("calling app->Run\n");
  117. app->Run();
  118. delete app;
  119. return 0;
  120. }