This repository has been archived by the owner on May 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
TestCase2.java
149 lines (124 loc) · 4.21 KB
/
TestCase2.java
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
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author aaklick
*/
import ion2d.support.*;
import org.lwjgl.opengl.*;
import java.nio.*;
import org.lwjgl.BufferUtils;
public class TestCase2
{
public static void main(String[] args)
{
INDisplay.createGLDisplay("TestCase", 800, 600, INTypes.DepthBufferFormat.DepthBufferNone, false);
setAlphaBlending(true);
setDepthTest(true);
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(0, INDisplay.getWidth(), 0, INDisplay.getHeight(), -1, 1);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();
GL11.glViewport(0, 0, INDisplay.getWidth(), INDisplay.getHeight());
while(!Display.isCloseRequested())
{
if(Display.isActive())
{
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
GL11.glPushMatrix();
enableDefaultGLStates();
float[] vertices = new float[3*4];
vertices[0] = 32.0f;
vertices[1] = 32.0f;
vertices[2] = 0.0f;
vertices[3] = 118.0f;
vertices[4] = 32.0f;
vertices[5] = 0.0f;
vertices[6] = 118.0f;
vertices[7] = 118.0f;
vertices[8] = 0.0f;
vertices[9] = 32.0f;
vertices[10] = 118.0f;
vertices[11] = 0.0f;
float[] colors = new float[4*4];
colors[0] = 0.5f;
colors[1] = 1.0f;
colors[2] = 0.5f;
colors[3] = 1.0f;
colors[4] = 0.5f;
colors[5] = 1.0f;
colors[6] = 0.5f;
colors[7] = 1.0f;
colors[8] = 0.5f;
colors[9] = 1.0f;
colors[10] = 0.5f;
colors[11] = 1.0f;
colors[12] = 0.5f;
colors[13] = 1.0f;
colors[14] = 0.5f;
colors[15] = 1.0f;
FloatBuffer verticeBuffer = BufferUtils.createFloatBuffer(3*4);
verticeBuffer.put(vertices);
verticeBuffer.rewind();
FloatBuffer colorBuffer = BufferUtils.createFloatBuffer(4*4);
colorBuffer.put(colors);
colorBuffer.rewind();
GL11.glColorPointer(4, 0, colorBuffer);
GL11.glVertexPointer(3, 0, verticeBuffer);
GL11.glDrawArrays(GL11.GL_QUADS, 0, 4);
disableDefaultGLStates();
GL11.glPopMatrix();
System.gc();
}
INDisplay.update();
}
Display.destroy();
}
protected static void enableDefaultGLStates()
{
if(Display.isCreated() == false) return;
GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);
//GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
GL11.glEnable(GL11.GL_TEXTURE_2D);
}
protected static void disableDefaultGLStates()
{
if(Display.isCreated() == false) return;
GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
GL11.glDisableClientState(GL11.GL_COLOR_ARRAY);
//GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
GL11.glDisable(GL11.GL_TEXTURE_2D);
}
public static void setAlphaBlending(boolean blending)
{
if(Display.isCreated() == false) return;
if(blending)
{
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(INTypes.BLEND_SRC, INTypes.BLEND_DST);
}
else
{
GL11.glDisable(GL11.GL_BLEND);
}
}
public static void setDepthTest(boolean depth)
{
if(Display.isCreated() == false) return;
if(depth)
{
GL11.glClearDepth(1.0f);
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glDepthFunc(GL11.GL_LEQUAL);
GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
}
else
{
GL11.glDisable(GL11.GL_DEPTH_TEST);
}
}
}