Rev 1789 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1789 | yogev_ezra | 1 | /* |
2 | iadn |
||
3 | http://www.iadn.narod.ru |
||
4 | iadn@bk.ru |
||
5 | */ |
||
6 | #include |
||
7 | #include |
||
8 | #include |
||
9 | |||
10 | #include "SysCall.h" |
||
11 | #include "ProcessTab.h" |
||
12 | #include "bmp.h" |
||
13 | |||
14 | |||
15 | int Fps (long x, long y); |
||
16 | extern "C"{ |
||
5098 | clevermous | 17 | int main(void); |
1789 | yogev_ezra | 18 | } |
19 | |||
20 | struct { |
||
21 | int x,y; |
||
22 | int dx,dy; |
||
23 | } win; |
||
24 | |||
25 | #define KEY_ESC 1 |
||
26 | #define KEY_F 33 |
||
27 | |||
28 | char *title1 = "TinyGL in KolibriOS"; |
||
29 | char *title2 = "F full screen"; |
||
30 | char *title3 = "ESC - exit"; |
||
31 | char *fps = "FPS:"; |
||
32 | |||
33 | unsigned char FullScreen = 0; |
||
34 | unsigned char skin = 3; |
||
35 | |||
36 | static GLuint* TexObj; |
||
37 | |||
38 | float angle = 0.0; |
||
39 | process_table_entry_* pri; |
||
40 | KOSGLContext cgl; |
||
41 | |||
42 | struct V3{ |
||
43 | float v1; |
||
44 | float v2; |
||
45 | float v3; |
||
46 | } ptrv[8] = {{-1.0,1.0,1.0}, |
||
47 | {-1.0,-1.0,1.0}, |
||
48 | {1.0,-1.0,1.0}, |
||
49 | {1.0,1.0,1.0}, |
||
50 | {-1.0,1.0,-1.0}, |
||
51 | {-1.0,-1.0,-1.0}, |
||
52 | {1.0,-1.0,-1.0}, |
||
53 | {1.0,1.0,-1.0}}; |
||
54 | |||
55 | struct T2{ |
||
56 | float t1; |
||
57 | float t2; |
||
58 | } ptrt[4] = { |
||
59 | {0.0, 0.0}, |
||
60 | {1.0, 0.0}, |
||
61 | {1.0, 1.0}, |
||
62 | {0.0, 1.0} |
||
63 | }; |
||
64 | |||
65 | void DrawQUADS(V3* ptr, int iv1, int iv2, int iv3, int iv4, T2* ptrt, int it1, int it2, int it3, int it4) |
||
66 | { |
||
67 | glBegin(GL_QUADS); |
||
68 | glTexCoord2fv((float*)&ptrt[it1]); |
||
69 | glVertex3fv((float*)&ptr[iv1]); |
||
70 | glTexCoord2fv((float*)&ptrt[it2]); |
||
71 | glVertex3fv((float*)&ptr[iv2]); |
||
72 | glTexCoord2fv((float*)&ptrt[it3]); |
||
73 | glVertex3fv((float*)&ptr[iv3]); |
||
74 | glTexCoord2fv((float*)&ptrt[it4]); |
||
75 | glVertex3fv((float*)&ptr[iv4]); |
||
76 | glEnd(); |
||
77 | } |
||
78 | void DrawGL() |
||
79 | { |
||
80 | glLoadIdentity(); // устанавливаем еденичную матрицу |
||
81 | glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
||
82 | |||
83 | glTranslatef(0.0, 0.0, -6.0); |
||
84 | glRotatef(angle, 1.0, 0.0, 0.0); |
||
85 | glRotatef(2.0*angle, 0.0, 1.0, 0.0); |
||
86 | glRotatef(3.0*angle, 0.0, 0.0, 1.0); |
||
87 | |||
88 | DrawQUADS((V3*)&ptrv,0,1,2,3,(T2*)&ptrt,3,0,1,2); |
||
89 | DrawQUADS((V3*)&ptrv,0,3,7,4,(T2*)&ptrt,1,2,3,0); |
||
90 | DrawQUADS((V3*)&ptrv,4,7,6,5,(T2*)&ptrt,2,3,0,1); |
||
91 | DrawQUADS((V3*)&ptrv,5,6,2,1,(T2*)&ptrt,3,0,1,2); |
||
92 | DrawQUADS((V3*)&ptrv,7,3,2,6,(T2*)&ptrt,3,0,1,2); |
||
93 | DrawQUADS((V3*)&ptrv,5,1,0,4,(T2*)&ptrt,3,0,1,2); |
||
94 | |||
95 | kosglSwapBuffers(); |
||
96 | } |
||
97 | |||
98 | void reshape() |
||
99 | { |
||
100 | __menuet__get_process_table((process_table_entry*)pri,-1); |
||
101 | glViewport(0, 0, pri->winx_size, pri->winy_size-20); |
||
102 | glMatrixMode(GL_PROJECTION); |
||
103 | glLoadIdentity(); |
||
104 | gluPerspective(50.0, (GLfloat)pri->winx_size/pri->winy_size, 1.0, 300.0); |
||
105 | glMatrixMode(GL_MODELVIEW); |
||
106 | glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); |
||
107 | } |
||
108 | |||
109 | void disabletgl() |
||
110 | { |
||
111 | kosglDestroyContext(cgl); |
||
112 | delete pri; |
||
113 | } |
||
114 | |||
115 | void Title() |
||
116 | { |
||
117 | __menuet__write_text(300,8,0x10ffffff,fps,strlen(fps)); |
||
118 | __menuet__write_text(8,8,0x10ffffff,title1,strlen(title1)); |
||
119 | __menuet__write_text(180,8,0x00ffffff,title2,strlen(title2)); |
||
120 | __menuet__write_text(600,8,0x00ffffff,title3,strlen(title3)); |
||
121 | } |
||
122 | |||
123 | void draw_window(void) |
||
124 | { |
||
125 | // start redraw |
||
126 | __menuet__window_redraw(1); |
||
127 | // define&draw window |
||
128 | __menuet__define_window(win.x,win.y,win.dx,win.dy,TYPEWIN(0,0,0,1,skin,0,0,0),0,0); |
||
129 | // end redraw |
||
130 | __menuet__window_redraw(2); |
||
131 | // display string |
||
132 | Title(); |
||
133 | } |
||
134 | |||
5098 | clevermous | 135 | int main(void) |
1789 | yogev_ezra | 136 | { |
137 | |||
138 | win.x = 100; |
||
139 | win.y = 100; |
||
140 | win.dx = 400; |
||
141 | win.dy = 400; |
||
142 | |||
143 | draw_window(); |
||
144 | |||
145 | cgl = kosglCreateContext( 0, 0); |
||
146 | kosglMakeCurrent( 0, 20, win.dx, win.dy-20, cgl); |
||
147 | |||
148 | glMatrixMode(GL_MODELVIEW); |
||
149 | glLoadIdentity(); |
||
150 | |||
151 | glClearDepth(1.0); |
||
152 | glEnable( GL_CULL_FACE ); |
||
153 | glEnable(GL_DEPTH_TEST); |
||
154 | |||
155 | |||
156 | int width, height; |
||
157 | unsigned char* texture; |
||
158 | LoadFileBMP( "./logio.bmp", &texture, &width, &height, false ); |
||
159 | |||
160 | /* Setup texturing */ |
||
161 | glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); |
||
162 | glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); |
||
163 | |||
164 | /* generate texture object IDs */ |
||
165 | glGenTextures(1, TexObj); |
||
166 | glBindTexture(GL_TEXTURE_2D, *TexObj); |
||
167 | glTexImage2D(GL_TEXTURE_2D, 0, 3, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, texture); |
||
168 | |||
169 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
||
170 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
||
171 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
||
172 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
||
173 | glBindTexture(GL_TEXTURE_2D, *TexObj); |
||
174 | glEnable(GL_TEXTURE_2D); |
||
175 | |||
176 | pri=new process_table_entry_; |
||
177 | SysCall(66,1,1); |
||
178 | |||
179 | reshape(); |
||
180 | |||
181 | do{ |
||
182 | |||
183 | angle += 0.001 + 0.1*Fps (330,8); |
||
184 | |||
185 | DrawGL(); |
||
186 | |||
187 | switch(__menuet__check_for_event()) |
||
188 | { |
||
189 | case 1: draw_window(); |
||
190 | reshape(); |
||
191 | break; |
||
192 | |||
193 | case 2: |
||
194 | switch(__menuet__getkey()){ |
||
195 | |||
196 | case KEY_F: |
||
197 | if(!FullScreen){ |
||
198 | skin=0; |
||
199 | SysCall(67,0,0,SysCall(14)>>16,SysCall(14)&0xffff); |
||
200 | draw_window(); |
||
201 | reshape(); |
||
202 | FullScreen = 1; |
||
203 | } |
||
204 | else{ |
||
205 | skin=3; |
||
206 | draw_window(); |
||
207 | SysCall(67,win.x,win.y,win.dx,win.dy); |
||
208 | reshape(); |
||
209 | FullScreen = 0; |
||
210 | }; |
||
211 | break; |
||
212 | |||
213 | case KEY_ESC: disabletgl(); |
||
5098 | clevermous | 214 | return 0;} |
1789 | yogev_ezra | 215 | break; |
216 | |||
217 | case 3: disabletgl(); |
||
5098 | clevermous | 218 | return 0; |
1789 | yogev_ezra | 219 | } |
220 | }while(1); |
||
221 | } |
||
222 |