summaryrefslogtreecommitdiffstats
path: root/menu_demo/main.c
blob: 0592c57307ba615cb83411ab0f6da08aa4e0e91e (plain)
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
#ifdef G_OS_WIN32
#define WIN32_LEAN_AND_MEAN 1
#include <windows.h>
#endif

#include <stdlib.h>

#include <GL/gl.h>
#include <GL/glut.h>

#include "menu.h"

#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480


void init_gl(void)
{
  double l_dHalfWidth  = SCREEN_WIDTH / 2;
  double l_dHalfHeight = SCREEN_HEIGHT / 2;

  glDepthFunc(GL_LESS);
  glEnable(GL_DEPTH_TEST);
  glEnable(GL_TEXTURE_2D);

  glMatrixMode(GL_PROJECTION);

  glOrtho(-l_dHalfWidth,
           l_dHalfWidth,
          -l_dHalfHeight,
           l_dHalfHeight,
          -1,
           1
         );

  glMatrixMode(GL_MODELVIEW);
}

void render_scene(void)
{
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glClearColor(1, 1, 1, 0);

  MenuRender();

  glutSwapBuffers();
}

void process_normal_keys(unsigned char key, int x, int y)
{
  // escape
  if (key == 27) exit(0);
}

void process_special_keys(int key, int x, int y)
{
  switch (key)
  {
	  // do sumting
  }
}

int main(int argc, char **argv)
{
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
  glutInitWindowSize(SCREEN_WIDTH, SCREEN_HEIGHT);
  glutCreateWindow("Menu demo");
  glutDisplayFunc(render_scene);
  glutIdleFunc(render_scene);
  glutKeyboardFunc(process_normal_keys);
  glutSpecialFunc(process_special_keys);

  init_gl();
  MenuInit();

  glutMainLoop();

  return 0;
}