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/OpenGL_Utils.h"
35#include "opengl/Textures.h"
36#include "opengl/LoadTextures.h"
37#include "main/MainLoop.h"
38#include "scenegraph/RenderFuncs.h"
39#include "statusbar.h"
40#include "../scenegraph/LinearAlgebra.h"
41
42
43/* I made a 32x32 image in Gimp, and exported to C Struct format */
44static const struct {
45 int width;
46 int height;
47 int bytes_per_pixel; /* 3:RGB, 4:RGBA */
48 GLubyte pixel_data[32 * 32 * 4 + 1];
49} circleCursor = {
50 32, 32, 4,
51 "\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"
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 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\206\377\200\200\200\377\200\200\200\377"
82 "\206\206\206\377\216\216\216\377\213\213\213\377ddd\363000\251\0\0\0""0\0"
83 "\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"
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,"
85 ",,\266yyy\373\247\247\247\377ttt\366<<<\313\33\33\33\227\0\0\0\200\0\0\0"
86 "\200\33\33\33\227<<<\313ttt\366\247\247\247\377yyy\373,,,\266\0\0\0""0\0"
87 "\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"
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\40""000\251yyy\373\213"
89 "\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"
90 "\0\0\0@\33\33\33\226GGG\347\213\213\213\377yyy\373000\251\0\0\0\40\0\0\0"
91 "\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"
92 "\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"
93 "\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"
94 "\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"
95 "\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"
96 "\0\0\0\0\0\0\0\0""0***\302\213\213\213\377ttt\366\33\33\33\226\0\0\0\40\0"
97 "\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"
98 "\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"
99 "\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"
100 "\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"
101 "\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"
102 "\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"
103 "\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"
104 "\33\33\33\227\0\0\0\20\0\0\0\0\0\0\0\0\0\0\0@,,,\271ccc\365ccc\365,,,\271"
105 "\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"
106 "\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"
107 "\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"
108 "\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"
109 "\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"
110 "\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"
111 "\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"
112 "\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"
113 "\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"
114 "\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"
115 "\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"
116 "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@,,,"
117 "\271ccc\365ccc\365,,,\271\0\0\0@\0\0\0\0\0\0\0\0\0\0\0\20\33\33\33\227\206"
118 "\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"
119 "\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"
120 "\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"
121 "\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"
122 "\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"
123 "\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"
124 "\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"
125 "\0\0\0\0\0\40\33\33\33\226ttt\366\213\213\213\377***\302\0\0\0""0\0\0\0\0"
126 "\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"
127 "\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"
128 "\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"
129 "\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"
130 "\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"
131 "\0\0\0\0\0\0\0\0\40""000\251yyy\373\213\213\213\377GGG\347\33\33\33\226\0"
132 "\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"
133 "\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"
134 "\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"
135 "\0\0\0\0\0\0""0,,,\266yyy\373\247\247\247\377ttt\366<<<\313\33\33\33\227"
136 "\0\0\0\200\0\0\0\200\33\33\33\227<<<\313ttt\366\247\247\247\377yyy\373,,"
137 ",\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"
138 "\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"
139 "\0\0\0\0\0\0""0000\251ddd\363\213\213\213\377\216\216\216\377\206\206\206"
140 "\377\200\200\200\377\200\200\200\377\206\206\206\377\216\216\216\377\213"
141 "\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"
142 "\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"
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\40\0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0\0\0\0\0\0"
171 "\0\0\0",
172};
173//
174//1-2 4
175//| /|
176//0 3 5
177GLfloat cursorVert[] = {
178 -.05f, -.05f, 0.0f,
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};
184GLfloat cursorTex[] = {
185 0.0f, 0.0f,
186 0.0f, 1.0f,
187 1.0f, 1.0f,
188 0.0f, 0.0f,
189 1.0f, 1.0f,
190 1.0f, 0.0f};
191
192typedef struct pCursorDraw{
193 GLuint textureID;
194 int done;
195}* ppCursorDraw;
196void *CursorDraw_constructor(){
197 void *v = MALLOCV(sizeof(struct pCursorDraw));
198 memset(v,0,sizeof(struct pCursorDraw));
199 return v;
200}
201void CursorDraw_init(struct tCursorDraw *t){
202 //public
203 //private
204 t->prv = CursorDraw_constructor();
205 {
206 ppCursorDraw p = (ppCursorDraw)t->prv;
207 p->done = 0;
208 p->textureID = 0;
209 }
210}
211
212typedef struct {int x; int y;} XY;
213XY mouse2screen2(int x, int y)
214{
215 XY xy;
216 xy.x = x;
217 //xy.y = gglobal()->display.screenHeight -y;
218 xy.y = y;
219 return xy;
220}
221typedef struct {GLfloat x; GLfloat y;} FXY;
222FXY screen2normalized( GLfloat x, GLfloat y )
223{
224 FXY xy;
225 xy.x = (x / gglobal()->display.screenWidth)*2.0f -1.0f;
226 xy.y = (y / gglobal()->display.screenHeight)*2.0f -1.0f;
227 return xy;
228}
229static GLfloat cursIdentity[] = {
230 1.0f, 0.0f, 0.0f, 0.0f,
231 0.0f, 1.0f, 0.0f, 0.0f,
232 0.0f, 0.0f, 1.0f, 0.0f,
233 0.0f, 0.0f, 0.0f, 1.0f
234};
235struct cline {
236 int n; //0 means no more lines
237 GLfloat p[6]; //max 3 xy points, fill unused with 0f
238};
239static struct cline cur_fiducials [] = {
240 {3,{-.02f,.0f, 0.0f,-.02f, .02f,.0f}}, // v offset downward a bit to get on the screen at the top
241 {0,{0.0f,0.0f,0.0f,0.0f,0.0f,0.0f}},
242};
243static struct cline cur_down [] = {
244 {3,{-.02f,.02f, .0f,.0f, .02f,.02f}}, // v
245 {0,{.0f,.0f,.0f,.0f,.0f,.0f}},
246};
247static struct cline cur_up [] = {
248 {3,{-.02f,-.02f, .0f,.0f, .02f,-.02f}}, // ^
249 {0,{.0f,.0f,.0f,.0f,.0f,.0f}},
250};
251static struct cline cur_hover [] = {
252 {2,{-.02f,.0f, .02f,.0f, .0f,.0f}}, // +
253 {2,{.0f,-.02f, .0f,.02f, .0f,.0f}},
254 {0,{.0f,.0f,.0f,.0f,.0f,.0f}},
255};
256static struct cline cur_over [] = {
257 {2,{.0f,.0f, .0f,.005f, .0f,.0f}}, // !
258 {2,{.0f,.008f, .0f,.02f, .0f,.0f}},
259 {0,{.0f,.0f,.0f,.0f,.0f,.0f}},
260};
261/* - in CursorDraw.h
262enum cursor_type {
263 CURSOR_UP = 0,
264 CURSOR_DOWN,
265 CURSOR_HOVER,
266 CURSOR_OVER,
267 CURSOR_FIDUCIALS
268};
269*/
270static struct cline *cursor_array [] = {
271 cur_up,
272 cur_down,
273 cur_hover,
274 cur_over,
275 cur_fiducials,
276 NULL,
277};
278/* attempt to draw fiducials with lines - draws wrong place */
279s_shader_capabilities_t *getMyShader(unsigned int rq_cap0);
280void fiducialDrawB(int cursortype, int x, int y)
281{
282 XY xy;
283 FXY fxy;
284 int i,k;
285 GLfloat p[3][2];
286 float aspect;
287 GLint positionLoc;
288 struct cline *cur, *line;
290 ttglobal tg = gglobal();
291
292 //as of May 2016 the mouse/touch events come in the pick() stack relative to the whole window
293 // -not shifted relative to the current vport in the vport stack.
294 // if that changes, then the following few lines would also need to change
295 xy = mouse2screen2(x,y);
296 FW_GL_VIEWPORT(0, 0, tg->display.screenWidth, tg->display.screenHeight);
297 fxy = screen2normalized((GLfloat)xy.x,(GLfloat)xy.y);
298 aspect = (float)tg->display.screenHeight/(float)tg->display.screenWidth;
299
300
301 FW_GL_DEPTHMASK(GL_FALSE);
302 glDisable(GL_DEPTH_TEST);
303 scap = getMyShader(NO_APPEARANCE_SHADER);
304 enableGlobalShader(scap);
305 glUniformMatrix4fv(scap->ModelViewMatrix, 1, GL_FALSE, cursIdentity);
306 glUniformMatrix4fv(scap->ProjectionMatrix, 1, GL_FALSE, cursIdentity);
307
308
309 //FW_GL_VERTEX_POINTER(2, GL_FLOAT, 0, (GLfloat *)p);
310 //sendArraysToGPU(GL_LINE_STRIP, 0, 3);
311 positionLoc = scap->Vertices; //glGetAttribLocation ( shader, "fw_Vertex" );
312
313 cur = cursor_array[cursortype];
314 k = 0;
315 line = &cur[k];
316 while(line->n){
317 for(i=0;i<line->n;i++){
318 p[i][0] = line->p[i*2]*aspect + fxy.x;
319 p[i][1] = line->p[i*2 + 1] + fxy.y;
320 }
321 glVertexAttribPointer (positionLoc, 2, GL_FLOAT,
322 GL_FALSE, 0, p );
323 glDrawArrays(GL_LINE_STRIP,0,line->n);
324 k++;
325 line = &cur[k];
326 }
327
328 FW_GL_BINDBUFFER(GL_ARRAY_BUFFER, 0);
329 FW_GL_BINDBUFFER(GL_ELEMENT_ARRAY_BUFFER, 0);
330
331
332 glEnable(GL_DEPTH_TEST);
333 FW_GL_DEPTHMASK(GL_TRUE);
334 restoreGlobalShader();
335}
336void fiducialDraw(int ID, int x, int y, float angleDeg)
337{
338 //pre- may 8, 2016
339 XY xy;
340 FXY fxy;
341 int i;
342 GLfloat p[3][2];
343 GLint positionLoc;
345 ttglobal tg = gglobal();
346
347 xy = mouse2screen2(x,y);
348 FW_GL_VIEWPORT(0, 0, tg->display.screenWidth, tg->display.screenHeight);
349 fxy = screen2normalized((GLfloat)xy.x,(GLfloat)xy.y);
350 //I was hoping for a little v at the top
351
352 p[0][0] = -.01f;
353 p[0][1] = .01f;
354 p[1][0] = .00f;
355 p[1][1] = .00f;
356 p[2][0] = .01f;
357 p[2][1] = .01f;
358 if(angleDeg != 0.0f){
359 GLfloat cosine, sine, angleRad, xx,yy;
360 angleRad = angleDeg * (float)PI / 180.0f;
361 cosine = cosf(angleRad);
362 sine = sinf(angleRad);
363 for(i=0;i<3;i++){
364 xx = cosine*p[i][0] + sine*p[i][1];
365 yy = -sine*p[i][0] + cosine*p[i][1];
366 p[i][0]=xx;
367 p[i][1]=yy;
368 }
369 }
370 if(ID == 1){
371 for(i=0;i<3;i++)
372 p[i][1] -= .01f;
373 }
374 for(i=0;i<3;i++){
375 p[i][0] += fxy.x;
376 p[i][1] += fxy.y;
377 }
378
379 FW_GL_DEPTHMASK(GL_FALSE);
380 glDisable(GL_DEPTH_TEST);
381 scap = getMyShader(NO_APPEARANCE_SHADER);
382 enableGlobalShader(scap);
383 glUniformMatrix4fv(scap->ModelViewMatrix, 1, GL_FALSE, cursIdentity);
384 glUniformMatrix4fv(scap->ProjectionMatrix, 1, GL_FALSE, cursIdentity);
385
386
387 //FW_GL_VERTEX_POINTER(2, GL_FLOAT, 0, (GLfloat *)p);
388 //sendArraysToGPU(GL_LINE_STRIP, 0, 3);
389 positionLoc = scap->Vertices; //glGetAttribLocation ( shader, "fw_Vertex" );
390 glVertexAttribPointer (positionLoc, 2, GL_FLOAT,
391 GL_FALSE, 0, p );
392 glDrawArrays(GL_LINE_STRIP,0,3);
393
394 FW_GL_BINDBUFFER(GL_ARRAY_BUFFER, 0);
395 FW_GL_BINDBUFFER(GL_ELEMENT_ARRAY_BUFFER, 0);
396
397
398 glEnable(GL_DEPTH_TEST);
399 FW_GL_DEPTHMASK(GL_TRUE);
400 restoreGlobalShader();
401}
402/* the slave cursor method emulates a multitouch, but doesn't suppress
403 the regular mouse cursor, so don't draw ID=0
404 currently no use of angle
405 as of March 14, 2012 I'm using this only in stereovision mode, to draw
406 viewport alignment fiducials
407 */
408void statusbarHud_DrawCursor(GLint textureID,int x,int y);
409
410unsigned int getCircleCursorTextureID(){
411 //not bad texture for use in testing elsewhere
412 ppCursorDraw p;
413 ttglobal tg = gglobal();
414 p = (ppCursorDraw)tg->CursorDraw.prv;
415 if(!p->done)
416 {
417 glGenTextures(1, &p->textureID);
418 glBindTexture(GL_TEXTURE_2D, p->textureID);
419 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
420 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
421 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, circleCursor.width, circleCursor.height, 0, GL_RGBA , GL_UNSIGNED_BYTE, circleCursor.pixel_data);
422 p->done = 1;
423 }
424 return p->textureID;
425}
426void cursorDraw(int ID, int x, int y, float angle)
427{
428 XY xy;
429 FXY fxy;
430 int i,j;
431 //GLint shader;
432 GLint positionLoc, texCoordLoc, textureLoc;
433 //GLint textureCount;
434 GLint textureMatrix0;
435 ppCursorDraw p;
436 GLfloat cursorVert2[18];
437 //GLushort ind[] = {0,1,2,3,4,5};
438 //GLint pos, tex;
440 ttglobal tg = gglobal();
441 p = (ppCursorDraw)tg->CursorDraw.prv;
442
443 //if( ID == 0 )return;
444
445 if(!p->done)
446 {
447 glGenTextures(1, &p->textureID);
448 glBindTexture(GL_TEXTURE_2D, p->textureID);
449 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
450 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
451 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, circleCursor.width, circleCursor.height, 0, GL_RGBA , GL_UNSIGNED_BYTE, circleCursor.pixel_data);
452 p->done = 1;
453 }
454#ifdef STATUSBAR_HUD
455 //Nov 2015: I find this works with emulate_multitouch and multi_window
456 statusbarHud_DrawCursor(p->textureID,x,y);
457 return;
458#endif
459#ifndef NEWWAY_COPIED_FROM_STATUSBARHUD_CURSORDRAW
460 //Nov 2015: I find this does NOT work 100% with emulate_multitouch and multi_window - it sometimes makes regular scene geometry invisible
461 FW_GL_DEPTHMASK(GL_FALSE);
462 glDisable(GL_DEPTH_TEST);
463 //if(p->programObject == 0) initProgramObject();
464 //glUseProgram ( p->programObject );
465 scap = getMyShader(ONE_TEX_APPEARANCE_SHADER);
466 enableGlobalShader(scap);
467 //shader = getAppearanceProperties()->currentShaderProperties->myShaderProgram;
468
469 xy = mouse2screen2(x,y);
470 FW_GL_VIEWPORT(0, 0, tg->display.screenWidth, tg->display.screenHeight);
471 fxy = screen2normalized((GLfloat)xy.x,(GLfloat)xy.y);
472 //fxy.y -= 1.0;
473 //fxy.x -= 1.0;
474 for(i=0;i<6;i++){
475 for(j=0;j<3;j++)
476 cursorVert2[i*3 + j] = cursorVert[i*3 +j];
477 cursorVert2[i*3 +0] += fxy.x;
478 cursorVert2[i*3 +1] += fxy.y;
479 }
480 positionLoc = scap->Vertices; //glGetAttribLocation ( shader, "fw_Vertex" );
481 glVertexAttribPointer (positionLoc, 3, GL_FLOAT,
482 GL_FALSE, 0, cursorVert2 );
483 // Load the texture coordinate
484 //texCoordLoc = glGetAttribLocation ( shader, "fw_MultiTexCoord0"); //"fw_TexCoords" );
485 texCoordLoc = scap->TexCoords[0];
486 glVertexAttribPointer ( texCoordLoc, 2, GL_FLOAT,
487 GL_FALSE, 0, cursorTex ); //fails - p->texCoordLoc is 429xxxxx - garbage
488 //glUniform4f(p->color4fLoc,0.7f,0.7f,0.9f,1.0f);
489 glEnableVertexAttribArray (positionLoc );
490 glEnableVertexAttribArray ( texCoordLoc);
491
493 glActiveTexture ( GL_TEXTURE0 );
494 glBindTexture ( GL_TEXTURE_2D, p->textureID );
495
496 // Set the base map sampler to texture unit to 0
497 //textureLoc = glGetAttribLocation ( shader, "fw_Texture_unit0"); //"fw_Texture0" );
498 textureLoc = scap->TextureUnit[0];
499 //textureCount = scap->textureCount;
500 //glUniform1i(textureCount,(GLint)1);
501 textureMatrix0 = scap->TextureMatrix[0];
502 glUniformMatrix4fv(textureMatrix0, 1, GL_FALSE, cursIdentity);
503
504 glUniform1i ( textureLoc, 0 );
505 //glDrawElements ( GL_TRIANGLES, 3*2, GL_UNSIGNED_SHORT, ind ); //just render the active ones
506
507 // this more direct hacking also works
508 //loc = glGetAttribLocation ( shader, "fw_ModelViewMatrix" );
509 glUniformMatrix4fv(scap->ModelViewMatrix, 1, GL_FALSE, cursIdentity);
510 //loc = glGetAttribLocation ( shader, "fw_ProjectionMatrix" );
511 glUniformMatrix4fv(scap->ProjectionMatrix, 1, GL_FALSE, cursIdentity);
512
513 glDrawArrays(GL_TRIANGLES,0,6);
514
515 FW_GL_BINDBUFFER(GL_ARRAY_BUFFER, 0);
516 FW_GL_BINDBUFFER(GL_ELEMENT_ARRAY_BUFFER, 0);
517
518
519 glEnable(GL_DEPTH_TEST);
520 FW_GL_DEPTHMASK(GL_TRUE);
521 restoreGlobalShader();
522
523#endif //NEWWAY_COPIED_FROM_STATUSBARHUD_CURSORDRAW
524
525#ifdef OLDWAY
526
527 FW_GL_DEPTHMASK(GL_FALSE);
528
529 #ifndef GL_ES_VERSION_2_0
530 FW_GL_SHADEMODEL(GL_FLAT);
531 y += 10;
532 #else
533
534 // There is an issue here where Anaglyph rendering gets dinked - see
535 // fwl_RenderSceneUpdateScene() for comments.
536 //return;
537
538
539// JAS, trying this GL_PUSH_MATRIX();
540
541 {
542 xy = mouse2screen2(x,y);
543 //FW_GL_VIEWPORT(0, 0, tg->display.screenWidth, tg->display.screenHeight);
544#ifdef OLDGL
545 FW_GL_MATRIX_MODE(GL_PROJECTION); //glMatrixMode(GL_PROJECTION);
546 FW_GL_LOAD_IDENTITY(); //glLoadIdentity();
547 FW_GL_MATRIX_MODE(GL_MODELVIEW); //glMatrixMode(GL_MODELVIEW);
548 FW_GL_LOAD_IDENTITY(); //glLoadIdentity();
549#endif
550 fxy = screen2normalized((GLfloat)xy.x,(GLfloat)xy.y);
551#ifdef OLDGL
552 FW_GL_TRANSLATE_F((float)fxy.x,(float)fxy.y,0.0f);
553#endif
554 }
555 enableGlobalShader(getMyShader(ONE_TEX_APPEARANCE_SHADER));
556 shader = getAppearanceProperties()->currentShaderProperties->myShaderProgram;
557 //glEnable(GL_TEXTURE_2D);
558 glActiveTexture ( GL_TEXTURE0 );
559 glBindTexture ( GL_TEXTURE_2D, p->textureID );
560 //SET_TEXTURE_UNIT(0);
561 //glActiveTexture(GL_TEXTURE0+c);
562 /*glUniform1i(loc+c, c); */
563 loc = glGetAttribLocation ( shader, "fw_Texture0" );
564 glUniform1i(loc,0);
565 loc = glGetAttribLocation ( shader, "fw_Vertex" );
566 xy = mouse2screen2(x,y);
567 for(i=0;i<6;i++){
568 for(j=0;j<3;j++)
569 cursorVert2[i*3 + j] = cursorVert[i*3 +j];
570 cursorVert2[i*3 +0] += fxy.x;
571 cursorVert2[i*3 +1] += fxy.y;
572
573 }
574 glVertexAttribPointer ( loc, 3, GL_FLOAT, GL_FALSE, 0, cursorVert2 );
575 // Load the texture coordinate
576 loc = glGetAttribLocation ( shader, "fw_TexCoords" );
577 glEnableVertexAttribArray ( loc );
578 glVertexAttribPointer ( loc, 2, GL_FLOAT, GL_FALSE, 0, cursorTex ); //fails - p->texCoordLoc is 429xxxxx - garbage
579
580 glEnableVertexAttribArray ( loc );
581
582
583
584// JAS, trying this GL_POP_MATRIX();
585
586 #endif /* GL_ES_VERSION_2_0 */
587 glDisable(GL_DEPTH_TEST);
588
589 //xy = mouse2screen2(x,y);
590 /* please note that OpenGL ES and OpenGL-3.x does not have the following; here is
591 a hint for future work:
592 "If you are using OpenGL ES 2.0, you can use framebuffer objects to render to
593 texture, which is a much better alternative."
594 */
595 #ifndef GL_ES_VERSION_2_0
596 FW_GL_WINDOWPOS2I(xy.x,xy.y);
597 FW_GL_DRAWPIXELS(circleCursor.width,circleCursor.height,GL_BGRA,GL_UNSIGNED_BYTE,circleCursor.pixel_data);
598 #else
599 if(0){
600 // this more direct hacking also works
601 loc = glGetAttribLocation ( shader, "fw_ModelViewMatrix" );
602 glUniformMatrix4fv(loc, 1, GL_FALSE, cursIdentity);
603 loc = glGetAttribLocation ( shader, "fw_ProjectionMatrix" );
604 glUniformMatrix4fv(loc, 1, GL_FALSE, cursIdentity);
605 }
606 glDrawArrays(GL_TRIANGLES,0,6);
607 #endif /* GL_ES_VERSION_2_0 */
608
609 glEnable(GL_DEPTH_TEST);
610
611 #ifndef GL_ES_VERSION_2_0
612 FW_GL_SHADEMODEL(GL_SMOOTH);
613 #endif /* GL_ES_VERSION_2_0 */
614 FW_GL_DEPTHMASK(GL_TRUE);
615 //FW_GL_FLUSH();
616#endif //OLDWAY
617
618 return;
619}
620void vecprinti3fb(char *name, int i, float *p, char *eol){
621printf("%s[%d] %f %f %f %s",name,i,p[0],p[1],p[2],eol);
622}
623int extent6f_isSet(float *extent6);
624static float testextent [] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f};
625void reallyDrawOnce();
626void clearDraw();
627void extent6f_draw(float *extent)
628{
629 //draw bouneding box / extent as lines
630 //hacked from cursorDrawB and Component_ParticalPhysics
631 int i,j,k,n;
632 GLint positionLoc;
633 GLfloat p[24][3];
634 unsigned short lineindices[3];
635 struct cline *cur, *line;
637 ttglobal tg = gglobal();
638 if(!extent6f_isSet(extent)) return;
639
640 scap = getMyShader(NO_APPEARANCE_SHADER);
641 enableGlobalShader(scap);
642 //glUniformMatrix4fv(scap->ModelViewMatrix, 1, GL_FALSE, cursIdentity);
643 //glUniformMatrix4fv(scap->ProjectionMatrix, 1, GL_FALSE, cursIdentity);
644 //printf("extent %f %f %f %f %f %f\n",extent[0],extent[1],extent[2],extent[3],extent[4],extent[5]);
645 lineindices[0] = 0;
646 lineindices[1] = 1;
647 lineindices[2] = -1;
648 n = 0;
649 //extent = testextent;
650 //lines parallel to x
651 for(k=0;k<2;k++)
652 for(j=0;j<2;j++)
653 for(i=0;i<2;i++){
654 p[n][0] = extent[i];
655 p[n][1] = extent[j+2];
656 p[n][2] = extent[k+4];
657 //printf("ei ej+2 ek+4 = %f %f %f\n",extent[i],extent[j+2],extent[k+4]);
658 //vecprinti3fb("vec",n, p[n], "\n");
659 n++;
660 }
661 //lines parallel to y
662 for(k=0;k<2;k++)
663 for(j=0;j<2;j++)
664 for(i=0;i<2;i++){
665 p[n][0] = extent[j];
666 p[n][1] = extent[i+2];
667 p[n][2] = extent[k+4];
668 //vecprinti3fb("vec",n, p[n], "\n");
669 n++;
670 }
671 //lines parallel to z
672 for(k=0;k<2;k++)
673 for(j=0;j<2;j++)
674 for(i=0;i<2;i++){
675 p[n][0] = extent[k];
676 p[n][1] = extent[j+2];
677 p[n][2] = extent[i+4];
678 //vecprinti3fb("vec",n, p[n], "\n");
679 n++;
680 }
681
682 //FW_GL_VERTEX_POINTER(2, GL_FLOAT, 0, (GLfloat *)p);
683 //sendArraysToGPU(GL_LINE_STRIP, 0, 3);
684 positionLoc = scap->Vertices; //glGetAttribLocation ( shader, "fw_Vertex" );
685 setupShaderB();
686 if(1){
687 //fewer calls
688 sendArraysToGPU (GL_LINES, 0, n);
689 FW_GL_VERTEX_POINTER (3,GL_FLOAT,0,p[0]);
690 reallyDrawOnce();
691 }else{
692 //this also works
693 sendElementsToGPU(GL_LINES,2,(ushort *)lineindices);
694
695 for(i=0;i<n;i+=2){
696 //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]);
697 //glVertexAttribPointer (positionLoc, 2, GL_FLOAT,
698 // GL_FALSE, 0, &p[i] );
699 //glDrawArrays(GL_LINE_STRIP,0,2);
700 FW_GL_VERTEX_POINTER (3,GL_FLOAT,0,p[i]);
701
702 //}
703 //draw
704 reallyDrawOnce();
705 }
706 }
707 clearDraw();
708
709 //printf("\n");
710 FW_GL_BINDBUFFER(GL_ARRAY_BUFFER, 0);
711 FW_GL_BINDBUFFER(GL_ELEMENT_ARRAY_BUFFER, 0);
712
713 restoreGlobalShader();
714}