summaryrefslogtreecommitdiff
path: root/src/graphics_opengl.c
blob: 9e200de2a528b4144d1182209a8f50510e0b7938 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96

#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <GL/glut.h>

GLenum doubleBuffer;
GLubyte ubImage[65536];

void draw_cs_line(cs_t p1,cs_t p2) {
 
}

void draw_cs_text() {

}

void draw_c3_shape() {
 //oh lawdy... this should be draw_cs_shape...
}

static void
graphics_init(void)
{
  GLenum type;
  int j;
  GLubyte *img;
  GLsizei imgWidth = 128;

  type = GLUT_RGB;
  type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
  glutInitDisplayMode(type);
  glutCreateWindow("ABGR extension");
  if (!glutExtensionSupported("GL_EXT_abgr")) {
    printf("Couldn't find abgr extension.\n");
    exit(0);
  }

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(60.0, 1.0, 0.1, 1000.0);
  glMatrixMode(GL_MODELVIEW);
  glDisable(GL_DITHER);

  glutKeyboardFunc(keypress_handler);
  glutDisplayFunc(draw_screen);

}

/* ARGSUSED1 */
static void
keypress_handler(unsigned char key, int x, int y)
{
  switch (key) {
  case 27:
    exit(0);
  }
}

static void draw_screen(void)
{

  glClearColor(0.0, 0.0, 0.0, 1.0);
  glClear(GL_COLOR_BUFFER_BIT);


  glRasterPos3f(0.2, -0.8, -1.5);
  glDrawPixels(128, 128, GL_RGBA, GL_UNSIGNED_BYTE, ubImage);

  if (doubleBuffer) {
    glutSwapBuffers();
  } else {
    glFlush();
  }
}

static void
Args(int argc, char **argv)
{
  GLint i;

  doubleBuffer = GL_TRUE;

  for (i = 1; i < argc; i++) {
    if (strcmp(argv[i], "-sb") == 0) {
      doubleBuffer = GL_FALSE;
    } else if (strcmp(argv[i], "-db") == 0) {
      doubleBuffer = GL_TRUE;
    }
  }
}

void graphics_event_handler() {
  glutMainLoopUpdate();
  return 0;             /* ANSI C requires main to return int. */
}