Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <math.h>
  5.  
  6. #define EGL_EGLEXT_PROTOTYPES
  7. #include "EGL/egl.h"
  8. #include "EGL/eglext.h"
  9. #include "GL/gl.h"
  10. #include "gbm.h"
  11. #include <kos32sys.h>
  12.  
  13. #include "eglut.h"
  14.  
  15. GLint list;
  16.  
  17. static void init(void)
  18. {
  19. //   fprintf(stderr, "GL_RENDERER   = %s\n", (char *) glGetString(GL_RENDERER));
  20. //   fprintf(stderr, "GL_VERSION    = %s\n", (char *) glGetString(GL_VERSION));
  21. //   fprintf(stderr, "GL_VENDOR     = %s\n", (char *) glGetString(GL_VENDOR));
  22. //   fflush(stderr);
  23.  
  24.    list = glGenLists(1);
  25.    glNewList(list, GL_COMPILE);
  26.  
  27.    /* XXX: this state-change will only be executed if list is called
  28.     * from outside a begin/end pair:
  29.     */
  30.    glShadeModel( GL_FLAT );
  31.    glBegin(GL_TRIANGLES);
  32.    glColor3f(0,0,0.7);
  33.    glVertex3f( -0.9,  0.9, -30.0);
  34.    glColor3f(0,0.9,0);
  35.    glVertex3f( -0.9, -0.9, -30.0);
  36.    glColor3f(0.8,0,0);
  37.    glVertex3f(  0.9,  0.0, -30.0);
  38.    glEnd();
  39.  
  40.    glEndList();
  41. }
  42.  
  43. static void
  44. idle(void)
  45. {
  46.     eglutPostRedisplay();
  47. }
  48.  
  49. static void reshape(int width, int height)
  50. {
  51.   asm volatile ("int3");
  52. /*
  53.     glViewport(0, 0, (GLint)width, (GLint)height);
  54.  
  55.     glMatrixMode(GL_PROJECTION);
  56.     glLoadIdentity();
  57.     glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 100.0);
  58.     glMatrixMode(GL_MODELVIEW);
  59.     glLoadIdentity();
  60. */
  61.     glViewport(0, 0, (GLint) width, (GLint) height);
  62.  
  63.     GLfloat h = (GLfloat) height / (GLfloat) width;
  64.  
  65.     glMatrixMode(GL_PROJECTION);
  66.     glLoadIdentity();
  67.     glFrustum(-1.0, 1.0, -h, h, 5.0, 60.0);
  68.  
  69.     glMatrixMode(GL_MODELVIEW);
  70.     glLoadIdentity();
  71. }
  72.  
  73. static void draw(void)
  74. {
  75.    asm volatile ("int3");
  76.  
  77.    glClear(GL_COLOR_BUFFER_BIT);
  78.  
  79.    glShadeModel( GL_SMOOTH );
  80.  
  81.    glBegin(GL_TRIANGLES);
  82.  
  83.    /* Note: call the list from inside a begin/end pair.  The end is
  84.     * provided by the display list...
  85.     */
  86.    glCallList(list);
  87.  
  88.  //  glFlush();
  89.  
  90. }
  91.  
  92. int
  93. main(int argc, char *argv[])
  94. {
  95.    eglutInitWindowSize(384, 384);
  96.    eglutInitAPIMask(EGLUT_OPENGL_BIT);
  97.    eglutInit(argc, argv);
  98.  
  99.    eglutCreateWindow("gl-render");
  100.  
  101.    eglutIdleFunc(idle);
  102.    eglutReshapeFunc(reshape);
  103.    eglutDisplayFunc(draw);
  104.  
  105.    glClearColor( 0, 0, 0, 1.0);
  106.  
  107.    init();
  108.    glDrawBuffer(GL_BACK);
  109.  
  110.    eglutMainLoop();
  111.  
  112.    return 0;
  113. }
  114.