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