Subversion Repositories gelsvn

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
561 awk 1
 
2
#include <GLGraphics/Console.h>
3
#include <GLGraphics/gel_glut.h>
4
 
5
#include <CGLA/Vec3f.h>
6
 
7
GLGraphics::Console console;
8
 
9
int width, height;
10
bool console_visible = true;
11
 
12
static void display()
13
{
14
    glClearColor(0.4f, 0.4f, 0.4f, 1.f);
15
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
16
 
17
    if (console_visible)
18
    {
19
        //draw console in upper half of screen
20
        glPushAttrib(GL_VIEWPORT_BIT);
21
        glViewport(0, height-height/2,
22
                   width, height/2);
23
        console.display();
24
        glPopAttrib();
25
    }
26
 
27
    assert(glGetError() == GL_NO_ERROR);
28
    glutSwapBuffers();
29
}
30
 
31
static void reshape(int w, int h)
32
{
33
    width = w;
34
    height = h;
35
 
36
    glViewport( 0, 0, width, height);
37
}
38
 
39
static void keyboard(unsigned char key, int x, int y)
40
{
41
    //toggle console with ESC
42
    if (key == 27)
43
    {
44
        console_visible = !console_visible;
45
        glutPostRedisplay();
46
        return;
47
    }
48
 
49
    if (console_visible)
50
    {
51
        console.keyboard(key);
52
        glutPostRedisplay();
53
        return;
54
    }
55
 
56
    //switch (key)
57
    //{
58
    //}
59
 
60
    glutPostRedisplay();
61
}
62
 
63
static void special(int key, int x, int y)
64
{
65
    if (console_visible)
66
    {
67
        console.special(key);
68
        glutPostRedisplay();
69
        return;
70
    }
71
 
72
    //switch (key)
73
    //{
74
    //}
75
 
76
    glutPostRedisplay();
77
}
78
 
79
int main( int argc, char *argv[] )
80
{
81
  glutInit(&argc, argv);
82
  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
83
  glutInitWindowSize(768, 768);
84
  glutInitWindowPosition(256, 256);
85
  glutCreateWindow(argv[0]);
86
  glutReshapeFunc(reshape);
87
  glutKeyboardFunc(keyboard);
88
  glutSpecialFunc(special);
89
  glutDisplayFunc(display);
90
 
91
  console.printf("GLGraphics console test.");
92
  console.newline();
93
 
94
  //some examples of use:
95
 
96
  console.reg_cmd("quit",
97
      std::bind(&std::exit, EXIT_SUCCESS), "Exit application.");
98
 
99
  console.reg_cmd<int>("quit",
100
      std::bind(&std::exit, std::placeholders::_1),
101
      "Exit application with specified exit code.");
102
 
103
  console.reg_cmd("fullscreen", std::bind(&glutFullScreen), "Switch to fullscreen.");
104
 
105
#if 1
106
  //needs lambda
107
  console.reg_cmd("window_pos", [&]{
108
      console.printf("window_pos = %i %i", glutGet(GLUT_WINDOW_X),
109
          glutGet(GLUT_WINDOW_Y));
110
  }, "Show window position.");
111
  console.reg_cmd("window_size", [&]{
112
      console.printf("window_size = %i %i", glutGet(GLUT_WINDOW_WIDTH),
113
          glutGet(GLUT_WINDOW_HEIGHT));
114
  }, "Show window position.");
115
#endif
116
 
117
  console.reg_cmd<int,int>("window_pos", std::bind(&glutPositionWindow,
118
      std::placeholders::_1, std::placeholders::_2),
119
      "Set the window position.");
120
 
121
  console.executef("window_pos %i %i", 384, 256);
122
 
123
  console.reg_cmd<int,int>("window_size", std::bind(&glutReshapeWindow,
124
      std::placeholders::_1, std::placeholders::_2),
125
      "Set the window size.");
126
 
127
  using namespace GLGraphics;
128
 
129
  Console::variable<int> test_int(42);
130
  test_int.reg(console, "test_int", "Some clever help string..");
131
  console.execute("test_int");
132
  console.execute("test_int 167");
133
 
134
  Console::variable<float> test_float(3.14f);
135
  test_float.reg(console, "test_float", "Well..");
136
  console.execute("test_float");
137
  console.execute("test_float 2.71");
138
 
139
  Console::variable<std::string> test_string("Hello, world!");
140
  test_string.reg(console, "test_string", "Well..");
141
  console.execute("test_string");
142
  console.execute("test_string \"some other string with spaces in\"");
143
 
144
  Console::variable<CGLA::Vec3f> test_Vec3f(CGLA::Vec3f(1,2,3));
145
  test_Vec3f.reg(console, "test_Vec3f", "Well..");
146
  console.execute("test_Vec3f");
147
  console.execute("test_Vec3f [ 12 1234 15]");
148
 
149
  CGLA::Vec3f in(0,1,2);
150
  std::stringstream ss;
151
  ss << in;
152
  CGLA::Vec3f out;
153
  ss >> out;
154
  assert(in == out);
155
 
156
  glutMainLoop();
157
  return 0;
158
}
159
 
160
 
161
 
162
 
163