1 package org.newdawn.slick.opengl.renderer;
2
3 import java.nio.ByteBuffer;
4 import java.nio.DoubleBuffer;
5 import java.nio.FloatBuffer;
6 import java.nio.IntBuffer;
7
8 import org.lwjgl.opengl.EXTSecondaryColor;
9 import org.lwjgl.opengl.GL11;
10 import org.lwjgl.opengl.GLContext;
11
12 import javax.annotation.Nonnull;
13
14
15
16
17
18
19 public class ImmediateModeOGLRenderer implements SGL {
20
21 private int width;
22
23 private int height;
24
25 @Nonnull
26 private final float[] current = new float[] {1,1,1,1};
27
28 float alphaScale = 1;
29
30
31
32
33
34 public void initDisplay(int width, int height) {
35 this.width = width;
36 this.height = height;
37
38
39
40 GL11.glEnable(GL11.GL_TEXTURE_2D);
41 GL11.glShadeModel(GL11.GL_SMOOTH);
42 GL11.glDisable(GL11.GL_DEPTH_TEST);
43 GL11.glDisable(GL11.GL_LIGHTING);
44
45 GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
46 GL11.glClearDepth(1);
47
48 GL11.glEnable(GL11.GL_BLEND);
49 GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
50
51 GL11.glViewport(0,0,width,height);
52 GL11.glMatrixMode(GL11.GL_MODELVIEW);
53 }
54
55
56
57
58
59 public void enterOrtho(int xsize, int ysize) {
60 this.width = xsize;
61 this.height = ysize;
62 GL11.glMatrixMode(GL11.GL_PROJECTION);
63 GL11.glLoadIdentity();
64 GL11.glOrtho(0, width, height, 0, 1, -1);
65 GL11.glMatrixMode(GL11.GL_MODELVIEW);
66 GL11.glLoadIdentity();
67 GL11.glViewport(0,0,width,height);
68 }
69
70
71
72
73 public void glBegin(int geomType) {
74 GL11.glBegin(geomType);
75 }
76
77
78
79
80 public void glBindTexture(int target, int id) {
81 GL11.glBindTexture(target, id);
82 }
83
84
85
86
87 public void glBlendFunc(int src, int dest) {
88 GL11.glBlendFunc(src, dest);
89 }
90
91
92
93
94 public void glCallList(int id) {
95 GL11.glCallList(id);
96 }
97
98
99
100
101 public void glClear(int value) {
102 GL11.glClear(value);
103 }
104
105
106
107
108 public void glClearColor(float red, float green, float blue, float alpha) {
109 GL11.glClearColor(red, green, blue, alpha);
110 }
111
112
113
114
115 public void glClipPlane(int plane, DoubleBuffer buffer) {
116 GL11.glClipPlane(plane, buffer);
117 }
118
119
120
121
122 public void glColor4f(float r, float g, float b, float a) {
123 a *= alphaScale;
124
125 current[0] = r;
126 current[1] = g;
127 current[2] = b;
128 current[3] = a;
129
130 GL11.glColor4f(r, g, b, a);
131 }
132
133
134
135
136 public void glColorMask(boolean red, boolean green, boolean blue, boolean alpha) {
137 GL11.glColorMask(red, green, blue, alpha);
138 }
139
140
141
142
143 public void glCopyTexImage2D(int target, int level, int internalFormat, int x, int y, int width, int height, int border) {
144 GL11.glCopyTexImage2D(target, level, internalFormat, x, y, width, height, border);
145 }
146
147
148
149
150 public void glDeleteTextures(IntBuffer buffer) {
151 GL11.glDeleteTextures(buffer);
152 }
153
154
155
156
157 public void glDisable(int item) {
158 GL11.glDisable(item);
159 }
160
161
162
163
164 public void glEnable(int item) {
165 GL11.glEnable(item);
166 }
167
168
169
170
171 public void glEnd() {
172 GL11.glEnd();
173 }
174
175
176
177
178 public void glEndList() {
179 GL11.glEndList();
180 }
181
182
183
184
185 public int glGenLists(int count) {
186 return GL11.glGenLists(count);
187 }
188
189
190
191
192 public void glGetFloat(int id, FloatBuffer ret) {
193 GL11.glGetFloat(id, ret);
194 }
195
196
197
198
199 public void glGetInteger(int id, IntBuffer ret) {
200 GL11.glGetInteger(id, ret);
201 }
202
203
204
205
206 public void glGetTexImage(int target, int level, int format, int type, ByteBuffer pixels) {
207 GL11.glGetTexImage(target, level, format, type, pixels);
208 }
209
210
211
212
213 public void glLineWidth(float width) {
214 GL11.glLineWidth(width);
215 }
216
217
218
219
220 public void glLoadIdentity() {
221 GL11.glLoadIdentity();
222 }
223
224
225
226
227 public void glNewList(int id, int option) {
228 GL11.glNewList(id, option);
229 }
230
231
232
233
234 public void glPointSize(float size) {
235 GL11.glPointSize(size);
236 }
237
238
239
240
241 public void glPopMatrix() {
242 GL11.glPopMatrix();
243 }
244
245
246
247
248 public void glPushMatrix() {
249 GL11.glPushMatrix();
250 }
251
252
253
254
255 public void glReadPixels(int x, int y, int width, int height, int format, int type, ByteBuffer pixels) {
256 GL11.glReadPixels(x, y, width, height, format, type, pixels);
257 }
258
259
260
261
262 public void glRotatef(float angle, float x, float y, float z) {
263 GL11.glRotatef(angle, x, y, z);
264 }
265
266
267
268
269 public void glScalef(float x, float y, float z) {
270 GL11.glScalef(x, y, z);
271 }
272
273
274
275
276 public void glScissor(int x, int y, int width, int height) {
277 GL11.glScissor(x, y, width, height);
278 }
279
280
281
282
283 public void glTexCoord2f(float u, float v) {
284 GL11.glTexCoord2f(u, v);
285 }
286
287
288
289
290 public void glTexEnvi(int target, int mode, int value) {
291 GL11.glTexEnvi(target, mode, value);
292 }
293
294
295
296
297 public void glTranslatef(float x, float y, float z) {
298 GL11.glTranslatef(x, y, z);
299 }
300
301
302
303
304 public void glVertex2f(float x, float y) {
305 GL11.glVertex2f(x, y);
306 }
307
308
309
310
311 public void glVertex3f(float x, float y, float z) {
312 GL11.glVertex3f(x, y, z);
313 }
314
315
316
317
318 public void flush() {
319 }
320
321
322
323
324 public void glTexParameteri(int target, int param, int value) {
325 GL11.glTexParameteri(target, param, value);
326 }
327
328
329
330
331 @Nonnull
332 public float[] getCurrentColor() {
333 return current;
334 }
335
336
337
338
339 public void glDeleteLists(int list, int count) {
340 GL11.glDeleteLists(list, count);
341 }
342
343
344
345
346 public void glClearDepth(float value) {
347 GL11.glClearDepth(value);
348 }
349
350
351
352
353 public void glDepthFunc(int func) {
354 GL11.glDepthFunc(func);
355 }
356
357
358
359
360 public void glDepthMask(boolean mask) {
361 GL11.glDepthMask(mask);
362 }
363
364
365
366
367 public void setGlobalAlphaScale(float alphaScale) {
368 this.alphaScale = alphaScale;
369 }
370
371
372
373
374 public void glLoadMatrix(FloatBuffer buffer) {
375 GL11.glLoadMatrix(buffer);
376 }
377
378
379
380
381
382 public void glGenTextures(IntBuffer ids) {
383 GL11.glGenTextures(ids);
384 }
385
386
387
388
389
390 public void glGetError() {
391 GL11.glGetError();
392 }
393
394
395
396
397
398 public void glTexImage2D(int target, int i, int dstPixelFormat,
399 int width, int height, int j, int srcPixelFormat,
400 int glUnsignedByte, ByteBuffer textureBuffer) {
401 GL11.glTexImage2D(target, i, dstPixelFormat, width, height, j, srcPixelFormat,glUnsignedByte,textureBuffer);
402 }
403
404 public void glTexSubImage2D(int glTexture2d, int i, int pageX, int pageY,
405 int width, int height, int glBgra, int glUnsignedByte,
406 ByteBuffer scratchByteBuffer) {
407 GL11.glTexSubImage2D(glTexture2d, i, pageX, pageY, width, height, glBgra, glUnsignedByte, scratchByteBuffer);
408 }
409
410
411
412
413
414 public boolean canTextureMirrorClamp() {
415 return GLContext.getCapabilities().GL_EXT_texture_mirror_clamp;
416 }
417
418
419
420
421
422 public boolean canSecondaryColor() {
423 return GLContext.getCapabilities().GL_EXT_secondary_color;
424 }
425
426
427
428
429
430 public void glSecondaryColor3ubEXT(byte b, byte c, byte d) {
431 EXTSecondaryColor.glSecondaryColor3ubEXT(b,c,d);
432 }
433 }