source: Include/abgl.ab@ 37

Last change on this file since 37 was 37, checked in by NoWest, 17 years ago

OpenGL Class Library

File size: 23.1 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
213 Sub Light(num As GLenum)
214 Number=num
215 End Sub
216
217Public
218 Sub SetAmbient(amb As *GLdouble)
219 glLightdv(Number,GL_AMBIENT,amb)
220 End Sub
221 Sub SetAmbient(amb As *GLfloat)
222 glLightfv(Number,GL_AMBIENT,amb)
223 End Sub
224
225 Sub SetDiffuse(dif As *GLdouble)
226 glLightdv(Number,GL_DIFFUSE,dif)
227 End Sub
228 Sub SetDiffuse(dif As *GLfloat)
229 glLightfv(Number,GL_DIFFUSE,dif)
230 End Sub
231
232 Sub SetSpecular(spc As *GLdouble)
233 glLightdv(Number,GL_SPECULAR,spc)
234 End Sub
235 Sub SetSpecular(spc As *GLfloat)
236 glLightfv(Number,GL_SPECULAR,spc)
237 End Sub
238
239 Sub SetPosition(pos As *GLdouble)
240 glLightdv(Number,GL_POSITION,pos)
241 End Sub
242 Sub SetPosition(pos As *GLfloat)
243 glLightfv(Number,GL_POSITION,pos)
244 End Sub
245End Class
246
247Class Material
248Public
249 Sub Ambient(red As GLfloat, green As GLfloat, blue As GLfloat, alpha As GLfloat)
250 Dim face As GLenum
251 glGetIntegerv(GL_COLOR_MATERIAL_FACE,VarPtr(face))
252 Dim amb[3] As GLfloat
253 amb[0]=red
254 amb[1]=green
255 amb[2]=blue
256 amb[3]=alpha
257 glMaterialfv(face,GL_AMBIENT,amb)
258 End Sub
259 Sub Diffuse(red As GLfloat, green As GLfloat, blue As GLfloat, alpha As GLfloat)
260 Dim face As GLenum
261 glGetIntegerv(GL_COLOR_MATERIAL_FACE,VarPtr(face))
262 Dim dif[3] As GLfloat
263 dif[0]=red
264 dif[1]=green
265 dif[2]=blue
266 dif[3]=alpha
267 glMaterialfv(face,GL_DIFFUSE,dif)
268 End Sub
269 Sub Specular(red As GLfloat, green As GLfloat, blue As GLfloat, alpha As GLfloat)
270 Dim face As GLenum
271 glGetIntegerv(GL_COLOR_MATERIAL_FACE,VarPtr(face))
272 Dim spc[3] As GLfloat
273 spc[0]=red
274 spc[1]=green
275 spc[2]=blue
276 spc[3]=alpha
277 glMaterialfv(face,GL_SPECULAR,spc)
278 End Sub
279 Sub Shininess(shin As GLfloat)
280 Dim face As GLenum
281 glGetIntegerv(GL_COLOR_MATERIAL_FACE,VarPtr(face))
282 glMaterialf(face,GL_SHININESS,shin)
283 End Sub
284 Sub Emission(red As GLfloat, green As GLfloat, blue As GLfloat, alpha As GLfloat)
285 Dim face As GLenum
286 glGetIntegerv(GL_COLOR_MATERIAL_FACE,VarPtr(face))
287 Dim ems[3] As GLfloat
288 ems[0]=red
289 ems[1]=green
290 ems[2]=blue
291 ems[3]=alpha
292 glMaterialfv(face,GL_EMISSION,ems)
293 End Sub
294End Class
295
296Class ModelView
297Public
298 Sub LoadIdentity()
299 Dim mode As GLenum
300 glGetIntegerv(GL_MATRIX_MODE,VarPtr(mode))
301 If mode<>GL_MODELVIEW Then glMatrixMode(GL_MODELVIEW)
302 glLoadIdentity()
303 If mode<>GL_MODELVIEW Then glMatrixMode(mode)
304 End Sub
305 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)
306 Dim mode As GLenum
307 glGetIntegerv(GL_MATRIX_MODE,VarPtr(mode))
308 If mode<>GL_MODELVIEW Then glMatrixMode(GL_MODELVIEW)
309 gluLookAt(eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz)
310 If mode<>GL_MODELVIEW Then glMatrixMode(mode)
311 End Sub
312 Sub RotateX(angle As GLdouble)
313 Dim mode As GLenum
314 glGetIntegerv(GL_MATRIX_MODE,VarPtr(mode))
315 If mode<>GL_MODELVIEW Then glMatrixMode(GL_MODELVIEW)
316 glRotated(angle, 1.0 As GLdouble, 0.0 As GLdouble, 0.0 As GLdouble)
317 If mode<>GL_MODELVIEW Then glMatrixMode(mode)
318 End Sub
319 Sub RotateX(angle As GLfloat)
320 Dim mode As GLenum
321 glGetIntegerv(GL_MATRIX_MODE,VarPtr(mode))
322 If mode<>GL_MODELVIEW Then glMatrixMode(GL_MODELVIEW)
323 glRotatef(angle, 1.0 As GLfloat, 0.0 As GLfloat, 0.0 As GLfloat)
324 If mode<>GL_MODELVIEW Then glMatrixMode(mode)
325 End Sub
326 Sub RotateY(angle As GLdouble)
327 Dim mode As GLenum
328 glGetIntegerv(GL_MATRIX_MODE,VarPtr(mode))
329 If mode<>GL_MODELVIEW Then glMatrixMode(GL_MODELVIEW)
330 glRotated(angle, 0.0 As GLdouble, 1.0 As GLdouble, 0.0 As GLdouble)
331 If mode<>GL_MODELVIEW Then glMatrixMode(mode)
332 End Sub
333 Sub RotateY(angle As GLfloat)
334 Dim mode As GLenum
335 glGetIntegerv(GL_MATRIX_MODE,VarPtr(mode))
336 If mode<>GL_MODELVIEW Then glMatrixMode(GL_MODELVIEW)
337 glRotatef(angle, 0.0 As GLfloat, 1.0 As GLfloat, 0.0 As GLfloat)
338 If mode<>GL_MODELVIEW Then glMatrixMode(mode)
339 End Sub
340 Sub RotateZ(angle As GLdouble)
341 Dim mode As GLenum
342 glGetIntegerv(GL_MATRIX_MODE,VarPtr(mode))
343 If mode<>GL_MODELVIEW Then glMatrixMode(GL_MODELVIEW)
344 glRotated(angle, 0.0 As GLdouble, 0.0 As GLdouble, 1.0 As GLdouble)
345 If mode<>GL_MODELVIEW Then glMatrixMode(mode)
346 End Sub
347 Sub RotateZ(angle As GLfloat)
348 Dim mode As GLenum
349 glGetIntegerv(GL_MATRIX_MODE,VarPtr(mode))
350 If mode<>GL_MODELVIEW Then glMatrixMode(GL_MODELVIEW)
351 glRotatef(angle, 0.0 As GLfloat, 0.0 As GLfloat, 1.0 As GLfloat)
352 If mode<>GL_MODELVIEW Then glMatrixMode(mode)
353 End Sub
354 Sub Scale(x As GLdouble, y As GLdouble, z As GLdouble)
355 Dim mode As GLenum
356 glGetIntegerv(GL_MATRIX_MODE,VarPtr(mode))
357 If mode<>GL_MODELVIEW Then glMatrixMode(GL_MODELVIEW)
358 glScaled(x, y, z)
359 If mode<>GL_MODELVIEW Then glMatrixMode(mode)
360 End Sub
361 Sub Scale(x As GLfloat, y As GLfloat, z As GLfloat)
362 Dim mode As GLenum
363 glGetIntegerv(GL_MATRIX_MODE,VarPtr(mode))
364 If mode<>GL_MODELVIEW Then glMatrixMode(GL_MODELVIEW)
365 glScalef(x, y, z)
366 If mode<>GL_MODELVIEW Then glMatrixMode(mode)
367 End Sub
368 Sub Translate(x As GLdouble, y As GLdouble, z As GLdouble)
369 Dim mode As GLenum
370 glGetIntegerv(GL_MATRIX_MODE,VarPtr(mode))
371 If mode<>GL_MODELVIEW Then glMatrixMode(GL_MODELVIEW)
372 glTranslated(x, y, z)
373 If mode<>GL_MODELVIEW Then glMatrixMode(mode)
374 End Sub
375 Sub Translate(x As GLfloat, y As GLfloat, z As GLfloat)
376 Dim mode As GLenum
377 glGetIntegerv(GL_MATRIX_MODE,VarPtr(mode))
378 If mode<>GL_MODELVIEW Then glMatrixMode(GL_MODELVIEW)
379 glTranslatef(x, y, z)
380 If mode<>GL_MODELVIEW Then glMatrixMode(mode)
381 End Sub
382End Class
383
384Class Projection
385Public
386 Sub LoadIdentity()
387 Dim mode As GLenum
388 glGetIntegerv(GL_MATRIX_MODE,VarPtr(mode))
389 If mode<>GL_PROJECTION Then glMatrixMode(GL_PROJECTION)
390 glLoadIdentity()
391 If mode<>GL_PROJECTION Then glMatrixMode(mode)
392 End Sub
393 Sub Ortho2D(left As GLdouble, right As GLdouble, bottom As GLdouble, top As GLdouble)
394 Dim mode As GLenum
395 glGetIntegerv(GL_MATRIX_MODE,VarPtr(mode))
396 If mode<>GL_PROJECTION Then glMatrixMode(GL_PROJECTION)
397 gluOrtho2D(left, right, bottom, top)
398 If mode<>GL_PROJECTION Then glMatrixMode(mode)
399 End Sub
400 Sub Ortho3D(left As GLdouble, right As GLdouble, bottom As GLdouble, top As GLdouble, zNear As GLdouble, zFar As GLdouble)
401 Dim mode As GLenum
402 glGetIntegerv(GL_MATRIX_MODE,VarPtr(mode))
403 If mode<>GL_PROJECTION Then glMatrixMode(GL_PROJECTION)
404 glOrtho(left, right, bottom, top, zNear, zFar)
405 If mode<>GL_PROJECTION Then glMatrixMode(mode)
406 End Sub
407 Sub Frustum(left As GLdouble, right As GLdouble, bottom As GLdouble, top As GLdouble, zNear As GLdouble, zFar As GLdouble)
408 Dim mode As GLenum
409 glGetIntegerv(GL_MATRIX_MODE,VarPtr(mode))
410 If mode<>GL_PROJECTION Then glMatrixMode(GL_PROJECTION)
411 glFrustum(left, right, bottom, top, zNear, zFar)
412 If mode<>GL_PROJECTION Then glMatrixMode(mode)
413 End Sub
414 Sub Perspective(fovy As GLdouble, aspect As GLdouble, zNear As GLdouble, zFar As GLdouble)
415 Dim mode As GLenum
416 glGetIntegerv(GL_MATRIX_MODE,VarPtr(mode))
417 If mode<>GL_PROJECTION Then glMatrixMode(GL_PROJECTION)
418 gluPerspective(fovy, aspect, zNear, zFar)
419 If mode<>GL_PROJECTION Then glMatrixMode(mode)
420 End Sub
421End Class
422
423Class Transform
424Public
425 Projection As Projection
426 ModelView As ModelView
427End Class
428
429Class LightModel
430Public
431/* Function Ambient () As GLenum
432 Dim amb As GLenum
433 glGetFloatv(GL_LIGHT_MODEL_AMBIENT,VarPtr(amb))
434 Return func
435 End Function*/
436 Sub Ambient(amb As *GLfloat)
437 glLightModelfv(GL_LIGHT_MODEL_AMBIENT,VarPtr(amb))
438 End Sub
439
440 Function LocalView() As GLboolean
441 Dim local As GLboolean
442 glGetBooleanv(GL_LIGHT_MODEL_LOCAL_VIEW,VarPtr(local))
443 Return local
444 End Function
445 Sub LocalView(enable As GLboolean)
446 If enable Then
447 glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEW,GL_TRUE)
448 Else
449 glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEW,GL_FALSE)
450 End If
451 End Sub
452
453 Function TwoSide() As GLboolean
454 Dim local As GLboolean
455 glGetBooleanv(GL_LIGHT_MODEL_TWO_SIDE,VarPtr(local))
456 Return local
457 End Function
458 Sub TwoSide(enable As GLboolean)
459 If enable Then
460 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE)
461 Else
462 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_FALSE)
463 End If
464 End Sub
465End Class
466
467Class RenderState
468Public /* Composiotion */
469 LightModel As LightModel
470
471Public
472 Function AlphaTestEnable() As GLboolean
473 Dim alpha As GLboolean
474 glGetBooleanv(GL_ALPHA_TEST,VarPtr(alpha))
475 Return alpha
476 End Function
477 Sub AlphaTestEnable(enable As GLboolean)
478 If enable Then
479 glEnable(GL_ALPHA_TEST)
480 Else
481 glDisable(GL_ALPHA_TEST)
482 End If
483 End Sub
484
485 Function AlphaFunction() As GLenum
486 Dim func As GLenum
487 glGetIntegerv(GL_ALPHA_TEST_FUNC,VarPtr(func))
488 Return func
489 End Function
490 Sub AlphaFunction(func As GLenum)
491 Dim ref As GLclampf
492 glGetFloatv(GL_ALPHA_TEST_REF,VarPtr(ref))
493 glAlphaFunc(func,ref)
494 End Sub
495
496 Function BlendEnable() As GLboolean
497 Dim blend As GLboolean
498 glGetBooleanv(GL_BLEND,VarPtr(blend))
499 Return blend
500 End Function
501 Sub BlendEnable(enable As GLboolean)
502 If enable Then
503 glEnable(GL_BLEND)
504 Else
505 glDisable(GL_BLEND)
506 End If
507 End Sub
508
509 Function BlendDestinationFactor() As GLenum
510 Dim dfactor As GLenum
511 glGetIntegerv(GL_BLEND_DST,VarPtr(dfactor))
512 Return dfactor
513 End Function
514 Sub BlendDestinationFactor(dfactor As GLenum)
515 Dim sfactor As GLenum
516 glGetIntegerv(GL_BLEND_SRC,VarPtr(sfactor))
517 glBlendFunc(sfactor,dfactor)
518 End Sub
519
520 Function BlendSourceFactor() As GLenum
521 Dim sfactor As GLenum
522 glGetIntegerv(GL_BLEND_SRC,VarPtr(sfactor))
523 Return sfactor
524 End Function
525 Sub BlendSourceFactor(sfactor As GLenum)
526 Dim dfactor As GLenum
527 glGetIntegerv(GL_BLEND_DST,VarPtr(dfactor))
528 glBlendFunc(sfactor,dfactor)
529 End Sub
530
531 Function CullFaceEnable() As GLboolean
532 Dim cull As GLboolean
533 glGetBooleanv(GL_CULL_FACE,VarPtr(cull))
534 Return cull
535 End Function
536 Sub CullFaceEnable(enable As GLboolean)
537 If enable Then
538 glEnable(GL_CULL_FACE)
539 Else
540 glDisable(GL_CULL_FACE)
541 End If
542 End Sub
543
544 Function CullFaceMode () As GLenum
545 Dim mode As GLenum
546 glGetIntegerv(GL_CULL_FACE_MODE,VarPtr(mode))
547 Return mode
548 End Function
549 Sub CullFaceMode(mode As GLenum)
550 glCullFace(mode)
551 End Sub
552
553 Function DepthTestEnable () As GLboolean
554 Dim depth As GLboolean
555 glGetBooleanv(GL_DEPTH_TEST,VarPtr(depth))
556 Return depth
557 End Function
558 Sub DepthTestEnable(enable As GLboolean)
559 If enable Then
560 glEnable(GL_DEPTH_TEST)
561 Else
562 glDisable(GL_DEPTH_TEST)
563 End If
564 End Sub
565
566 Function DepthFunction () As GLenum
567 Dim func As GLenum
568 glGetIntegerv(GL_DEPTH_FUNC,VarPtr(func))
569 Return func
570 End Function
571 Sub DepthFunction(func As GLenum)
572 glDepthFunc(func)
573 End Sub
574
575 Function DepthBufferWritable() As GLboolean
576 Dim writable As GLboolean
577 glGetBooleanv(GL_DEPTH_WRITEMASK,VarPtr(writable))
578 Return writable
579 End Function
580 Sub DepthBufferWritable(enable As GLboolean)
581 If enable Then
582 glDepthMask(GL_DEPTH_WRITEMASK)
583 Else
584 glDepthMask(GL_DEPTH_WRITEMASK)
585 End If
586 End Sub
587
588 Function DitherEnable() As GLboolean
589 Dim dither As GLboolean
590 glGetBooleanv(GL_DITHER,VarPtr(dither))
591 Return dither
592 End Function
593 Sub DitherEnable(enable As GLboolean)
594 If enable Then
595 glEnable(GL_DITHER)
596 Else
597 glDisable(GL_DITHER)
598 End If
599 End Sub
600
601 Function FogEnable () As GLboolean
602 Dim fog As GLboolean
603 glGetBooleanv(GL_FOG,VarPtr(fog))
604 Return fog
605 End Function
606 Sub FogEnable(enable As GLboolean)
607 If enable Then
608 glEnable(GL_FOG)
609 Else
610 glDisable(GL_FOG)
611 End If
612 End Sub
613
614 Function FogMode() As GLenum
615 Dim mode As GLenum
616 glGetIntegerv(GL_FOG_MODE,VarPtr(mode))
617 Return mode
618 End Function
619 Sub FogMode(mode As GLenum)
620 glFogi(GL_FOG_MODE,mode)
621 End Sub
622
623 Function FogColor() As *GLfloat
624 glGetFloatv(GL_FOG_COLOR,FogColor)
625 Return FogColor
626 End Function
627 Sub FogColor(fcolor As *GLfloat)
628 glFogfv(GL_FOG_COLOR,fcolor)
629 End Sub
630
631 Function FogDensity() As GLfloat
632 Dim density As GLfloat
633 glGetFloatv(GL_FOG_DENSITY,density)
634 Return density
635 End Function
636 Sub FogDensity(density As GLfloat)
637 glFogf(GL_FOG_DENSITY,density)
638 End Sub
639
640 Function FogStart() As GLfloat
641 Dim fstrat As GLfloat
642 glGetFloatv(GL_FOG_START,fstrat)
643 Return fstrat
644 End Function
645 Sub FogStart(fstrat As GLfloat)
646 glFogf(GL_FOG_START,fstrat)
647 End Sub
648
649 Function FogEnd() As GLfloat
650 Dim fend As GLfloat
651 glGetFloatv(GL_FOG_END,fend)
652 Return fend
653 End Function
654 Sub FogEnd(fend As GLfloat)
655 glFogf(GL_FOG_END,fend)
656 End Sub
657
658 Function Lighting() As GLboolean
659 Dim lighting As GLboolean
660 glGetBooleanv(GL_LIGHTING,VarPtr(lighting))
661 Return lighting
662 End Function
663 Sub Lighting(enable As GLboolean)
664 If enable Then
665 glEnable(GL_LIGHTING)
666 Else
667 glDisable(GL_LIGHTING)
668 End If
669 End Sub
670
671 Function LineSmoothEnable() As GLboolean
672 Dim smooth As GLboolean
673 glGetBooleanv(GL_LINE_SMOOTH,VarPtr(smooth))
674 Return smooth
675 End Function
676 Sub LineSmoothEnable(enable As GLboolean)
677 If enable Then
678 glEnable(GL_LINE_SMOOTH)
679 Else
680 glDisable(GL_LINE_SMOOTH)
681 End If
682 End Sub
683
684 Function LogicOpEnable() As GLboolean
685 Dim logic As GLboolean
686 glGetBooleanv(GL_COLOR_LOGIC_OP,VarPtr(logic))
687 Return logic
688 End Function
689 Sub LogicOpEnable(enable As GLboolean)
690 If enable Then
691 glEnable(GL_COLOR_LOGIC_OP)
692 Else
693 glDisable(GL_COLOR_LOGIC_OP)
694 End If
695 End Sub
696
697 Function LogicOpCode() As GLenum
698 Dim code As GLenum
699 glGetFloatv(GL_COLOR_LOGIC_OP_MODE,code)
700 Return code
701 End Function
702 Sub LogicOpCode(code As GLenum)
703 glLogicOp(code)
704 End Sub
705
706 Function PointSmoothEnable() As GLboolean
707 Dim smooth As GLboolean
708 glGetBooleanv(GL_POINT_SMOOTH,VarPtr(smooth))
709 Return smooth
710 End Function
711 Sub PointSmoothEnable(enable As GLboolean)
712 If enable Then
713 glEnable(GL_POINT_SMOOTH)
714 Else
715 glDisable(GL_POINT_SMOOTH)
716 End If
717 End Sub
718
719 Function PolygonSmoothEnable() As GLboolean
720 Dim smooth As GLboolean
721 glGetBooleanv(GL_POLYGON_SMOOTH,VarPtr(smooth))
722 Return smooth
723 End Function
724 Sub PolygonSmoothEnable(enable As GLboolean)
725 If enable Then
726 glEnable(GL_POLYGON_SMOOTH)
727 Else
728 glDisable(GL_POLYGON_SMOOTH)
729 End If
730 End Sub
731
732 Function ReferenceAlpha() As GLclampf
733 Dim ref As GLclampf
734 glGetFloatv(GL_ALPHA_TEST_REF,VarPtr(ref))
735 Return ref
736 End Function
737 Sub ReferenceAlpha(ref As GLclampf)
738 Dim func As GLenum
739 glGetIntegerv(GL_ALPHA_TEST_FUNC,VarPtr(func))
740 glAlphaFunc(func,ref)
741 End Sub
742
743 Function ShadeModel() As GLenum
744 Dim mode As GLenum
745 glGetIntegerv(GL_SHADE_MODEL,VarPtr(mode))
746 Return mode
747 End Function
748 Sub ShadeModel(mode As GLenum)
749 glShadeModel(mode)
750 End Sub
751End Class
752
753
754Enum ColorType
755 RgbColor=0
756 RgbaColor=0
757 IndexColor
758End Enum
759
760Enum BufferType
761 SingleBuffer=0
762 DoubleBuffer
763End Enum
764
765Enum ClearBuffer
766 DepthBufferBit = &H00000100
767 AccumBufferBit = &H00000200
768 StencilBufferBit = &H00000400
769 ColorBufferBit = &H00004000
770End Enum
771
772Enum PrimitiveMode
773 Points = &H0000
774 Lines = &H0001
775 LineLoop = &H0002
776 LineStrip = &H0003
777 Triangles = &H0004
778 TriangleStrip = &H0005
779 TriangleFan = &H0006
780 Quads = &H0007
781 QuadStrip = &H0008
782 Polygon = &H0009
783End Enum
784
785Class RenderingContext
786Public /* Composiotion */
787 Material As Material
788 RenderState As RenderState
789 Transform As Transform
790 Lights[ELM(8)] As Light
791
792Public /* Constructor */
793 Sub RenderingContext()
794 Dim hrc As HGLRC
795 hrc=wglGetCurrentContext()
796 If hrc Then
797 wglMakeCurrent(NULL,NULL)
798 wglDeleteContext(hrc)
799 End If
800
801 Lights[0].Light(GL_LIGHT0)
802 Lights[1].Light(GL_LIGHT1)
803 Lights[2].Light(GL_LIGHT2)
804 Lights[3].Light(GL_LIGHT3)
805 Lights[4].Light(GL_LIGHT4)
806 Lights[5].Light(GL_LIGHT5)
807 Lights[6].Light(GL_LIGHT6)
808 Lights[7].Light(GL_LIGHT7)
809 End Sub
810 Sub RenderingContext(hdc As HDC)
811 RenderingContext()
812 End Sub
813 Sub RenderingContext(hdc As HDC, ByRef pfd As PIXELFORMATDESCRIPTOR)
814 RenderingContext()
815
816 Dim pf As Long
817 pf=ChoosePixelFormat(hdc,pfd)
818 If pf=0 Then
819 MessageBox(NULL,"Choose Pixel Format failed","error",MB_OK)
820 Exit Sub
821 End If
822 If SetPixelFormat(hdc,pf,pfd)=FALSE Then
823 MessageBox(NULL,"Set Pixel Format failed","error",MB_OK)
824 Exit Sub
825 End If
826
827 Dim hrc As HGLRC
828 hrc=wglCreateContext(hdc)
829 wglMakeCurrent(hdc,hrc)
830 End Sub
831 Sub RenderingContext(hdc As HDC, ByRef ctype As ColorType, ByRef btype As BufferType)
832 RenderingContext()
833
834 Dim pfd As PIXELFORMATDESCRIPTOR
835 pfd.nSize=SizeOf(PIXELFORMATDESCRIPTOR) As Word
836 pfd.nVersion=GL_VERSION_1_1
837 If btype=BufferType.DoubleBuffer As Long Then
838 pfd.dwFlags or=PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL or PFD_DOUBLEBUFFER
839 Else
840 pfd.dwFlags or=PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL
841 End If
842 If ctype=ColorType.RgbColor As Long Then
843 pfd.iPixelType=PFD_TYPE_RGBA
844 Else
845 pfd.iPixelType=PFD_TYPE_COLORINDEX
846 End If
847 pfd.cColorBits=24
848 pfd.cRedBits=0
849 pfd.cRedShift=0
850 pfd.cGreenBits=0
851 pfd.cGreenShift=0
852 pfd.cBlueBits=0
853 pfd.cBlueShift=0
854 pfd.cAlphaBits=0
855 pfd.cAlphaShift=0
856 pfd.cAccumBits=0
857 pfd.cAccumRedBits=0
858 pfd.cAccumGreenBits=0
859 pfd.cAccumBlueBits=0
860 pfd.cAccumAlphaBits=0
861 pfd.cDepthBits=32
862 pfd.cStencilBits=0
863 pfd.cAuxBuffers=0
864 pfd.iLayerType=PFD_MAIN_PLANE
865 pfd.bReserved=0
866 pfd.dwLayerMask=0
867 pfd.dwVisibleMask=0
868 pfd.dwDamageMask=0
869 RenderingContext(hdc,pfd)
870 End Sub
871
872Public /* Destructor */
873 Sub ~RenderingContext()
874 Dim hrc As HGLRC
875 hrc=wglGetCurrentContext()
876 wglMakeCurrent(NULL,NULL)
877 wglDeleteContext(hrc)
878 End Sub
879
880Public /* Method */
881 Sub Begin(mode As GLenum)
882 glBegin(mode)
883 End Sub
884 Sub Begin(mode As PrimitiveMode)
885 glBegin(mode)
886 End Sub
887 Sub Clear(mask As GLbitfield)
888 glClear(mask)
889 End Sub
890 Sub Clear(mask As ClearBuffer)
891 glClear(mask)
892 End Sub
893
894 Sub ClearAccum(red As GLfloat, green As GLfloat, blue As GLfloat, alpha As GLfloat)
895 glClearAccum(red, green, blue, alpha)
896 End Sub
897 Sub ClearAccum(color As Color4f)
898 glClearAccum(color.R, color.G, color.B, color.A)
899 End Sub
900 Sub ClearColor(red As GLclampf, green As GLclampf, blue As GLclampf, alpha As GLclampf)
901 glClearColor(red, green, blue, alpha)
902 End Sub
903 Sub ClearColor(color As Color4f)
904 glClearColor(color.R, color.G, color.B, color.A)
905 End Sub
906 Sub ClearDepth(depth As GLclampd)
907 glClearDepth(depth)
908 End Sub
909 Sub ClearIndex(c As GLfloat)
910 glClearIndex(c)
911 End Sub
912 Sub ClearStencil(s As GLint)
913 glClearStencil(s)
914 End Sub
915
916 Sub Color(red As GLdouble, green As GLdouble, blue As GLdouble)
917 glColor3d(red,green,blue)
918 End Sub
919 Sub Color(red As GLdouble, green As GLdouble, blue As GLdouble, alpha As GLdouble)
920 glColor4d(red,green,blue,alpha)
921 End Sub
922
923 Sub Color(red As GLfloat, green As GLfloat, blue As GLfloat)
924 glColor3f(red,green,blue)
925 End Sub
926 Sub Color(red As GLfloat, green As GLfloat, blue As GLfloat, alpha As GLfloat)
927 glColor4f(red,green,blue,alpha)
928 End Sub
929
930 Sub DrawPrimiteve()
931 End Sub
932
933 Sub End()
934 glEnd()
935 End Sub
936
937 Sub Finish()
938 glFinish()
939 End Sub
940 Sub Flush()
941 glFlush()
942 End Sub
943
944 Function GenerateTexures() As GLint
945 glGenTextures()
946 End Function
947
948 Sub MatrixMode(mode As GLenum)
949 glMatrixMode(mode)
950 End Sub
951
952 Sub Present()
953 SwapBuffers(wglGetCurrentDC())
954 End Sub
955 Sub Present(hdc As HDC)
956 SwapBuffers(hdc)
957 End Sub
958
959 Sub PopMatrix()
960 glPopMatrix()
961 End Sub
962
963 Sub PushMatrix()
964 glPushMatrix()
965 End Sub
966
967 Sub Vertex(x As GLdouble, y As GLdouble)
968 glVertex2d(x,y)
969 End Sub
970 Sub Vertex(x As GLdouble, y As GLdouble, z As GLdouble)
971 glVertex3d(x,y,z)
972 End Sub
973 Sub Vertex(x As GLdouble, y As GLdouble, z As GLdouble, w As GLdouble)
974 glVertex4d(x,y,z,w)
975 End Sub
976 Sub Vertex(x As GLfloat, y As GLfloat)
977 glVertex2f(x,y)
978 End Sub
979 Sub Vertex(x As GLfloat, y As GLfloat, z As GLfloat)
980 glVertex3f(x,y,z)
981 End Sub
982 Sub Vertex(x As GLfloat, y As GLfloat, z As GLfloat, w As GLfloat)
983 glVertex4f(x,y,z,w)
984 End Sub
985
986 Sub Viewport(x As GLint, y As GLint, width As GLsizei, height As GLsizei)
987 glViewport(x, y, width, height)
988 End Sub
989End Class
990
991
992
993#endif
Note: See TracBrowser for help on using the repository browser.