istereo2

view src/ui.cc @ 7:a3c4fcc9f8f3

- started a goatkit UI theme - font rendering with drawtext and shaders - asset manager (only used by drawtext for now, will replace respath eventually)
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 24 Sep 2015 06:49:25 +0300
parents 3bccfc7d10fe
children 64e15874f3bd
line source
1 #include <stdio.h>
2 #include "ui.h"
3 #include "goatkit/goatkit.h"
4 #include "opengl.h"
5 #include "sdr.h"
7 static goatkit::Screen scr;
8 static int width, height;
10 extern unsigned int prog_color, prog_ui;
12 int ui_init(void)
13 {
14 float ypos = 0;
15 float vsep = 0.1;
17 goatkit::Label *label = new goatkit::Label;
18 label->set_position(0.5, ypos += vsep);
19 label->set_size(0.1, 0.1);
20 label->set_text("Stereoscopic rendering");
21 scr.add_widget(label);
23 /*
24 goatkit::Button *button = new goatkit::Button;
25 button->set_position(300, ypos += vsep);
26 button->set_size(200, 40);
27 button->set_text("a button!");
28 button->set_callback(goatkit::EV_CLICK, callback);
29 scr.add_widget(button);
31 goatkit::TextBox *text = new goatkit::TextBox;
32 text->set_position(300, ypos += vsep);
33 text->set_size(200, 30);
34 text->set_text("foo");
35 text->set_callback(goatkit::EV_CHANGE, callback);
36 scr.add_widget(text);
38 goatkit::CheckBox *cbox = new goatkit::CheckBox;
39 cbox->set_position(300, ypos += vsep);
40 cbox->set_size(200, 20);
41 cbox->set_text("a checkbox!");
42 cbox->set_callback(goatkit::EV_CHANGE, callback);
43 scr.add_widget(cbox);
45 goatkit::Slider *slider = new goatkit::Slider;
46 slider->set_position(300, ypos += vsep);
47 slider->set_size(200, 40);
48 slider->set_callback(goatkit::EV_CHANGE, callback);
49 slider->set_continuous_change(false);
50 slider->set_range(0, 100.0);
51 scr.add_widget(slider);
53 goatkit::Slider *intslider = new goatkit::Slider;
54 intslider->set_position(300, ypos += vsep);
55 intslider->set_size(200, 40);
56 intslider->set_callback(goatkit::EV_CHANGE, callback);
57 intslider->set_continuous_change(false);
58 intslider->set_range(0, 100.0);
59 intslider->set_step(10);
60 scr.add_widget(intslider);
61 */
63 scr.show();
65 // load the theme
66 //goatkit::add_theme_path("themes/simple");
68 goatkit::theme = new goatkit::Theme;
69 if(!goatkit::theme->load(GOATKIT_THEME_BUILTIN)) {
70 fprintf(stderr, "no builitn theme\n");
71 return -1;
72 }
74 return 0;
75 }
77 void ui_shutdown(void)
78 {
79 }
81 void ui_reshape(int x, int y)
82 {
83 width = x;
84 height = y;
85 }
87 void ui_draw(void)
88 {
89 float aspect = (float)width / (float)height;
91 bind_program(prog_ui);
93 gl_matrix_mode(GL_PROJECTION);
94 gl_push_matrix();
95 gl_load_identity();
96 gl_scalef(2.0 / aspect, 2.0, 1);
97 gl_translatef(-1, -1, 0);
98 gl_matrix_mode(GL_MODELVIEW);
99 gl_push_matrix();
100 gl_load_identity();
102 glDisable(GL_CULL_FACE);
103 glDisable(GL_DEPTH_TEST);
104 glEnable(GL_BLEND);
105 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
107 set_uniform_float4(prog_ui, "ucolor", 0, 0, 0, 0.5);
109 gl_begin(GL_QUADS);
110 //gl_color4f(0, 0, 0, 0.5);
111 gl_vertex3f(0, 0, 0);
112 gl_vertex3f(0, 1.0, 0);
113 gl_vertex3f(1.0 * aspect, 1.0, 0);
114 gl_vertex3f(1.0 * aspect, 0, 0);
115 gl_end();
117 scr.draw();
119 glDisable(GL_BLEND);
120 glEnable(GL_CULL_FACE);
121 glEnable(GL_DEPTH_TEST);
124 gl_matrix_mode(GL_PROJECTION);
125 gl_pop_matrix();
126 gl_matrix_mode(GL_MODELVIEW);
127 gl_pop_matrix();
128 }
130 void ui_button(int bn, int press, int x, int y)
131 {
132 scr.sysev_mouse_button(bn, press != 0, (float)x / (float)width, (float)y / (float)height);
133 }
135 void ui_motion(int x, int y)
136 {
137 scr.sysev_mouse_motion((float)x / (float)width, (float)y / (float)height);