summaryrefslogtreecommitdiff
path: root/src/drivers/PicoAndroid/Fl_PicoAndroid_Graphics_Driver.cxx
blob: fd042bef4c136a4c71b263098db82459e8729c46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
//
// "$Id: Fl_PicoAndroid_Graphics_Driver.cxx 11241 2016-02-27 13:52:27Z manolo $"
//
// Rectangle drawing routines for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2016 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file.  If this
// file is missing or damaged, see the license at:
//
//     http://www.fltk.org/COPYING.php
//
// Please report all bugs and problems on the following page:
//
//     http://www.fltk.org/str.php
//


#include "../../config_lib.h"
#include "Fl_PicoAndroid_Graphics_Driver.h"

#include <jni.h>
#include <errno.h>

#include <EGL/egl.h>
#include <GLES/gl.h>

#include <android/log.h>
#include <android_native_app_glue.h>

#include <FL/Fl.H>

#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "native-activity", __VA_ARGS__))


/*
 * By linking this module, the following static method will instatiate the
 * PicoSDL Graphics driver as the main display driver.
 */
Fl_Graphics_Driver *Fl_Graphics_Driver::newMainGraphicsDriver()
{
  return new Fl_PicoAndroid_Graphics_Driver();
}




static GLint vertices[][3] = {
  { -0x10000, -0x10000, -0x10000 },
  {  0x10000, -0x10000, -0x10000 },
  {  0x10000,  0x10000, -0x10000 },
  { -0x10000,  0x10000, -0x10000 },
  { -0x10000, -0x10000,  0x10000 },
  {  0x10000, -0x10000,  0x10000 },
  {  0x10000,  0x10000,  0x10000 },
  { -0x10000,  0x10000,  0x10000 }
};

static GLint colors[][4] = {
  { 0x00000, 0x00000, 0x00000, 0x10000 },
  { 0x10000, 0x00000, 0x00000, 0x10000 },
  { 0x10000, 0x10000, 0x00000, 0x10000 },
  { 0x00000, 0x10000, 0x00000, 0x10000 },
  { 0x00000, 0x00000, 0x10000, 0x10000 },
  { 0x10000, 0x00000, 0x10000, 0x10000 },
  { 0x10000, 0x10000, 0x10000, 0x10000 },
  { 0x00000, 0x10000, 0x10000, 0x10000 }
};

GLubyte indices[] = {
  0, 4, 5,    0, 5, 1,
  1, 5, 6,    1, 6, 2,
  2, 6, 7,    2, 7, 3,
  3, 7, 4,    3, 4, 0,
  4, 7, 6,    4, 6, 5,
  3, 0, 1,    3, 1, 2
};

static void drawSomething()
{
  /*
  static float _angle = 0.0f;

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  glTranslatef(0, 0, -3.0f);
  glRotatef(_angle, 0, 1, 0);
  glRotatef(_angle*0.25f, 1, 0, 0);

  glEnableClientState(GL_VERTEX_ARRAY);
  glEnableClientState(GL_COLOR_ARRAY);

  glFrontFace(GL_CW);
  glVertexPointer(3, GL_FIXED, 0, vertices);
  glColorPointer(4, GL_FIXED, 0, colors);
  glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_BYTE, indices);

  _angle += 1.2f;
   */

  GLfloat q3[] = {
    -10,-10,
    10,-10,
    10,10,
    -10,10
  };

  uchar r, g, b;
  Fl::get_color(FL_RED, r, g, b);
//  Fl::get_color(Fl_Graphics_Driver::color(), r, g, b);
  glColor4ub(r, g, b, 255);

  glEnableClientState(GL_VERTEX_ARRAY);
  glVertexPointer(2, GL_FLOAT, 0, q3);
  glDrawArrays(GL_TRIANGLE_FAN,0,4);
  glDisableClientState(GL_VERTEX_ARRAY);
}



void Fl_PicoAndroid_Graphics_Driver::rectf(int x, int y, int w, int h)
{
  GLfloat q3[] = {
    x,     y,
    x,     y+h-3,
    x+w-3, y+h-3,
    x+w-3, y
  };

  uchar r, g, b;
  Fl::get_color(Fl_Graphics_Driver::color(), r, g, b);
  glColor4ub(r, g, b, 255);

  glEnableClientState(GL_VERTEX_ARRAY);
  glVertexPointer(2, GL_FLOAT, 0, q3);
  glDrawArrays(GL_TRIANGLE_FAN,0,4);
  glDisableClientState(GL_VERTEX_ARRAY);

  LOGI("Rect: %d %d %d %d", x, y, w, h);
}


void Fl_PicoAndroid_Graphics_Driver::line(int x, int y, int x1, int y1)
{
  GLfloat q3[] = {
    x,   y,
    x1, y1
  };

  uchar r, g, b;
  Fl::get_color(Fl_Graphics_Driver::color(), r, g, b);
  glColor4ub(r, g, b, 255);

  glEnableClientState(GL_VERTEX_ARRAY);
  glVertexPointer(2, GL_FLOAT, 0, q3);
  glDrawArrays(GL_LINES,0,2);
  glDisableClientState(GL_VERTEX_ARRAY);
}


void Fl_PicoAndroid_Graphics_Driver::point(int x, int y)
{
  GLfloat q3[] = {
    x, y
  };

  uchar r, g, b;
  Fl::get_color(Fl_Graphics_Driver::color(), r, g, b);
  glColor4ub(r, g, b, 255);

  glEnableClientState(GL_VERTEX_ARRAY);
  glVertexPointer(2, GL_POINTS, 0, q3);
  glDrawArrays(GL_LINES,0,1);
  glDisableClientState(GL_VERTEX_ARRAY);
}



//
// End of "$Id: Fl_PicoAndroid_Graphics_Driver.cxx 11241 2016-02-27 13:52:27Z manolo $".
//