rev |
line source |
nuclear@4
|
1 /*
|
nuclear@4
|
2 Cubemapper - a program for converting panoramic images into cubemaps
|
nuclear@4
|
3 Copyright (C) 2017 John Tsiombikas <nuclear@member.fsf.org>
|
nuclear@4
|
4
|
nuclear@4
|
5 This program is free software: you can redistribute it and/or modify
|
nuclear@4
|
6 it under the terms of the GNU General Public License as published by
|
nuclear@4
|
7 the Free Software Foundation, either version 3 of the License, or
|
nuclear@4
|
8 (at your option) any later version.
|
nuclear@4
|
9
|
nuclear@4
|
10 This program is distributed in the hope that it will be useful,
|
nuclear@4
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
nuclear@4
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
nuclear@4
|
13 GNU General Public License for more details.
|
nuclear@4
|
14
|
nuclear@4
|
15 You should have received a copy of the GNU General Public License
|
nuclear@4
|
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
|
nuclear@4
|
17 */
|
nuclear@0
|
18 #include <stdlib.h>
|
nuclear@0
|
19 #ifdef __APPLE__
|
nuclear@0
|
20 #include <GLUT/glut.h>
|
nuclear@0
|
21 #else
|
nuclear@0
|
22 #include <GL/glut.h>
|
nuclear@0
|
23 #endif
|
nuclear@0
|
24 #include "app.h"
|
nuclear@0
|
25
|
nuclear@0
|
26 static void display();
|
nuclear@0
|
27 static void reshape(int x, int y);
|
nuclear@0
|
28 static void keydown(unsigned char key, int x, int y);
|
nuclear@0
|
29 static void mouse(int bn, int st, int x, int y);
|
nuclear@0
|
30 static void motion(int x, int y);
|
nuclear@0
|
31
|
nuclear@2
|
32 static int win_width, win_height;
|
nuclear@2
|
33
|
nuclear@0
|
34 int main(int argc, char **argv)
|
nuclear@0
|
35 {
|
nuclear@1
|
36 glutInitWindowSize(1024, 768);
|
nuclear@0
|
37 glutInit(&argc, argv);
|
nuclear@2
|
38 glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_MULTISAMPLE);
|
nuclear@0
|
39 glutCreateWindow("cubemapper");
|
nuclear@0
|
40
|
nuclear@0
|
41 glutDisplayFunc(display);
|
nuclear@0
|
42 glutReshapeFunc(reshape);
|
nuclear@0
|
43 glutKeyboardFunc(keydown);
|
nuclear@0
|
44 glutMouseFunc(mouse);
|
nuclear@0
|
45 glutMotionFunc(motion);
|
nuclear@0
|
46
|
nuclear@0
|
47 if(!app_init(argc, argv)) {
|
nuclear@0
|
48 return 1;
|
nuclear@0
|
49 }
|
nuclear@0
|
50
|
nuclear@0
|
51 glutMainLoop();
|
nuclear@0
|
52 return 0;
|
nuclear@0
|
53 }
|
nuclear@0
|
54
|
nuclear@0
|
55 void app_quit()
|
nuclear@0
|
56 {
|
nuclear@0
|
57 app_cleanup();
|
nuclear@0
|
58 exit(0);
|
nuclear@0
|
59 }
|
nuclear@0
|
60
|
nuclear@0
|
61 void app_redisplay()
|
nuclear@0
|
62 {
|
nuclear@0
|
63 glutPostRedisplay();
|
nuclear@0
|
64 }
|
nuclear@0
|
65
|
nuclear@0
|
66 void app_swap_buffers()
|
nuclear@0
|
67 {
|
nuclear@0
|
68 glutSwapBuffers();
|
nuclear@0
|
69 }
|
nuclear@0
|
70
|
nuclear@1
|
71 void app_resize(int x, int y)
|
nuclear@1
|
72 {
|
nuclear@1
|
73 glutReshapeWindow(x, y);
|
nuclear@1
|
74 }
|
nuclear@1
|
75
|
nuclear@2
|
76 void app_print_text(int x, int y, const char *str)
|
nuclear@2
|
77 {
|
nuclear@2
|
78 glMatrixMode(GL_PROJECTION);
|
nuclear@2
|
79 glPushMatrix();
|
nuclear@2
|
80 glLoadIdentity();
|
nuclear@2
|
81 glOrtho(0, win_width, 0, win_height, -1, 1);
|
nuclear@2
|
82
|
nuclear@2
|
83 glMatrixMode(GL_MODELVIEW);
|
nuclear@2
|
84 glPushMatrix();
|
nuclear@2
|
85 glLoadIdentity();
|
nuclear@2
|
86
|
nuclear@2
|
87 glRasterPos2i(x, y);
|
nuclear@2
|
88
|
nuclear@2
|
89 while(*str) {
|
nuclear@2
|
90 glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, *str++);
|
nuclear@2
|
91 }
|
nuclear@2
|
92
|
nuclear@2
|
93 glMatrixMode(GL_PROJECTION);
|
nuclear@2
|
94 glPopMatrix();
|
nuclear@2
|
95 glMatrixMode(GL_MODELVIEW);
|
nuclear@2
|
96 glPopMatrix();
|
nuclear@2
|
97 }
|
nuclear@2
|
98
|
nuclear@0
|
99 static void display()
|
nuclear@0
|
100 {
|
nuclear@0
|
101 app_draw();
|
nuclear@0
|
102 }
|
nuclear@0
|
103
|
nuclear@0
|
104 static void reshape(int x, int y)
|
nuclear@0
|
105 {
|
nuclear@2
|
106 win_width = x;
|
nuclear@2
|
107 win_height = y;
|
nuclear@0
|
108 app_reshape(x, y);
|
nuclear@0
|
109 }
|
nuclear@0
|
110
|
nuclear@0
|
111 static void keydown(unsigned char key, int x, int y)
|
nuclear@0
|
112 {
|
nuclear@0
|
113 app_keyboard(key, true);
|
nuclear@0
|
114 }
|
nuclear@0
|
115
|
nuclear@0
|
116 static void mouse(int bn, int st, int x, int y)
|
nuclear@0
|
117 {
|
nuclear@0
|
118 app_mouse_button(bn - GLUT_LEFT_BUTTON, st == GLUT_DOWN, x, y);
|
nuclear@0
|
119 }
|
nuclear@0
|
120
|
nuclear@0
|
121 static void motion(int x, int y)
|
nuclear@0
|
122 {
|
nuclear@0
|
123 app_mouse_motion(x, y);
|
nuclear@0
|
124 }
|