source: Include/abgl.ab@ 57

Last change on this file since 57 was 52, checked in by NoWest, 18 years ago

Add Methods to Material and Light Classes.

File size: 24.9 KB
Line 
1#ifndef _INC_ABGL
2#define _INC_ABGL
3
4#include <GL/gl.sbp>
5#include <GL/glu.sbp>
6
7Type RGB_FLOAT
8 r As GLfloat
9 g As GLfloat
10 b As GLfloat
11End Type
12
13Type RGB_DOUBLE
14 r As GLdouble
15 g As GLdouble
16 b As GLdouble
17End Type
18
19Class Color3f
20Public /* constructor */
21 Sub Color3f(r As GLfloat, g As GLfloat, b As GLfloat)
22 rgb.r = r
23 rgb.g = g
24 rgb.b = b
25 End Sub
26
27Public /* destructor */
28 Sub ~Color3f()
29 End Sub
30
31Public /* property */
32 Function R() As GLfloat
33 Return rgb.r
34 End Function
35 Function G() As GLfloat
36 Return rgb.g
37 End Function
38 Function B() As GLfloat
39 Return rgb.r
40 End Function
41 Sub R(r As GLfloat)
42 rgb.r = r
43 End Sub
44 Sub G(g As GLfloat)
45 rgb.g = g
46 End Sub
47 Sub B(b As GLfloat)
48 rgb.b = b
49 End Sub
50
51Protected
52 rgb As RGB_FLOAT
53End Class
54
55Class Color3d
56Public /* constructor */
57 Sub Color3d(r As GLdouble, g As GLdouble, b As GLdouble)
58 rgb.r = r
59 rgb.g = g
60 rgb.b = b
61 End Sub
62
63Public /* destructor */
64 Sub ~Color3d()
65 End Sub
66
67Public /* property */
68 Function R() As GLdouble
69 Return rgb.r
70 End Function
71 Function G() As GLdouble
72 Return rgb.g
73 End Function
74 Function B() As GLdouble
75 Return rgb.r
76 End Function
77 Sub R(r As GLdouble)
78 rgb.r = r
79 End Sub
80 Sub G(g As GLdouble)
81 rgb.g = g
82 End Sub
83 Sub B(b As GLdouble)
84 rgb.b = b
85 End Sub
86
87Protected
88 rgb As RGB_DOUBLE
89End Class
90
91Type RGBA_FLOAT
92 r As GLfloat
93 g As GLfloat
94 b As GLfloat
95 a As GLfloat
96End Type
97
98Type RGBA_DOUBLE
99 r As GLdouble
100 g As GLdouble
101 b As GLdouble
102 a As GLdouble
103End Type
104
105Class Color4f
106Public /* constructor */
107 Sub Color4f(r As GLfloat, g As GLfloat, b As GLfloat, a As GLfloat)
108 rgba.r = r
109 rgba.g = g
110 rgba.b = b
111 rgba.a = a
112 End Sub
113
114Public /* destructor */
115 Sub ~Color4f()
116 End Sub
117
118Public /* property */
119 Function R() As GLfloat
120 Return rgba.r
121 End Function
122 Function G() As GLfloat
123 Return rgba.g
124 End Function
125 Function B() As GLfloat
126 Return rgba.r
127 End Function
128 Function A() As GLfloat
129 Return rgba.a
130 End Function
131 Sub R(r As GLfloat)
132 rgba.r = r
133 End Sub
134 Sub G(g As GLfloat)
135 rgba.g = g
136 End Sub
137 Sub B(b As GLfloat)
138 rgba.b = b
139 End Sub
140 Sub A(a As GLfloat)
141 rgba.a = a
142 End Sub
143
144Protected
145 rgba As RGBA_FLOAT
146End Class
147
148Class Color4d
149
150Public /* constructor */
151 Sub Color4d(r As GLdouble, g As GLdouble, b As GLdouble, a As GLdouble)
152 rgba.r = r
153 rgba.g = g
154 rgba.b = b
155 rgba.a = a
156 End Sub
157
158Public /* destructor */
159 Sub ~Color4d()
160 End Sub
161
162Public /* property */
163 Function R() As GLdouble
164 Return rgba.r
165 End Function
166 Function G() As GLdouble
167 Return rgba.g
168 End Function
169 Function B() As GLdouble
170 Return rgba.r
171 End Function
172 Function A() As GLdouble
173 Return rgba.a
174 End Function
175 Sub R(r As GLdouble)
176 rgba.r = r
177 End Sub
178 Sub G(g As GLdouble)
179 rgba.g = g
180 End Sub
181 Sub B(b As GLdouble)
182 rgba.b = b
183 End Sub
184 Sub A(a As GLdouble)
185 rgba.a = a
186 End Sub
187
188Protected
189 rgba As RGBA_DOUBLE
190End Class
191
192
193
194Class Light
195Private
196 Number As GLenum
197
198Public
199 Sub Enabled(enabled As GLboolean)
200 Dim lighting As GLboolean
201 glGetBooleanv(Number,VarPtr(lighting))
202 Return lighting
203 End Sub
204 Function Enable() As GLboolean
205 If enabled Then
206 glEnable(Number)
207 Else
208 glDisable(Number)
209 End If
210 End Function
211
212Public /* constructor */
213 Sub Light(num As GLenum)
214 Number=num
215 End Sub
216
217Public
218 Sub SetAmbient(red As GLfloat, green As GLfloat, blue As GLfloat, alpha As GLfloat)
219 Dim amb[3] As GLfloat
220 amb[0]=red
221 amb[1]=green
222 amb[2]=blue
223 amb[3]=alpha
224 glLightfv(Number,GL_AMBIENT,amb)
225 End Sub
226 Sub SetAmbient(color As Color4f)
227 Dim amb[3] As GLfloat
228 amb[0]=color.R
229 amb[1]=color.G
230 amb[2]=color.B
231 amb[3]=color.A
232 glLightfv(Number,GL_AMBIENT,amb)
233 End Sub
234 Sub SetAmbient(amb As *GLfloat)
235 glLightfv(Number,GL_AMBIENT,amb)
236 End Sub
237
238 Sub SetDiffuse(red As GLfloat, green As GLfloat, blue As GLfloat, alpha As GLfloat)
239 Dim dif[3] As GLfloat
240 dif[0]=red
241 dif[1]=green
242 dif[2]=blue
243 dif[3]=alpha
244 glLightfv(Number,GL_DIFFUSE,dif)
245 End Sub
246 Sub SetDiffuse(color As Color4f)
247 Dim dif[3] As GLfloat
248 amb[0]=color.R
249 amb[1]=color.G
250 amb[2]=color.B
251 amb[3]=color.A
252 glLightfv(Number,GL_DIFFUSE,dif)
253 End Sub
254 Sub SetDiffuse(dif As *GLfloat)
255 glLightfv(Number,GL_DIFFUSE,dif)
256 End Sub
257
258 Sub SetSpecular(red As GLfloat, green As GLfloat, blue As GLfloat, alpha As GLfloat)
259 Dim spc[3] As GLfloat
260 spc[0]=red
261 spc[1]=green
262 spc[2]=blue
263 spc[3]=alpha
264 glLightfv(Number,GL_SPECULAR,spc)
265 End Sub
266 Sub SetSpecular(color As Color4f)
267 Dim spc[3] As GLfloat
268 amb[0]=color.R
269 amb[1]=color.G
270 amb[2]=color.B
271 amb[3]=color.A
272 glLightfv(Number,GL_SPECULAR,spc)
273 End Sub
274 Sub SetSpecular(spc As *GLfloat)
275 glLightfv(Number,GL_SPECULAR,spc)
276 End Sub
277
278 Sub SetPosition(pos As *GLfloat)
279 glLightfv(Number,GL_POSITION,pos)
280 End Sub
281End Class
282
283Class Material
284Public
285 Sub Ambient(red As GLfloat, green As GLfloat, blue As GLfloat, alpha As GLfloat)
286 Dim face As GLenum
287 glGetIntegerv(GL_COLOR_MATERIAL_FACE,VarPtr(face))
288 Dim amb[3] As GLfloat
289 amb[0]=red
290 amb[1]=green
291 amb[2]=blue
292 amb[3]=alpha
293 glMaterialfv(face,GL_AMBIENT,amb)
294 End Sub
295 Sub Ambient(color As Color4f)
296 Dim face As GLenum
297 glGetIntegerv(GL_COLOR_MATERIAL_FACE,VarPtr(face))
298 Dim amb[3] As GLfloat
299 amb[0]=color.R
300 amb[1]=color.G
301 amb[2]=color.B
302 amb[3]=color.A
303 glMaterialfv(face,GL_AMBIENT,amb)
304 End Sub
305 Sub Ambient(amb As *GLfloat)
306 glMaterialfv(face,GL_AMBIENT,amb)
307 End Sub
308
309 Sub Diffuse(red As GLfloat, green As GLfloat, blue As GLfloat, alpha As GLfloat)
310 Dim face As GLenum
311 glGetIntegerv(GL_COLOR_MATERIAL_FACE,VarPtr(face))
312 Dim dif[3] As GLfloat
313 dif[0]=red
314 dif[1]=green
315 dif[2]=blue
316 dif[3]=alpha
317 glMaterialfv(face,GL_DIFFUSE,dif)
318 End Sub
319 Sub Diffuse(color As Color4f)
320 Dim face As GLenum
321 glGetIntegerv(GL_COLOR_MATERIAL_FACE,VarPtr(face))
322 Dim dif[3] As GLfloat
323 dif[0]=color.R
324 dif[1]=color.G
325 dif[2]=color.B
326 dif[3]=color.A
327 glMaterialfv(face,GL_DIFFUSE,dif)
328 End Sub
329 Sub Diffuse(dif As *GLfloat)
330 glMaterialfv(face,GL_DIFFUSE,dif)
331 End Sub
332
333 Sub Specular(red As GLfloat, green As GLfloat, blue As GLfloat, alpha As GLfloat)
334 Dim face As GLenum
335 glGetIntegerv(GL_COLOR_MATERIAL_FACE,VarPtr(face))
336 Dim spc[3] As GLfloat
337 spc[0]=red
338 spc[1]=green
339 spc[2]=blue
340 spc[3]=alpha
341 glMaterialfv(face,GL_SPECULAR,spc)
342 End Sub
343 Sub Specular(color As Color4f)
344 Dim face As GLenum
345 glGetIntegerv(GL_COLOR_MATERIAL_FACE,VarPtr(face))
346 Dim spc[3] As GLfloat
347 spc[0]=color.R
348 spc[1]=color.G
349 spc[2]=color.B
350 spc[3]=color.A
351 glMaterialfv(face,GL_SPECULAR,spc)
352 End Sub
353 Sub Specular(spc As *GLfloat)
354 glMaterialfv(face,GL_SPECULAR,spc)
355 End Sub
356
357 Sub Shininess(shin As GLfloat)
358 Dim face As GLenum
359 glGetIntegerv(GL_COLOR_MATERIAL_FACE,VarPtr(face))
360 glMaterialf(face,GL_SHININESS,shin)
361 End Sub
362
363 Sub Emission(red As GLfloat, green As GLfloat, blue As GLfloat, alpha As GLfloat)
364 Dim face As GLenum
365 glGetIntegerv(GL_COLOR_MATERIAL_FACE,VarPtr(face))
366 Dim ems[3] As GLfloat
367 ems[0]=red
368 ems[1]=green
369 ems[2]=blue
370 ems[3]=alpha
371 glMaterialfv(face,GL_EMISSION,ems)
372 End Sub
373End Class
374
375Class ModelView
376Public
377 Sub LoadIdentity()
378 Dim mode As GLenum
379 glGetIntegerv(GL_MATRIX_MODE,VarPtr(mode))
380 If mode<>GL_MODELVIEW Then glMatrixMode(GL_MODELVIEW)
381 glLoadIdentity()
382 If mode<>GL_MODELVIEW Then glMatrixMode(mode)
383 End Sub
384 Sub LookAt(eyex As GLdouble, eyey As GLdouble, eyez As GLdouble, centerx As GLdouble, centery As GLdouble, centerz As GLdouble, upx As GLdouble, upy As GLdouble, upz As GLdouble)
385 Dim mode As GLenum
386 glGetIntegerv(GL_MATRIX_MODE,VarPtr(mode))
387 If mode<>GL_MODELVIEW Then glMatrixMode(GL_MODELVIEW)
388 gluLookAt(eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz)
389 If mode<>GL_MODELVIEW Then glMatrixMode(mode)
390 End Sub
391 Sub RotateX(angle As GLdouble)
392 Dim mode As GLenum
393 glGetIntegerv(GL_MATRIX_MODE,VarPtr(mode))
394 If mode<>GL_MODELVIEW Then glMatrixMode(GL_MODELVIEW)
395 glRotated(angle, 1.0 As GLdouble, 0.0 As GLdouble, 0.0 As GLdouble)
396 If mode<>GL_MODELVIEW Then glMatrixMode(mode)
397 End Sub
398 Sub RotateX(angle As GLfloat)
399 Dim mode As GLenum
400 glGetIntegerv(GL_MATRIX_MODE,VarPtr(mode))
401 If mode<>GL_MODELVIEW Then glMatrixMode(GL_MODELVIEW)
402 glRotatef(angle, 1.0 As GLfloat, 0.0 As GLfloat, 0.0 As GLfloat)
403 If mode<>GL_MODELVIEW Then glMatrixMode(mode)
404 End Sub
405 Sub RotateY(angle As GLdouble)
406 Dim mode As GLenum
407 glGetIntegerv(GL_MATRIX_MODE,VarPtr(mode))
408 If mode<>GL_MODELVIEW Then glMatrixMode(GL_MODELVIEW)
409 glRotated(angle, 0.0 As GLdouble, 1.0 As GLdouble, 0.0 As GLdouble)
410 If mode<>GL_MODELVIEW Then glMatrixMode(mode)
411 End Sub
412 Sub RotateY(angle As GLfloat)
413 Dim mode As GLenum
414 glGetIntegerv(GL_MATRIX_MODE,VarPtr(mode))
415 If mode<>GL_MODELVIEW Then glMatrixMode(GL_MODELVIEW)
416 glRotatef(angle, 0.0 As GLfloat, 1.0 As GLfloat, 0.0 As GLfloat)
417 If mode<>GL_MODELVIEW Then glMatrixMode(mode)
418 End Sub
419 Sub RotateZ(angle As GLdouble)
420 Dim mode As GLenum
421 glGetIntegerv(GL_MATRIX_MODE,VarPtr(mode))
422 If mode<>GL_MODELVIEW Then glMatrixMode(GL_MODELVIEW)
423 glRotated(angle, 0.0 As GLdouble, 0.0 As GLdouble, 1.0 As GLdouble)
424 If mode<>GL_MODELVIEW Then glMatrixMode(mode)
425 End Sub
426 Sub RotateZ(angle As GLfloat)
427 Dim mode As GLenum
428 glGetIntegerv(GL_MATRIX_MODE,VarPtr(mode))
429 If mode<>GL_MODELVIEW Then glMatrixMode(GL_MODELVIEW)
430 glRotatef(angle, 0.0 As GLfloat, 0.0 As GLfloat, 1.0 As GLfloat)
431 If mode<>GL_MODELVIEW Then glMatrixMode(mode)
432 End Sub
433 Sub Scale(x As GLdouble, y As GLdouble, z As GLdouble)
434 Dim mode As GLenum
435 glGetIntegerv(GL_MATRIX_MODE,VarPtr(mode))
436 If mode<>GL_MODELVIEW Then glMatrixMode(GL_MODELVIEW)
437 glScaled(x, y, z)
438 If mode<>GL_MODELVIEW Then glMatrixMode(mode)
439 End Sub
440 Sub Scale(x As GLfloat, y As GLfloat, z As GLfloat)
441 Dim mode As GLenum
442 glGetIntegerv(GL_MATRIX_MODE,VarPtr(mode))
443 If mode<>GL_MODELVIEW Then glMatrixMode(GL_MODELVIEW)
444 glScalef(x, y, z)
445 If mode<>GL_MODELVIEW Then glMatrixMode(mode)
446 End Sub
447 Sub Translate(x As GLdouble, y As GLdouble, z As GLdouble)
448 Dim mode As GLenum
449 glGetIntegerv(GL_MATRIX_MODE,VarPtr(mode))
450 If mode<>GL_MODELVIEW Then glMatrixMode(GL_MODELVIEW)
451 glTranslated(x, y, z)
452 If mode<>GL_MODELVIEW Then glMatrixMode(mode)
453 End Sub
454 Sub Translate(x As GLfloat, y As GLfloat, z As GLfloat)
455 Dim mode As GLenum
456 glGetIntegerv(GL_MATRIX_MODE,VarPtr(mode))
457 If mode<>GL_MODELVIEW Then glMatrixMode(GL_MODELVIEW)
458 glTranslatef(x, y, z)
459 If mode<>GL_MODELVIEW Then glMatrixMode(mode)
460 End Sub
461End Class
462
463Class Projection
464Public
465 Sub LoadIdentity()
466 Dim mode As GLenum
467 glGetIntegerv(GL_MATRIX_MODE,VarPtr(mode))
468 If mode<>GL_PROJECTION Then glMatrixMode(GL_PROJECTION)
469 glLoadIdentity()
470 If mode<>GL_PROJECTION Then glMatrixMode(mode)
471 End Sub
472 Sub Ortho2D(left As GLdouble, right As GLdouble, bottom As GLdouble, top As GLdouble)
473 Dim mode As GLenum
474 glGetIntegerv(GL_MATRIX_MODE,VarPtr(mode))
475 If mode<>GL_PROJECTION Then glMatrixMode(GL_PROJECTION)
476 gluOrtho2D(left, right, bottom, top)
477 If mode<>GL_PROJECTION Then glMatrixMode(mode)
478 End Sub
479 Sub Ortho3D(left As GLdouble, right As GLdouble, bottom As GLdouble, top As GLdouble, zNear As GLdouble, zFar As GLdouble)
480 Dim mode As GLenum
481 glGetIntegerv(GL_MATRIX_MODE,VarPtr(mode))
482 If mode<>GL_PROJECTION Then glMatrixMode(GL_PROJECTION)
483 glOrtho(left, right, bottom, top, zNear, zFar)
484 If mode<>GL_PROJECTION Then glMatrixMode(mode)
485 End Sub
486 Sub Frustum(left As GLdouble, right As GLdouble, bottom As GLdouble, top As GLdouble, zNear As GLdouble, zFar As GLdouble)
487 Dim mode As GLenum
488 glGetIntegerv(GL_MATRIX_MODE,VarPtr(mode))
489 If mode<>GL_PROJECTION Then glMatrixMode(GL_PROJECTION)
490 glFrustum(left, right, bottom, top, zNear, zFar)
491 If mode<>GL_PROJECTION Then glMatrixMode(mode)
492 End Sub
493 Sub Perspective(fovy As GLdouble, aspect As GLdouble, zNear As GLdouble, zFar As GLdouble)
494 Dim mode As GLenum
495 glGetIntegerv(GL_MATRIX_MODE,VarPtr(mode))
496 If mode<>GL_PROJECTION Then glMatrixMode(GL_PROJECTION)
497 gluPerspective(fovy, aspect, zNear, zFar)
498 If mode<>GL_PROJECTION Then glMatrixMode(mode)
499 End Sub
500End Class
501
502Class Transform
503Public
504 Projection As Projection
505 ModelView As ModelView
506End Class
507
508Class LightModel
509Public
510/* Function Ambient () As GLenum
511 Dim amb As GLenum
512 glGetFloatv(GL_LIGHT_MODEL_AMBIENT,VarPtr(amb))
513 Return func
514 End Function*/
515 Sub Ambient(amb As *GLfloat)
516 glLightModelfv(GL_LIGHT_MODEL_AMBIENT,VarPtr(amb))
517 End Sub
518
519 Function LocalView() As GLboolean
520 Dim local As GLboolean
521 glGetBooleanv(GL_LIGHT_MODEL_LOCAL_VIEW,VarPtr(local))
522 Return local
523 End Function
524 Sub LocalView(enable As GLboolean)
525 If enable Then
526 glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEW,GL_TRUE)
527 Else
528 glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEW,GL_FALSE)
529 End If
530 End Sub
531
532 Function TwoSide() As GLboolean
533 Dim local As GLboolean
534 glGetBooleanv(GL_LIGHT_MODEL_TWO_SIDE,VarPtr(local))
535 Return local
536 End Function
537 Sub TwoSide(enable As GLboolean)
538 If enable Then
539 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE)
540 Else
541 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_FALSE)
542 End If
543 End Sub
544End Class
545
546Class RenderState
547Public /* Composiotion */
548 LightModel As LightModel
549
550Public
551 Function AlphaTestEnable() As GLboolean
552 Dim alpha As GLboolean
553 glGetBooleanv(GL_ALPHA_TEST,VarPtr(alpha))
554 Return alpha
555 End Function
556 Sub AlphaTestEnable(enable As GLboolean)
557 If enable Then
558 glEnable(GL_ALPHA_TEST)
559 Else
560 glDisable(GL_ALPHA_TEST)
561 End If
562 End Sub
563
564 Function AlphaFunction() As GLenum
565 Dim func As GLenum
566 glGetIntegerv(GL_ALPHA_TEST_FUNC,VarPtr(func))
567 Return func
568 End Function
569 Sub AlphaFunction(func As GLenum)
570 Dim ref As GLclampf
571 glGetFloatv(GL_ALPHA_TEST_REF,VarPtr(ref))
572 glAlphaFunc(func,ref)
573 End Sub
574
575 Function BlendEnable() As GLboolean
576 Dim blend As GLboolean
577 glGetBooleanv(GL_BLEND,VarPtr(blend))
578 Return blend
579 End Function
580 Sub BlendEnable(enable As GLboolean)
581 If enable Then
582 glEnable(GL_BLEND)
583 Else
584 glDisable(GL_BLEND)
585 End If
586 End Sub
587
588 Function BlendDestinationFactor() As GLenum
589 Dim dfactor As GLenum
590 glGetIntegerv(GL_BLEND_DST,VarPtr(dfactor))
591 Return dfactor
592 End Function
593 Sub BlendDestinationFactor(dfactor As GLenum)
594 Dim sfactor As GLenum
595 glGetIntegerv(GL_BLEND_SRC,VarPtr(sfactor))
596 glBlendFunc(sfactor,dfactor)
597 End Sub
598
599 Function BlendSourceFactor() As GLenum
600 Dim sfactor As GLenum
601 glGetIntegerv(GL_BLEND_SRC,VarPtr(sfactor))
602 Return sfactor
603 End Function
604 Sub BlendSourceFactor(sfactor As GLenum)
605 Dim dfactor As GLenum
606 glGetIntegerv(GL_BLEND_DST,VarPtr(dfactor))
607 glBlendFunc(sfactor,dfactor)
608 End Sub
609
610 Function CullFaceEnable() As GLboolean
611 Dim cull As GLboolean
612 glGetBooleanv(GL_CULL_FACE,VarPtr(cull))
613 Return cull
614 End Function
615 Sub CullFaceEnable(enable As GLboolean)
616 If enable Then
617 glEnable(GL_CULL_FACE)
618 Else
619 glDisable(GL_CULL_FACE)
620 End If
621 End Sub
622
623 Function CullFaceMode () As GLenum
624 Dim mode As GLenum
625 glGetIntegerv(GL_CULL_FACE_MODE,VarPtr(mode))
626 Return mode
627 End Function
628 Sub CullFaceMode(mode As GLenum)
629 glCullFace(mode)
630 End Sub
631
632 Function DepthTestEnable () As GLboolean
633 Dim depth As GLboolean
634 glGetBooleanv(GL_DEPTH_TEST,VarPtr(depth))
635 Return depth
636 End Function
637 Sub DepthTestEnable(enable As GLboolean)
638 If enable Then
639 glEnable(GL_DEPTH_TEST)
640 Else
641 glDisable(GL_DEPTH_TEST)
642 End If
643 End Sub
644
645 Function DepthFunction () As GLenum
646 Dim func As GLenum
647 glGetIntegerv(GL_DEPTH_FUNC,VarPtr(func))
648 Return func
649 End Function
650 Sub DepthFunction(func As GLenum)
651 glDepthFunc(func)
652 End Sub
653
654 Function DepthBufferWritable() As GLboolean
655 Dim writable As GLboolean
656 glGetBooleanv(GL_DEPTH_WRITEMASK,VarPtr(writable))
657 Return writable
658 End Function
659 Sub DepthBufferWritable(enable As GLboolean)
660 If enable Then
661 glDepthMask(GL_DEPTH_WRITEMASK)
662 Else
663 glDepthMask(GL_DEPTH_WRITEMASK)
664 End If
665 End Sub
666
667 Function DitherEnable() As GLboolean
668 Dim dither As GLboolean
669 glGetBooleanv(GL_DITHER,VarPtr(dither))
670 Return dither
671 End Function
672 Sub DitherEnable(enable As GLboolean)
673 If enable Then
674 glEnable(GL_DITHER)
675 Else
676 glDisable(GL_DITHER)
677 End If
678 End Sub
679
680 Function FogEnable () As GLboolean
681 Dim fog As GLboolean
682 glGetBooleanv(GL_FOG,VarPtr(fog))
683 Return fog
684 End Function
685 Sub FogEnable(enable As GLboolean)
686 If enable Then
687 glEnable(GL_FOG)
688 Else
689 glDisable(GL_FOG)
690 End If
691 End Sub
692
693 Function FogMode() As GLenum
694 Dim mode As GLenum
695 glGetIntegerv(GL_FOG_MODE,VarPtr(mode))
696 Return mode
697 End Function
698 Sub FogMode(mode As GLenum)
699 glFogi(GL_FOG_MODE,mode)
700 End Sub
701
702 Function FogColor() As *GLfloat
703 glGetFloatv(GL_FOG_COLOR,FogColor)
704 Return FogColor
705 End Function
706 Sub FogColor(fcolor As *GLfloat)
707 glFogfv(GL_FOG_COLOR,fcolor)
708 End Sub
709
710 Function FogDensity() As GLfloat
711 Dim density As GLfloat
712 glGetFloatv(GL_FOG_DENSITY,density)
713 Return density
714 End Function
715 Sub FogDensity(density As GLfloat)
716 glFogf(GL_FOG_DENSITY,density)
717 End Sub
718
719 Function FogStart() As GLfloat
720 Dim fstrat As GLfloat
721 glGetFloatv(GL_FOG_START,fstrat)
722 Return fstrat
723 End Function
724 Sub FogStart(fstrat As GLfloat)
725 glFogf(GL_FOG_START,fstrat)
726 End Sub
727
728 Function FogEnd() As GLfloat
729 Dim fend As GLfloat
730 glGetFloatv(GL_FOG_END,fend)
731 Return fend
732 End Function
733 Sub FogEnd(fend As GLfloat)
734 glFogf(GL_FOG_END,fend)
735 End Sub
736
737 Function Lighting() As GLboolean
738 Dim lighting As GLboolean
739 glGetBooleanv(GL_LIGHTING,VarPtr(lighting))
740 Return lighting
741 End Function
742 Sub Lighting(enable As GLboolean)
743 If enable Then
744 glEnable(GL_LIGHTING)
745 Else
746 glDisable(GL_LIGHTING)
747 End If
748 End Sub
749
750 Function LineSmoothEnable() As GLboolean
751 Dim smooth As GLboolean
752 glGetBooleanv(GL_LINE_SMOOTH,VarPtr(smooth))
753 Return smooth
754 End Function
755 Sub LineSmoothEnable(enable As GLboolean)
756 If enable Then
757 glEnable(GL_LINE_SMOOTH)
758 Else
759 glDisable(GL_LINE_SMOOTH)
760 End If
761 End Sub
762
763 Function LogicOpEnable() As GLboolean
764 Dim logic As GLboolean
765 glGetBooleanv(GL_COLOR_LOGIC_OP,VarPtr(logic))
766 Return logic
767 End Function
768 Sub LogicOpEnable(enable As GLboolean)
769 If enable Then
770 glEnable(GL_COLOR_LOGIC_OP)
771 Else
772 glDisable(GL_COLOR_LOGIC_OP)
773 End If
774 End Sub
775
776 Function LogicOpCode() As GLenum
777 Dim code As GLenum
778 glGetFloatv(GL_COLOR_LOGIC_OP_MODE,code)
779 Return code
780 End Function
781 Sub LogicOpCode(code As GLenum)
782 glLogicOp(code)
783 End Sub
784
785 Function PointSmoothEnable() As GLboolean
786 Dim smooth As GLboolean
787 glGetBooleanv(GL_POINT_SMOOTH,VarPtr(smooth))
788 Return smooth
789 End Function
790 Sub PointSmoothEnable(enable As GLboolean)
791 If enable Then
792 glEnable(GL_POINT_SMOOTH)
793 Else
794 glDisable(GL_POINT_SMOOTH)
795 End If
796 End Sub
797
798 Function PolygonSmoothEnable() As GLboolean
799 Dim smooth As GLboolean
800 glGetBooleanv(GL_POLYGON_SMOOTH,VarPtr(smooth))
801 Return smooth
802 End Function
803 Sub PolygonSmoothEnable(enable As GLboolean)
804 If enable Then
805 glEnable(GL_POLYGON_SMOOTH)
806 Else
807 glDisable(GL_POLYGON_SMOOTH)
808 End If
809 End Sub
810
811 Function ReferenceAlpha() As GLclampf
812 Dim ref As GLclampf
813 glGetFloatv(GL_ALPHA_TEST_REF,VarPtr(ref))
814 Return ref
815 End Function
816 Sub ReferenceAlpha(ref As GLclampf)
817 Dim func As GLenum
818 glGetIntegerv(GL_ALPHA_TEST_FUNC,VarPtr(func))
819 glAlphaFunc(func,ref)
820 End Sub
821
822 Function ShadeModel() As GLenum
823 Dim mode As GLenum
824 glGetIntegerv(GL_SHADE_MODEL,VarPtr(mode))
825 Return mode
826 End Function
827 Sub ShadeModel(mode As GLenum)
828 glShadeModel(mode)
829 End Sub
830End Class
831
832
833Enum ColorType
834 RgbColor=0
835 RgbaColor=0
836 IndexColor
837End Enum
838
839Enum BufferType
840 SingleBuffer=0
841 DoubleBuffer
842End Enum
843
844Enum ClearBuffer
845 DepthBufferBit = &H00000100
846 AccumBufferBit = &H00000200
847 StencilBufferBit = &H00000400
848 ColorBufferBit = &H00004000
849End Enum
850
851Enum PrimitiveMode
852 Points = &H0000
853 Lines = &H0001
854 LineLoop = &H0002
855 LineStrip = &H0003
856 Triangles = &H0004
857 TriangleStrip = &H0005
858 TriangleFan = &H0006
859 Quads = &H0007
860 QuadStrip = &H0008
861 Polygon = &H0009
862End Enum
863
864Class RenderingContext
865Public /* Composiotion */
866 Material As Material
867 RenderState As RenderState
868 Transform As Transform
869 Lights[ELM(8)] As Light
870
871Public /* Constructor */
872 Sub RenderingContext()
873 Dim hrc As HGLRC
874 hrc=wglGetCurrentContext()
875 If hrc Then
876 wglMakeCurrent(NULL,NULL)
877 wglDeleteContext(hrc)
878 End If
879
880 Lights[0].Light(GL_LIGHT0)
881 Lights[1].Light(GL_LIGHT1)
882 Lights[2].Light(GL_LIGHT2)
883 Lights[3].Light(GL_LIGHT3)
884 Lights[4].Light(GL_LIGHT4)
885 Lights[5].Light(GL_LIGHT5)
886 Lights[6].Light(GL_LIGHT6)
887 Lights[7].Light(GL_LIGHT7)
888 End Sub
889 Sub RenderingContext(hdc As HDC)
890 RenderingContext()
891 End Sub
892 Sub RenderingContext(hdc As HDC, ByRef pfd As PIXELFORMATDESCRIPTOR)
893 RenderingContext()
894
895 Dim pf As Long
896 pf=ChoosePixelFormat(hdc,pfd)
897 If pf=0 Then
898 MessageBox(NULL,"Choose Pixel Format failed","error",MB_OK)
899 Exit Sub
900 End If
901 If SetPixelFormat(hdc,pf,pfd)=FALSE Then
902 MessageBox(NULL,"Set Pixel Format failed","error",MB_OK)
903 Exit Sub
904 End If
905
906 Dim hrc As HGLRC
907 hrc=wglCreateContext(hdc)
908 wglMakeCurrent(hdc,hrc)
909 End Sub
910 Sub RenderingContext(hdc As HDC, ByRef ctype As ColorType, ByRef btype As BufferType)
911 RenderingContext()
912
913 Dim pfd As PIXELFORMATDESCRIPTOR
914 pfd.nSize=SizeOf(PIXELFORMATDESCRIPTOR) As Word
915 pfd.nVersion=GL_VERSION_1_1
916 If btype=BufferType.DoubleBuffer As Long Then
917 pfd.dwFlags or=PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL or PFD_DOUBLEBUFFER
918 Else
919 pfd.dwFlags or=PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL
920 End If
921 If ctype=ColorType.RgbColor As Long Then
922 pfd.iPixelType=PFD_TYPE_RGBA
923 Else
924 pfd.iPixelType=PFD_TYPE_COLORINDEX
925 End If
926 pfd.cColorBits=24
927 pfd.cRedBits=0
928 pfd.cRedShift=0
929 pfd.cGreenBits=0
930 pfd.cGreenShift=0
931 pfd.cBlueBits=0
932 pfd.cBlueShift=0
933 pfd.cAlphaBits=0
934 pfd.cAlphaShift=0
935 pfd.cAccumBits=0
936 pfd.cAccumRedBits=0
937 pfd.cAccumGreenBits=0
938 pfd.cAccumBlueBits=0
939 pfd.cAccumAlphaBits=0
940 pfd.cDepthBits=32
941 pfd.cStencilBits=0
942 pfd.cAuxBuffers=0
943 pfd.iLayerType=PFD_MAIN_PLANE
944 pfd.bReserved=0
945 pfd.dwLayerMask=0
946 pfd.dwVisibleMask=0
947 pfd.dwDamageMask=0
948 RenderingContext(hdc,pfd)
949 End Sub
950
951Public /* Destructor */
952 Sub ~RenderingContext()
953 Dim hrc As HGLRC
954 hrc=wglGetCurrentContext()
955 wglMakeCurrent(NULL,NULL)
956 wglDeleteContext(hrc)
957 End Sub
958
959Public /* Method */
960 Sub Begin(mode As GLenum)
961 glBegin(mode)
962 End Sub
963 Sub Begin(mode As PrimitiveMode)
964 glBegin(mode)
965 End Sub
966 Sub Clear(mask As GLbitfield)
967 glClear(mask)
968 End Sub
969 Sub Clear(mask As ClearBuffer)
970 glClear(mask)
971 End Sub
972
973 Sub ClearAccum(red As GLfloat, green As GLfloat, blue As GLfloat, alpha As GLfloat)
974 glClearAccum(red, green, blue, alpha)
975 End Sub
976 Sub ClearAccum(color As Color4f)
977 glClearAccum(color.R, color.G, color.B, color.A)
978 End Sub
979 Sub ClearColor(red As GLclampf, green As GLclampf, blue As GLclampf, alpha As GLclampf)
980 glClearColor(red, green, blue, alpha)
981 End Sub
982 Sub ClearColor(color As Color4f)
983 glClearColor(color.R, color.G, color.B, color.A)
984 End Sub
985 Sub ClearDepth(depth As GLclampd)
986 glClearDepth(depth)
987 End Sub
988 Sub ClearIndex(c As GLfloat)
989 glClearIndex(c)
990 End Sub
991 Sub ClearStencil(s As GLint)
992 glClearStencil(s)
993 End Sub
994
995 Sub Color(red As GLdouble, green As GLdouble, blue As GLdouble)
996 glColor3d(red,green,blue)
997 End Sub
998 Sub Color(red As GLdouble, green As GLdouble, blue As GLdouble, alpha As GLdouble)
999 glColor4d(red,green,blue,alpha)
1000 End Sub
1001
1002 Sub Color(red As GLfloat, green As GLfloat, blue As GLfloat)
1003 glColor3f(red,green,blue)
1004 End Sub
1005 Sub Color(red As GLfloat, green As GLfloat, blue As GLfloat, alpha As GLfloat)
1006 glColor4f(red,green,blue,alpha)
1007 End Sub
1008
1009 Sub DrawPrimiteve()
1010 End Sub
1011
1012 Sub End()
1013 glEnd()
1014 End Sub
1015
1016 Sub Finish()
1017 glFinish()
1018 End Sub
1019 Sub Flush()
1020 glFlush()
1021 End Sub
1022
1023 Function GenerateTexures() As GLint
1024 glGenTextures()
1025 End Function
1026
1027 Sub MatrixMode(mode As GLenum)
1028 glMatrixMode(mode)
1029 End Sub
1030
1031 Sub Present()
1032 SwapBuffers(wglGetCurrentDC())
1033 End Sub
1034 Sub Present(hdc As HDC)
1035 SwapBuffers(hdc)
1036 End Sub
1037
1038 Sub PopMatrix()
1039 glPopMatrix()
1040 End Sub
1041
1042 Sub PushMatrix()
1043 glPushMatrix()
1044 End Sub
1045
1046 Sub Vertex(x As GLdouble, y As GLdouble)
1047 glVertex2d(x,y)
1048 End Sub
1049 Sub Vertex(x As GLdouble, y As GLdouble, z As GLdouble)
1050 glVertex3d(x,y,z)
1051 End Sub
1052 Sub Vertex(x As GLdouble, y As GLdouble, z As GLdouble, w As GLdouble)
1053 glVertex4d(x,y,z,w)
1054 End Sub
1055 Sub Vertex(x As GLfloat, y As GLfloat)
1056 glVertex2f(x,y)
1057 End Sub
1058 Sub Vertex(x As GLfloat, y As GLfloat, z As GLfloat)
1059 glVertex3f(x,y,z)
1060 End Sub
1061 Sub Vertex(x As GLfloat, y As GLfloat, z As GLfloat, w As GLfloat)
1062 glVertex4f(x,y,z,w)
1063 End Sub
1064
1065 Sub Viewport(x As GLint, y As GLint, width As GLsizei, height As GLsizei)
1066 glViewport(x, y, width, height)
1067 End Sub
1068End Class
1069
1070
1071
1072#endif
Note: See TracBrowser for help on using the repository browser.