FreeWRL / FreeX3D 4.3.0
CursorDraw.c
1/****************************************************************************
2 This file is part of the FreeWRL/FreeX3D Distribution.
3
4 Copyright 2009 CRC Canada. (http://www.crc.gc.ca)
5
6 FreeWRL/FreeX3D is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 FreeWRL/FreeX3D is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with FreeWRL/FreeX3D. If not, see <http://www.gnu.org/licenses/>.
18****************************************************************************/
19
20
21#include <config.h>
22#include <system.h>
23#include <display.h>
24#include <internal.h>
25
26#include <libFreeWRL.h>
27#include <display.h>
28
29#include "../vrml_parser/Structs.h"
30#include "main/headers.h"
31#include "vrml_parser/Structs.h"
32#include "scenegraph/Viewer.h"
33#include "scenegraph/Component_Shape.h"
34#include "opengl/Frustum.h"
35#include "opengl/OpenGL_Utils.h"
36#include "opengl/Textures.h"
37#include "opengl/LoadTextures.h"
38#include "main/MainLoop.h"
39#include "scenegraph/RenderFuncs.h"
40#include "statusbar.h"
41#include "../scenegraph/LinearAlgebra.h"
42
43
44/* I made a 32x32 image in Gimp, and exported to C Struct format */
45static const struct {
46 int width;
47 int height;
48 int bytes_per_pixel; /* 3:RGB, 4:RGBA */
49 GLubyte pixel_data[32 * 32 * 4 + 1];
50} circleCursor = {
51 32, 32, 4,
52 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
53 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
54 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0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\213\377\216\216\216\377\206\206\206\377\200\200\200\377\200\200\200\377"
83 "\206\206\206\377\216\216\216\377\213\213\213\377ddd\363000\251\0\0\0""0\0"
84 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
85 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0""0,"
86 ",,\266yyy\373\247\247\247\377ttt\366<<<\313\33\33\33\227\0\0\0\200\0\0\0"
87 "\200\33\33\33\227<<<\313ttt\366\247\247\247\377yyy\373,,,\266\0\0\0""0\0"
88 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
89 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\40""000\251yyy\373\213"
90 "\213\213\377GGG\347\33\33\33\226\0\0\0@\0\0\0\20\0\0\0\0\0\0\0\0\0\0\0\20"
91 "\0\0\0@\33\33\33\226GGG\347\213\213\213\377yyy\373000\251\0\0\0\40\0\0\0"
92 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
93 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\20\0\0\0pddd\363\247\247\247\377GGG\347"
94 "\0\0\0\177\0\0\0\40\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
95 "\40\0\0\0\177GGG\347\247\247\247\377ddd\363\0\0\0p\0\0\0\20\0\0\0\0\0\0\0"
96 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
97 "\0\0\0\0\0\0\0\0""0***\302\213\213\213\377ttt\366\33\33\33\226\0\0\0\40\0"
98 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\40\33"
99 "\33\33\226ttt\366\213\213\213\377***\302\0\0\0""0\0\0\0\0\0\0\0\0\0\0\0\0"
100 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
101 "\0\0\0PWWW\350\216\216\216\377<<<\313\0\0\0@\0\0\0\0\0\0\0\0\0\0\0\20\0\0"
102 "\0@\0\0\0o\0\0\0o\0\0\0@\0\0\0\20\0\0\0\0\0\0\0\0\0\0\0@<<<\313\216\216\216"
103 "\377WWW\350\0\0\0P\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
104 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0oqqq\372\206\206\206\377"
105 "\33\33\33\227\0\0\0\20\0\0\0\0\0\0\0\0\0\0\0@,,,\271ccc\365ccc\365,,,\271"
106 "\0\0\0@\0\0\0\0\0\0\0\0\0\0\0\20\33\33\33\227\206\206\206\377qqq\372\0\0"
107 "\0o\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
108 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\177\177\177\177\377\200\200\200\377\0\0"
109 "\0\200\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0occc\365\337\337\337\377\337\337\337"
110 "\377ccc\365\0\0\0o\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\200\200\200\200\377\177"
111 "\177\177\377\0\0\0\177\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
112 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\177\177\177\177\377"
113 "\200\200\200\377\0\0\0\200\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0occc\365\337\337"
114 "\337\377\337\337\337\377ccc\365\0\0\0o\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\200"
115 "\200\200\200\377\177\177\177\377\0\0\0\177\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
116 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
117 "oqqq\372\206\206\206\377\33\33\33\227\0\0\0\20\0\0\0\0\0\0\0\0\0\0\0@,,,"
118 "\271ccc\365ccc\365,,,\271\0\0\0@\0\0\0\0\0\0\0\0\0\0\0\20\33\33\33\227\206"
119 "\206\206\377qqq\372\0\0\0o\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
120 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0PWWW\350\216\216"
121 "\216\377<<<\313\0\0\0@\0\0\0\0\0\0\0\0\0\0\0\20\0\0\0@\0\0\0o\0\0\0o\0\0"
122 "\0@\0\0\0\20\0\0\0\0\0\0\0\0\0\0\0@<<<\313\216\216\216\377WWW\350\0\0\0P"
123 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
124 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0""0***\302\213\213\213\377ttt\366\33\33\33"
125 "\226\0\0\0\40\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
126 "\0\0\0\0\0\40\33\33\33\226ttt\366\213\213\213\377***\302\0\0\0""0\0\0\0\0"
127 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
128 "\0\0\0\0\0\0\0\0\0\0\0\20\0\0\0pddd\363\247\247\247\377GGG\347\0\0\0\177"
129 "\0\0\0\40\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\40\0\0\0"
130 "\177GGG\347\247\247\247\377ddd\363\0\0\0p\0\0\0\20\0\0\0\0\0\0\0\0\0\0\0"
131 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
132 "\0\0\0\0\0\0\0\0\40""000\251yyy\373\213\213\213\377GGG\347\33\33\33\226\0"
133 "\0\0@\0\0\0\20\0\0\0\0\0\0\0\0\0\0\0\20\0\0\0@\33\33\33\226GGG\347\213\213"
134 "\213\377yyy\373000\251\0\0\0\40\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
135 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
136 "\0\0\0\0\0\0""0,,,\266yyy\373\247\247\247\377ttt\366<<<\313\33\33\33\227"
137 "\0\0\0\200\0\0\0\200\33\33\33\227<<<\313ttt\366\247\247\247\377yyy\373,,"
138 ",\266\0\0\0""0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
139 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
140 "\0\0\0\0\0\0""0000\251ddd\363\213\213\213\377\216\216\216\377\206\206\206"
141 "\377\200\200\200\377\200\200\200\377\206\206\206\377\216\216\216\377\213"
142 "\213\213\377ddd\363000\251\0\0\0""0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
143 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
144 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0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0\0\0\0\0\0\0\0\0\0\0\0\0\0"
172 "\0\0\0",
173};
174//
175//1-2 4
176//| /|
177//0 3 5
178GLfloat cursorVert[] = {
179 -.05f, -.05f, 0.0f,
180 -.05f, .05f, 0.0f,
181 .05f, .05f, 0.0f,
182 -.05f, -.05f, 0.0f,
183 .05f, .05f, 0.0f,
184 .05f, -.05f, 0.0f};
185GLfloat cursorTex[] = {
186 0.0f, 0.0f,
187 0.0f, 1.0f,
188 1.0f, 1.0f,
189 0.0f, 0.0f,
190 1.0f, 1.0f,
191 1.0f, 0.0f};
192
193typedef struct pCursorDraw{
194 GLuint textureID;
195 int done;
196}* ppCursorDraw;
197void *CursorDraw_constructor(){
198 void *v = MALLOCV(sizeof(struct pCursorDraw));
199 memset(v,0,sizeof(struct pCursorDraw));
200 return v;
201}
202void CursorDraw_init(struct tCursorDraw *t){
203 //public
204 //private
205 t->prv = CursorDraw_constructor();
206 {
207 ppCursorDraw p = (ppCursorDraw)t->prv;
208 p->done = 0;
209 p->textureID = 0;
210 }
211}
212
213typedef struct {int x; int y;} XY;
214XY mouse2screen2(int x, int y)
215{
216 XY xy;
217 xy.x = x;
218 //xy.y = gglobal()->display.screenHeight -y;
219 xy.y = y;
220 return xy;
221}
222typedef struct {GLfloat x; GLfloat y;} FXY;
223FXY screen2normalized( GLfloat x, GLfloat y )
224{
225 FXY xy;
226 xy.x = (x / gglobal()->display.screenWidth)*2.0f -1.0f;
227 xy.y = (y / gglobal()->display.screenHeight)*2.0f -1.0f;
228 return xy;
229}
230static GLfloat cursIdentity[] = {
231 1.0f, 0.0f, 0.0f, 0.0f,
232 0.0f, 1.0f, 0.0f, 0.0f,
233 0.0f, 0.0f, 1.0f, 0.0f,
234 0.0f, 0.0f, 0.0f, 1.0f
235};
236struct cline {
237 int n; //0 means no more lines
238 GLfloat p[6]; //max 3 xy points, fill unused with 0f
239};
240static struct cline cur_fiducials [] = {
241 {3,{-.02f,.0f, 0.0f,-.02f, .02f,.0f}}, // v offset downward a bit to get on the screen at the top
242 {0,{0.0f,0.0f,0.0f,0.0f,0.0f,0.0f}},
243};
244static struct cline cur_down [] = {
245 {3,{-.02f,.02f, .0f,.0f, .02f,.02f}}, // v
246 {0,{.0f,.0f,.0f,.0f,.0f,.0f}},
247};
248static struct cline cur_up [] = {
249 {3,{-.02f,-.02f, .0f,.0f, .02f,-.02f}}, // ^
250 {0,{.0f,.0f,.0f,.0f,.0f,.0f}},
251};
252static struct cline cur_hover [] = {
253 {2,{-.02f,.0f, .02f,.0f, .0f,.0f}}, // +
254 {2,{.0f,-.02f, .0f,.02f, .0f,.0f}},
255 {0,{.0f,.0f,.0f,.0f,.0f,.0f}},
256};
257static struct cline cur_over [] = {
258 {2,{.0f,.0f, .0f,.005f, .0f,.0f}}, // !
259 {2,{.0f,.008f, .0f,.02f, .0f,.0f}},
260 {0,{.0f,.0f,.0f,.0f,.0f,.0f}},
261};
262static struct cline cur_circle [] = {
263 {3,{.1f,.00f, .0866f,.05f, .05f,.0866f}},
264 {3,{.05f,.0866f, .00f, .1f, -.05f, .0866f}},
265 {3,{-.05f, .0866f, -.0866f, .05f, -.1f, .00f}},
266 {3,{ -.1f, .00f, -.0866f, -.05f, -.05f, -.0866f}},
267 {3,{ -.05f, -.0866f, .00f, -.1f, .05f, -.0866f}},
268 {3,{ .05f, -.0866f, .0866f, -.05f, .1f, .00f }},
269 {0,{.0f,.0f,.0f,.0f,.0f,.0f}},
270};
271/* - in CursorDraw.h
272enum cursor_type {
273 CURSOR_UP = 0,
274 CURSOR_DOWN,
275 CURSOR_HOVER,
276 CURSOR_OVER,
277 CURSOR_FIDUCIALS
278};
279*/
280static struct cline *cursor_array [] = {
281 cur_up,
282 cur_down,
283 cur_hover,
284 cur_over,
285 cur_fiducials,
286 cur_circle,
287 NULL,
288};
289/* attempt to draw fiducials with lines - draws wrong place */
290s_shader_capabilities_t *getMyShader(unsigned int rq_cap0);
291
292void fiducialDrawB(int cursortype, int x, int y)
293{
294 XY xy;
295 FXY fxy;
296 int i,k;
297 GLfloat p[3][2];
298 float aspect;
299 GLint positionLoc;
300 struct cline *cur, *line;
301 s_shader_capabilities_t *scap;
302 ttglobal tg = gglobal();
303
304 //as of May 2016 the mouse/touch events come in the pick() stack relative to the whole window
305 // -not shifted relative to the current vport in the vport stack.
306 // if that changes, then the following few lines would also need to change
307 xy = mouse2screen2(x,y);
308 FW_GL_VIEWPORT(0, 0, tg->display.screenWidth, tg->display.screenHeight);
309 fxy = screen2normalized((GLfloat)xy.x,(GLfloat)xy.y);
310 aspect = (float)tg->display.screenHeight/(float)tg->display.screenWidth;
311
312
313 FW_GL_DEPTHMASK(GL_FALSE);
314 glDisable(GL_DEPTH_TEST);
315 scap = getMyShader(NO_APPEARANCE_SHADER);
316 enableGlobalShader(scap);
317 glUniformMatrix4fv(scap->ModelViewMatrix, 1, GL_FALSE, cursIdentity);
318 glUniformMatrix4fv(scap->ProjectionMatrix, 1, GL_FALSE, cursIdentity);
319
320
321 //FW_GL_VERTEX_POINTER(2, GL_FLOAT, 0, (GLfloat *)p);
322 //sendArraysToGPU(GL_LINE_STRIP, 0, 3);
323 positionLoc = scap->Vertices; //glGetAttribLocation ( shader, "fw_Vertex" );
324
325 cur = cursor_array[cursortype];
326 k = 0;
327 line = &cur[k];
328 while(line->n){
329 for(i=0;i<line->n;i++){
330 p[i][0] = line->p[i*2]*aspect + fxy.x;
331 p[i][1] = line->p[i*2 + 1] + fxy.y;
332 }
333 glVertexAttribPointer (positionLoc, 2, GL_FLOAT,
334 GL_FALSE, 0, p );
335 glDrawArrays(GL_LINE_STRIP,0,line->n);
336 k++;
337 line = &cur[k];
338 }
339
340 FW_GL_BINDBUFFER(GL_ARRAY_BUFFER, 0);
341 FW_GL_BINDBUFFER(GL_ELEMENT_ARRAY_BUFFER, 0);
342
343
344 glEnable(GL_DEPTH_TEST);
345 FW_GL_DEPTHMASK(GL_TRUE);
346 restoreGlobalShader();
347}
348void fiducialDraw(int ID, int x, int y, float angleDeg)
349{
350 //pre- may 8, 2016
351 XY xy;
352 FXY fxy;
353 int i;
354 GLfloat p[3][2];
355 GLint positionLoc;
356 s_shader_capabilities_t *scap;
357 ttglobal tg = gglobal();
358
359 xy = mouse2screen2(x,y);
360 FW_GL_VIEWPORT(0, 0, tg->display.screenWidth, tg->display.screenHeight);
361 fxy = screen2normalized((GLfloat)xy.x,(GLfloat)xy.y);
362 //I was hoping for a little v at the top
363
364 p[0][0] = -.01f;
365 p[0][1] = .01f;
366 p[1][0] = .00f;
367 p[1][1] = .00f;
368 p[2][0] = .01f;
369 p[2][1] = .01f;
370 if(angleDeg != 0.0f){
371 GLfloat cosine, sine, angleRad, xx,yy;
372 angleRad = angleDeg * (float)PI / 180.0f;
373 cosine = cosf(angleRad);
374 sine = sinf(angleRad);
375 for(i=0;i<3;i++){
376 xx = cosine*p[i][0] + sine*p[i][1];
377 yy = -sine*p[i][0] + cosine*p[i][1];
378 p[i][0]=xx;
379 p[i][1]=yy;
380 }
381 }
382 if(ID == 1){
383 for(i=0;i<3;i++)
384 p[i][1] -= .01f;
385 }
386 for(i=0;i<3;i++){
387 p[i][0] += fxy.x;
388 p[i][1] += fxy.y;
389 }
390
391 FW_GL_DEPTHMASK(GL_FALSE);
392 glDisable(GL_DEPTH_TEST);
393 scap = getMyShader(NO_APPEARANCE_SHADER);
394 enableGlobalShader(scap);
395 glUniformMatrix4fv(scap->ModelViewMatrix, 1, GL_FALSE, cursIdentity);
396 glUniformMatrix4fv(scap->ProjectionMatrix, 1, GL_FALSE, cursIdentity);
397
398
399 //FW_GL_VERTEX_POINTER(2, GL_FLOAT, 0, (GLfloat *)p);
400 //sendArraysToGPU(GL_LINE_STRIP, 0, 3);
401 positionLoc = scap->Vertices; //glGetAttribLocation ( shader, "fw_Vertex" );
402 glVertexAttribPointer (positionLoc, 2, GL_FLOAT,
403 GL_FALSE, 0, p );
404 glDrawArrays(GL_LINE_STRIP,0,3);
405
406 FW_GL_BINDBUFFER(GL_ARRAY_BUFFER, 0);
407 FW_GL_BINDBUFFER(GL_ELEMENT_ARRAY_BUFFER, 0);
408
409
410 glEnable(GL_DEPTH_TEST);
411 FW_GL_DEPTHMASK(GL_TRUE);
412 restoreGlobalShader();
413}
414/* the slave cursor method emulates a multitouch, but doesn't suppress
415 the regular mouse cursor, so don't draw ID=0
416 currently no use of angle
417 as of March 14, 2012 I'm using this only in stereovision mode, to draw
418 viewport alignment fiducials
419 */
420void statusbarHud_DrawCursor(GLint textureID,int x,int y);
421
422unsigned int getCircleCursorTextureID(){
423 //not bad texture for use in testing elsewhere
424 ppCursorDraw p;
425 ttglobal tg = gglobal();
426 p = (ppCursorDraw)tg->CursorDraw.prv;
427 if(!p->done)
428 {
429 glGenTextures(1, &p->textureID);
430 glBindTexture(GL_TEXTURE_2D, p->textureID);
431 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
432 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
433 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, circleCursor.width, circleCursor.height, 0, GL_RGBA , GL_UNSIGNED_BYTE, circleCursor.pixel_data);
434 p->done = 1;
435 }
436 return p->textureID;
437}
438void cursorDraw(int ID, int x, int y, float angle)
439{
440 XY xy;
441 FXY fxy;
442 int i,j;
443 //GLint shader;
444 GLint positionLoc, texCoordLoc, textureLoc;
445 //GLint textureCount;
446 GLint textureMatrix0;
447 ppCursorDraw p;
448 GLfloat cursorVert2[18];
449 //GLushort ind[] = {0,1,2,3,4,5};
450 //GLint pos, tex;
451 s_shader_capabilities_t *scap;
452 ttglobal tg = gglobal();
453 p = (ppCursorDraw)tg->CursorDraw.prv;
454
455 //if( ID == 0 )return;
456
457 if(!p->done)
458 {
459 glGenTextures(1, &p->textureID);
460 glBindTexture(GL_TEXTURE_2D, p->textureID);
461 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
462 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
463 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, circleCursor.width, circleCursor.height, 0, GL_RGBA , GL_UNSIGNED_BYTE, circleCursor.pixel_data);
464 p->done = 1;
465 }
466#ifdef STATUSBAR_HUD
467 //Nov 2015: I find this works with emulate_multitouch and multi_window
468 statusbarHud_DrawCursor(p->textureID,x,y);
469 return;
470#endif
471#ifndef NEWWAY_COPIED_FROM_STATUSBARHUD_CURSORDRAW
472 //Nov 2015: I find this does NOT work 100% with emulate_multitouch and multi_window - it sometimes makes regular scene geometry invisible
473 FW_GL_DEPTHMASK(GL_FALSE);
474 glDisable(GL_DEPTH_TEST);
475 //if(p->programObject == 0) initProgramObject();
476 //glUseProgram ( p->programObject );
477 scap = getMyShader(ONE_TEX_APPEARANCE_SHADER);
478 enableGlobalShader(scap);
479 //shader = getAppearanceProperties()->currentShaderProperties->myShaderProgram;
480
481 xy = mouse2screen2(x,y);
482 FW_GL_VIEWPORT(0, 0, tg->display.screenWidth, tg->display.screenHeight);
483 fxy = screen2normalized((GLfloat)xy.x,(GLfloat)xy.y);
484 //fxy.y -= 1.0;
485 //fxy.x -= 1.0;
486 for(i=0;i<6;i++){
487 for(j=0;j<3;j++)
488 cursorVert2[i*3 + j] = cursorVert[i*3 +j];
489 cursorVert2[i*3 +0] += fxy.x;
490 cursorVert2[i*3 +1] += fxy.y;
491 }
492 positionLoc = scap->Vertices; //glGetAttribLocation ( shader, "fw_Vertex" );
493 glVertexAttribPointer (positionLoc, 3, GL_FLOAT,
494 GL_FALSE, 0, cursorVert2 );
495 // Load the texture coordinate
496 //texCoordLoc = glGetAttribLocation ( shader, "fw_MultiTexCoord0"); //"fw_TexCoords" );
497 texCoordLoc = scap->TexCoords[0];
498 glVertexAttribPointer ( texCoordLoc, 2, GL_FLOAT,
499 GL_FALSE, 0, cursorTex ); //fails - p->texCoordLoc is 429xxxxx - garbage
500 //glUniform4f(p->color4fLoc,0.7f,0.7f,0.9f,1.0f);
501 glEnableVertexAttribArray (positionLoc );
502 glEnableVertexAttribArray ( texCoordLoc);
503
505 glActiveTexture ( GL_TEXTURE0 );
506 glBindTexture ( GL_TEXTURE_2D, p->textureID );
507
508 // Set the base map sampler to texture unit to 0
509 //textureLoc = glGetAttribLocation ( shader, "fw_Texture_unit0"); //"fw_Texture0" );
510 textureLoc = scap->TextureUnit[0];
511 //textureCount = scap->textureCount;
512 //glUniform1i(textureCount,(GLint)1);
513 textureMatrix0 = scap->TextureMatrix[0];
514 glUniformMatrix4fv(textureMatrix0, 1, GL_FALSE, cursIdentity);
515
516 glUniform1i ( textureLoc, 0 );
517 //glDrawElements ( GL_TRIANGLES, 3*2, GL_UNSIGNED_SHORT, ind ); //just render the active ones
518
519 // this more direct hacking also works
520 //loc = glGetAttribLocation ( shader, "fw_ModelViewMatrix" );
521 glUniformMatrix4fv(scap->ModelViewMatrix, 1, GL_FALSE, cursIdentity);
522 //loc = glGetAttribLocation ( shader, "fw_ProjectionMatrix" );
523 glUniformMatrix4fv(scap->ProjectionMatrix, 1, GL_FALSE, cursIdentity);
524
525 glDrawArrays(GL_TRIANGLES,0,6);
526
527 FW_GL_BINDBUFFER(GL_ARRAY_BUFFER, 0);
528 FW_GL_BINDBUFFER(GL_ELEMENT_ARRAY_BUFFER, 0);
529
530
531 glEnable(GL_DEPTH_TEST);
532 FW_GL_DEPTHMASK(GL_TRUE);
533 restoreGlobalShader();
534
535#endif //NEWWAY_COPIED_FROM_STATUSBARHUD_CURSORDRAW
536
537#ifdef OLDWAY
538
539 FW_GL_DEPTHMASK(GL_FALSE);
540
541 #ifndef GL_ES_VERSION_2_0
542 FW_GL_SHADEMODEL(GL_FLAT);
543 y += 10;
544 #else
545
546 // There is an issue here where Anaglyph rendering gets dinked - see
547 // fwl_RenderSceneUpdateScene() for comments.
548 //return;
549
550
551// JAS, trying this GL_PUSH_MATRIX();
552
553 {
554 xy = mouse2screen2(x,y);
555 //FW_GL_VIEWPORT(0, 0, tg->display.screenWidth, tg->display.screenHeight);
556#ifdef OLDGL
557 FW_GL_MATRIX_MODE(GL_PROJECTION); //glMatrixMode(GL_PROJECTION);
558 FW_GL_LOAD_IDENTITY(); //glLoadIdentity();
559 FW_GL_MATRIX_MODE(GL_MODELVIEW); //glMatrixMode(GL_MODELVIEW);
560 FW_GL_LOAD_IDENTITY(); //glLoadIdentity();
561#endif
562 fxy = screen2normalized((GLfloat)xy.x,(GLfloat)xy.y);
563#ifdef OLDGL
564 FW_GL_TRANSLATE_F((float)fxy.x,(float)fxy.y,0.0f);
565#endif
566 }
567 enableGlobalShader(getMyShader(ONE_TEX_APPEARANCE_SHADER));
568 shader = getAppearanceProperties()->currentShaderProperties->myShaderProgram;
569 //glEnable(GL_TEXTURE_2D);
570 glActiveTexture ( GL_TEXTURE0 );
571 glBindTexture ( GL_TEXTURE_2D, p->textureID );
572 //SET_TEXTURE_UNIT(0);
573 //glActiveTexture(GL_TEXTURE0+c);
574 /*glUniform1i(loc+c, c); */
575 loc = glGetAttribLocation ( shader, "fw_Texture0" );
576 glUniform1i(loc,0);
577 loc = glGetAttribLocation ( shader, "fw_Vertex" );
578 xy = mouse2screen2(x,y);
579 for(i=0;i<6;i++){
580 for(j=0;j<3;j++)
581 cursorVert2[i*3 + j] = cursorVert[i*3 +j];
582 cursorVert2[i*3 +0] += fxy.x;
583 cursorVert2[i*3 +1] += fxy.y;
584
585 }
586 glVertexAttribPointer ( loc, 3, GL_FLOAT, GL_FALSE, 0, cursorVert2 );
587 // Load the texture coordinate
588 loc = glGetAttribLocation ( shader, "fw_TexCoords" );
589 glEnableVertexAttribArray ( loc );
590 glVertexAttribPointer ( loc, 2, GL_FLOAT, GL_FALSE, 0, cursorTex ); //fails - p->texCoordLoc is 429xxxxx - garbage
591
592 glEnableVertexAttribArray ( loc );
593
594
595
596// JAS, trying this GL_POP_MATRIX();
597
598 #endif /* GL_ES_VERSION_2_0 */
599 glDisable(GL_DEPTH_TEST);
600
601 //xy = mouse2screen2(x,y);
602 /* please note that OpenGL ES and OpenGL-3.x does not have the following; here is
603 a hint for future work:
604 "If you are using OpenGL ES 2.0, you can use framebuffer objects to render to
605 texture, which is a much better alternative."
606 */
607 #ifndef GL_ES_VERSION_2_0
608 FW_GL_WINDOWPOS2I(xy.x,xy.y);
609 FW_GL_DRAWPIXELS(circleCursor.width,circleCursor.height,GL_BGRA,GL_UNSIGNED_BYTE,circleCursor.pixel_data);
610 #else
611 if(0){
612 // this more direct hacking also works
613 loc = glGetAttribLocation ( shader, "fw_ModelViewMatrix" );
614 glUniformMatrix4fv(loc, 1, GL_FALSE, cursIdentity);
615 loc = glGetAttribLocation ( shader, "fw_ProjectionMatrix" );
616 glUniformMatrix4fv(loc, 1, GL_FALSE, cursIdentity);
617 }
618 glDrawArrays(GL_TRIANGLES,0,6);
619 #endif /* GL_ES_VERSION_2_0 */
620
621 glEnable(GL_DEPTH_TEST);
622
623 #ifndef GL_ES_VERSION_2_0
624 FW_GL_SHADEMODEL(GL_SMOOTH);
625 #endif /* GL_ES_VERSION_2_0 */
626 FW_GL_DEPTHMASK(GL_TRUE);
627 //FW_GL_FLUSH();
628#endif //OLDWAY
629
630 return;
631}
632void vecprinti3fb(char *name, int i, float *p, char *eol){
633printf("%s[%d] %f %f %f %s",name,i,p[0],p[1],p[2],eol);
634}
635int extent6f_isSet(float *extent6);
636static float testextent [] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f};
637void reallyDrawOnce();
638void clearDraw();
639void extent6f_draw(float *extent)
640{
641 //draw bouneding box / extent as lines
642 //hacked from cursorDrawB and Component_ParticalPhysics
643 int i,j,k,n;
644 GLint positionLoc;
645 GLfloat p[24][3];
646 GLuint lineindices[3];
647 struct cline *cur, *line;
648 s_shader_capabilities_t *scap;
649 ttglobal tg = gglobal();
650 if(!extent6f_isSet(extent)) return;
651
652 scap = getMyShader(NO_APPEARANCE_SHADER);
653 enableGlobalShader(scap);
654 //glUniformMatrix4fv(scap->ModelViewMatrix, 1, GL_FALSE, cursIdentity);
655 //glUniformMatrix4fv(scap->ProjectionMatrix, 1, GL_FALSE, cursIdentity);
656 //printf("extent %f %f %f %f %f %f\n",extent[0],extent[1],extent[2],extent[3],extent[4],extent[5]);
657 lineindices[0] = 0;
658 lineindices[1] = 1;
659 lineindices[2] = -1;
660 n = 0;
661 //extent = testextent;
662 //lines parallel to x
663 for(k=0;k<2;k++)
664 for(j=0;j<2;j++)
665 for(i=0;i<2;i++){
666 p[n][0] = extent[i];
667 p[n][1] = extent[j+2];
668 p[n][2] = extent[k+4];
669 //printf("ei ej+2 ek+4 = %f %f %f\n",extent[i],extent[j+2],extent[k+4]);
670 //vecprinti3fb("vec",n, p[n], "\n");
671 n++;
672 }
673 //lines parallel to y
674 for(k=0;k<2;k++)
675 for(j=0;j<2;j++)
676 for(i=0;i<2;i++){
677 p[n][0] = extent[j];
678 p[n][1] = extent[i+2];
679 p[n][2] = extent[k+4];
680 //vecprinti3fb("vec",n, p[n], "\n");
681 n++;
682 }
683 //lines parallel to z
684 for(k=0;k<2;k++)
685 for(j=0;j<2;j++)
686 for(i=0;i<2;i++){
687 p[n][0] = extent[k];
688 p[n][1] = extent[j+2];
689 p[n][2] = extent[i+4];
690 //vecprinti3fb("vec",n, p[n], "\n");
691 n++;
692 }
693
694 //FW_GL_VERTEX_POINTER(2, GL_FLOAT, 0, (GLfloat *)p);
695 //sendArraysToGPU(GL_LINE_STRIP, 0, 3);
696 positionLoc = scap->Vertices; //glGetAttribLocation ( shader, "fw_Vertex" );
697 setupShaderB();
698 if(1){
699 //fewer calls
700 sendArraysToGPU (GL_LINES, 0, n);
701 FW_GL_VERTEX_POINTER (3,GL_FLOAT,0,p[0]);
702 reallyDrawOnce();
703 }else{
704 //this also works
705 sendElementsToGPU(GL_LINES,2,(int *)lineindices);
706
707 for(i=0;i<n;i+=2){
708 //printf("line [%f %f %f] to [%f %f %f]\n",p[i][0],p[i][1],p[i][2],p[i+1][0],p[i+1][1],p[i+1][2]);
709 //glVertexAttribPointer (positionLoc, 2, GL_FLOAT,
710 // GL_FALSE, 0, &p[i] );
711 //glDrawArrays(GL_LINE_STRIP,0,2);
712 FW_GL_VERTEX_POINTER (3,GL_FLOAT,0,p[i]);
713
714 //}
715 //draw
716 reallyDrawOnce();
717 }
718 }
719 clearDraw();
720
721 //printf("\n");
722 FW_GL_BINDBUFFER(GL_ARRAY_BUFFER, 0);
723 FW_GL_BINDBUFFER(GL_ELEMENT_ARRAY_BUFFER, 0);
724
725 restoreGlobalShader();
726}
727void draw_bbox(float *center, float *size){
728 float extent[6];
729 bbox2extent6f(center,size,extent);
730 extent6f_draw(extent);
731}
732void draw_viewpoint(int type, float *fov, float aspect)
733{
734 //assumes 0,0,0 is the perspective center, and -Z the look direction
735 int i,j,k,n;
736 GLint positionLoc;
737 GLfloat p[24][3];
738 struct cline *cur, *line;
739 s_shader_capabilities_t *scap;
740 ttglobal tg = gglobal();
741
742 scap = getMyShader(NO_APPEARANCE_SHADER);
743 enableGlobalShader(scap);
744 n = 0;
745 if(type == NODE_Viewpoint || type == NODE_GeoViewpoint){
746 //regular viewpoint
747 float d,w,h;
748 d = 1.0 * cos(*fov);
749 w = sin(*fov); //half-width
750 h = aspect *w; //half-height
751 //sides
752 vecset3f(p[0],0.0f,0.0f,0.0f);
753 vecset3f(p[1],w,h,-d);
754 vecset3f(p[2],0.0f,0.0f,0.0f);
755 vecset3f(p[3],-w,h,-d);
756 vecset3f(p[4],0.0f,0.0f,0.0f);
757 vecset3f(p[5],-w,-h,-d);
758 vecset3f(p[6],0.0f,0.0f,0.0f);
759 vecset3f(p[7],w,-h,-d);
760 //opening
761 vecset3f(p[8],-w,-h,-d);
762 vecset3f(p[9],w,-h,-d);
763 vecset3f(p[10],w,-h,-d);
764 vecset3f(p[11],w,h,-d);
765 vecset3f(p[12],w,h,-d);
766 vecset3f(p[13],-w,h,-d);
767 vecset3f(p[14],-w,h,-d);
768 vecset3f(p[15],-w,-h,-d);
769 n = 16;
770
771 }
772
773 if(type == NODE_OrthoViewpoint){
774 //regular viewpoint
775 float w1,w2,h1,h2,d = 1.0f;
776
777 //printf("ortho fov %f %f %f %f\n",fov[0],fov[1],fov[2],fov[3]);
778 w1=fov[0];
779 w2=fov[2];
780 h1=fov[1];
781 h2=fov[3];
782 vecset3f(p[0],w1,h1,d);
783 vecset3f(p[1],w2,h1,d);
784 vecset3f(p[2],w2,h1,d);
785 vecset3f(p[3],w2,h2,d);
786 vecset3f(p[4],w2,h2,d);
787 vecset3f(p[5],w1,h2,d);
788 vecset3f(p[6],w1,h2,d);
789 vecset3f(p[7],w1,h1,d);
790
791 vecset3f(p[8 ],w1,h1,-d);
792 vecset3f(p[9 ],w2,h1,-d);
793 vecset3f(p[10],w2,h1,-d);
794 vecset3f(p[11],w2,h2,-d);
795 vecset3f(p[12],w2,h2,-d);
796 vecset3f(p[13],w1,h2,-d);
797 vecset3f(p[14],w1,h2,-d);
798 vecset3f(p[15],w1,h1,-d);
799
800 n = 16;
801 }
802
803 //FW_GL_VERTEX_POINTER(2, GL_FLOAT, 0, (GLfloat *)p);
804 //sendArraysToGPU(GL_LINE_STRIP, 0, 3);
805 positionLoc = scap->Vertices; //glGetAttribLocation ( shader, "fw_Vertex" );
806 setupShaderB();
807 sendArraysToGPU (GL_LINES, 0, n);
808 FW_GL_VERTEX_POINTER (3,GL_FLOAT,0,p[0]);
809 reallyDrawOnce();
810 clearDraw();
811
812 //printf("\n");
813 FW_GL_BINDBUFFER(GL_ARRAY_BUFFER, 0);
814 FW_GL_BINDBUFFER(GL_ELEMENT_ARRAY_BUFFER, 0);
815
816 restoreGlobalShader();
817
818}
819void draw_frustum(float *corners)
820{
821 //assumes 0,0,0 is the perspective center, and -Z the look direction
822 int i,j,k,n;
823 GLint positionLoc;
824 GLfloat p[24][3];
825 struct cline *cur, *line;
826 s_shader_capabilities_t *scap;
827 ttglobal tg = gglobal();
828
829 n = 0;
830 for(int j=0;j<2;j++)
831 for(int i=0;i<4;i++){
832 int k = j*4 + i;
833 int m = j*4 + (i+1) % 4;
834 veccopy3f(p[n],&corners[k*3]);
835 veccopy3f(p[n+1],&corners[m*3]);
836 n+=2;
837 }
838 for(int i=0;i<4;i++){
839 veccopy3f(p[n],&corners[i*3]);
840 veccopy3f(p[n+1],&corners[(i+4)*3]);
841 n+=2;
842 }
843 scap = getMyShader(NO_APPEARANCE_SHADER);
844 enableGlobalShader(scap);
845 //FW_GL_VERTEX_POINTER(2, GL_FLOAT, 0, (GLfloat *)p);
846 //sendArraysToGPU(GL_LINE_STRIP, 0, 3);
847 positionLoc = scap->Vertices; //glGetAttribLocation ( shader, "fw_Vertex" );
848 setupShaderB();
849 sendArraysToGPU (GL_LINES, 0, n);
850 FW_GL_VERTEX_POINTER (3,GL_FLOAT,0,p[0]);
851 reallyDrawOnce();
852 clearDraw();
853
854 //printf("\n");
855 FW_GL_BINDBUFFER(GL_ARRAY_BUFFER, 0);
856 FW_GL_BINDBUFFER(GL_ELEMENT_ARRAY_BUFFER, 0);
857
858 restoreGlobalShader();
859
860}
861void line_draw(float* p, float* q, int depthtest, float width) {
862 GLint positionLoc;
863 GLfloat pp[2][3];
864
865 s_shader_capabilities_t* scap;
866 ttglobal tg = gglobal();
867 veccopy3f(pp[0], p);
868 veccopy3f(pp[1], q);
869 scap = getMyShader(NO_APPEARANCE_SHADER);
870 enableGlobalShader(scap);
871 positionLoc = scap->Vertices; //glGetAttribLocation ( shader, "fw_Vertex" );
872 setupShaderB();
873 sendArraysToGPU(GL_LINES, 0, 2);
874 FW_GL_VERTEX_POINTER(3, GL_FLOAT, 0, pp[0]);
875 if (!depthtest) glDisable(GL_DEPTH_TEST);
876 glLineWidth(width);
877 reallyDrawOnce();
878 if (!depthtest) glEnable(GL_DEPTH_TEST);
879 glLineWidth(1.0f);
880 clearDraw();
881
882 //printf("\n");
883 FW_GL_BINDBUFFER(GL_ARRAY_BUFFER, 0);
884 FW_GL_BINDBUFFER(GL_ELEMENT_ARRAY_BUFFER, 0);
885
886 restoreGlobalShader();
887
888}