-
Notifications
You must be signed in to change notification settings - Fork 1
/
OpenGLAbstraction.pde
executable file
·106 lines (88 loc) · 2.92 KB
/
OpenGLAbstraction.pde
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
/*
Harmonograph3d: An interactive 3d harmonograph
Copyright (C) 2010 Maxime Beauchemin
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
Class OpenGLAbstraction:
The goal is to keep all or most of the OpenGL specific code in this file to avoid abstract
the rest of the program from it all.
The current program uses vertex arrays, and the twisted treatment of all this is implement in this class.
*/
import javax.media.opengl.*;
import javax.media.opengl.glu.*;
import com.sun.opengl.util.*;
import processing.opengl.*;
import java.nio.*;
// Any time I want to draw a square, I use the squareList.
// Should be slightly faster than calling all the vertex calls over and over.
FloatBuffer vbuffer;
FloatBuffer cbuffer;
class OpenGLAbstraction
{
int numPoints;
PGraphicsOpenGL pgl;
GL gl;
OpenGLAbstraction()
{
pgl = (PGraphicsOpenGL) g;
gl = pgl.gl;
//gl.setSwapInterval(1);
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE);
}
void OpenGLStartDraw(int inNumPoints)
{
numPoints=inNumPoints;
pgl = (PGraphicsOpenGL) g;
int numPoints = inNumPoints;
vbuffer = BufferUtil.newFloatBuffer(numPoints * 3);
cbuffer = BufferUtil.newFloatBuffer(numPoints * 3);
gl.glDepthMask(false);
gl.glBlendFunc(GL.GL_SRC_ALPHA,GL.GL_ONE);
gl.glBlendEquation(GL.GL_FUNC_ADD);
}
void AddPoint(Vect3d v3d,color c)
{
vbuffer.put(v3d.x);
vbuffer.put(v3d.y);
vbuffer.put(v3d.z);
// random r,g,b
cbuffer.put(red(c));
cbuffer.put(green(c));
cbuffer.put(blue(c));
}
void OpenGLEndDraw()
{
vbuffer.rewind();
cbuffer.rewind();
pgl.beginGL();
if(ColorBlending.value==0)
{
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
gl.glBlendEquation(GL.GL_FUNC_ADD);
}
else
{
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE);
}
gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
gl.glVertexPointer(3, GL.GL_FLOAT, 0, vbuffer);
gl.glEnableClientState(GL.GL_COLOR_ARRAY);
gl.glColorPointer(3, GL.GL_FLOAT, 0, cbuffer);
gl.glLineWidth(StrokeWeight.value);
gl.glEnable (gl.GL_LINE_SMOOTH);
gl.glPushMatrix();
gl.glDrawArrays(GL.GL_LINE_STRIP, 0, numPoints);
gl.glPopMatrix();
pgl.endGL();
}
};