Dark Bit Factory & Gravity
PROGRAMMING => General coding questions => Topic started by: WidowMaker [retired] on April 09, 2008
-
This code runs really well on my system, I attached a screenshot I took on my system.
The problem I have is that it looks totally different on some other systems.
On some systems the image is really really dark, almost to the point where you can't see the display :(
I can't work it out, here is the source code in the hope that somebody can see what I did wrong;
'-------------------------------------------------------------------------------
'
' 0X0007 Intro by Electric Druggies.
'
'-------------------------------------------------------------------------------
'-------------------------------------------------------------------------------
' Includes
'-------------------------------------------------------------------------------
#INCLUDE "GL/gl.bi"
#INCLUDE "GL/glu.bi"
#INCLUDE "windows.bi"
'-------------------------------------------------------------------------------
' VARIABLES FOR OPENGL;
'-------------------------------------------------------------------------------
OPTION STATIC
OPTION EXPLICIT
DIM SHARED AS BYTE W_FULLSCREEN =0 : ' 1 = FULLSCREEN
DIM SHARED AS INTEGER W_XO =0 : ' X pos of window
DIM SHARED AS INTEGER W_YO =0 : ' Y pos of window
DIM SHARED AS INTEGER W_XW =800 : ' Width.
DIM SHARED AS INTEGER W_YH =600 : ' Height.
DIM SHARED pfd as PIXELFORMATDESCRIPTOR
DIM SHARED hdc as hDC
DECLARE SUB InitOGL()
DECLARE SUB BATTENBURG()
DECLARE SUB DRAWGLENZECROSS()
DECLARE SUB DRAWGLENZE(BYVAL XO AS DOUBLE,BYVAL YO AS DOUBLE,BYVAL ZO AS DOUBLE)
DIM SHARED LightAmbient(0 to 3) as single => {.2, .2, .2,0.2}
DIM SHARED Lightdiffuse(0 to 3) as single => {1.0, 1.0, 1.0,.2}
DIM SHARED FACE1(0 to 3) AS SINGLE => {1.0, 0.25, 0.0,0.1} : '' RED FACES
DIM SHARED FACE2(0 to 3) AS SINGLE => {1.0, 1.0, 1.0,0.1} : '' WHITE FACES
' templates:
DIM SHARED FACE3(0 to 3) AS SINGLE => {.22, .22, .22,0.77}
DIM SHARED FACE4(0 to 3) AS SINGLE => {.18, .18, .18,0.76}
DIM SHARED FACE5(0 to 3) AS SINGLE => {.14, .14, .14,0.75}
DIM SHARED FACE6(0 to 3) AS SINGLE => {.10, .10, .10,0.74}
DIM SHARED FACE7(0 to 3) AS SINGLE => {.90, .90, .90,0.2}
DIM SHARED LightPosition(0 to 2) as single => {0.0, 0.0 ,60.0 }: '' Position is somewhat in front of screen
InitOGL()
'-------------------------------------------------------------------------------
' VARIABLES;
'-------------------------------------------------------------------------------
DIM SHARED AS DOUBLE XR,YR,ZR,INOUT,XM,YM ,xm2,ym2,zm2
'-------------------------------------------------------------------------------
' MAIN LOOP;
'-------------------------------------------------------------------------------
GLENABLE GL_LIGHTING
WHILE((GetAsyncKeyState(VK_ESCAPE)<>-32767))
XR=XR+.07
YR=YR+.04
ZR=ZR+.02
inout=2.5+.49*sin(xr/14)
XM=.02*SIN(YR/13)
YM=.03*SIN(ZR/12)
XM2=(.02*SIN(YR/13))
YM2=(.03*SIN(ZR/12))
ZM2=(1.03*SIN(ZR/12))-9
GLLOADIDENTITY
GLCLEAR(GL_DEPTH_BUFFER_BIT + GL_COLOR_BUFFER_BIT )
GLPUSHMATRIX
DRAWGLENZECROSS()
BATTENBURG()
GLPOPMATRIX
SWAPBUFFERS(hDC)
SLEEP 1
WEND
SUB BATTENBURG()
GLPUSHMATRIX
GLENABLE GL_BLEND
glTranslatef(XM, YM, -.1)
glRotatef(0, 1.0, 0.0, 0.0)
glRotatef(0, 0.0, 1.0, 0.0)
glRotatef(ZR*2, 0.0, 0.0, 1.0)
GLBEGIN GL_QUADS
GLNORMAL3F 0,0,1
GLMATERIALFV (GL_FRONT,GL_AMBIENT_AND_DIFFUSE,@FACE3(0))
GLVERTEX3F -1,-1,0
GLVERTEX3F 0,-1,0
GLVERTEX3F 0, 0,0
GLVERTEX3F -1, 0,0
GLMATERIALFV (GL_FRONT,GL_AMBIENT_AND_DIFFUSE,@FACE5(0))
GLVERTEX3F 1, 1,0
GLVERTEX3F 0, 1,0
GLVERTEX3F 0, 0,0
GLVERTEX3F 1, 0,0
GLMATERIALFV (GL_FRONT,GL_AMBIENT_AND_DIFFUSE,@FACE4(0))
GLVERTEX3F 0,-1,0
GLVERTEX3F 1,-1,0
GLVERTEX3F 1, 0,0
GLVERTEX3F 0, 0,0
GLMATERIALFV (GL_FRONT,GL_AMBIENT_AND_DIFFUSE,@FACE6(0))
GLVERTEX3F 0, 1,0
GLVERTEX3F -1,1,0
GLVERTEX3F -1, 0,0
GLVERTEX3F 0, 0,0
GLEND
GLDISABLE GL_BLEND
GLPOPMATRIX
END SUB
SUB DRAWGLENZECROSS()
GLPUSHMATRIX
glTranslatef(XM2, YM2, ZM2)
glRotatef(XR*3, 1.0, 0.0, 0.0)
glRotatef(YR*2, 0.0, 1.0, 0.0)
glRotatef(ZR, 0.0, 0.0, 1.0)
GLCULLFACE (GL_FRONT)
DRAWGLENZE(INOUT,0,0)
DRAWGLENZE(-INOUT,0,0)
DRAWGLENZE(0,INOUT,0)
DRAWGLENZE(0,-INOUT,0)
DRAWGLENZE(0,0,INOUT)
DRAWGLENZE(0,0,-INOUT)
GLENABLE GL_BLEND
GLCULLFACE (GL_BACK)
DRAWGLENZE(INOUT,0,0)
DRAWGLENZE(-INOUT,0,0)
DRAWGLENZE(0,INOUT,0)
DRAWGLENZE(0,-INOUT,0)
DRAWGLENZE(0,0,INOUT)
DRAWGLENZE(0,0,-INOUT)
GLDISABLE GL_BLEND
GLPOPMATRIX
END SUB
'-------------------------------------------------------------------------------
' SET UP THE SCREEN;
'-------------------------------------------------------------------------------
SUB InitOGL()
pfd.cColorBits = 32
pfd.cDepthBits = 32
pfd.dwFlags = PFD_SUPPORT_OPENGL + PFD_DOUBLEBUFFER
IF W_FULLSCREEN=1 THEN hDC = GetDC(CreateWindow( "Edit", "0X0007", WS_POPUP+WS_VISIBLE+WS_MAXIMIZE, 0 , 0 , 0 , 0, 0, 0, 0, 0))
IF W_FULLSCREEN<>1 THEN hDC = GetDC(CreateWindow("Edit", "0X0007", WS_POPUP+WS_VISIBLE+WS_BORDER,W_XO, W_YO, W_XW , W_YH, 0, 0, 0, 0))
SetPixelFormat ( hDC, ChoosePixelFormat ( hDC, @pfd) , @pfd )
wglMakeCurrent ( hDC, wglCreateContext(hDC) )
ShowCursor(FALSE)
GLLOADIDENTITY
IF W_FULLSCREEN=1 THEN
W_XW=GetSystemMetrics(SM_CXSCREEN)
W_YH=GetSystemMetrics(SM_CYSCREEN)
END IF
GLVIEWPORT 0, 0, w_xw, w_yh '' Reset The Current Viewport
GLMATRIXMODE GL_PROJECTION '' Select The Projection Matrix
GLLOADIDENTITY
GLUPERSPECTIVE 105.0, W_XW / W_YH, .1, 100.0 '' Calculate The Aspect Ratio Of The Window
GLMATRIXMODE GL_MODELVIEW '' Select The Modelview Matrix
GLLOADIDENTITY '' Reset The Modelview Matrix
GLSHADEMODEL GL_flat '' Enable Smooth Shading
GLCLEARCOLOR 0.0, 0.0, 0.1,0
GLCLEARDEPTH 1.0 '' Depth Buffer Setup
GLENABLE GL_DEPTH_TEST '' Enables Depth Testing
GLDEPTHFUNC GL_LEQUAL '' The Type Of Depth Testing To Do
GLHINT GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST '' Really Nice Perspective Calculations
GLBLENDFUNC(GL_ONE_MINUS_DST_ALPHA,GL_SRC_ALPHA)
GLDISABLE GL_BLEND
GLENABLE GL_CULL_FACE
GLLOADIDENTITY
glEnable(GL_LIGHT0)
glLightfv( GL_LIGHT0, GL_DIFFUSE, @LightDiffuse(0))
glLightfv( GL_LIGHT0, GL_AMBIENT, @LightAmbient(0)) '' Load Light-Parameters Into GL_LIGHT1
glLightfv( GL_LIGHT0, GL_POSITION,@LightPosition(0))
glEnable(GL_LIGHTING)
GLENABLE GL_SMOOTH
end sub
SUB DRAWGLENZE(BYVAL XO AS DOUBLE,BYVAL YO AS DOUBLE,BYVAL ZO AS DOUBLE)
GLBEGIN GL_TRIANGLES
'---------------------------------------------------------------------------
' TOP FACE
'---------------------------------------------------------------------------
GLCOLOR3F 1.0,0.0,0.0
GLMATERIALFV (GL_FRONT,GL_AMBIENT_AND_DIFFUSE,@FACE1(0))
GLNORMAL3F 0, 1,0
GLVERTEX3F 1+XO, 1+YO, 1+ZO
GLVERTEX3F 0+XO, 1+YO, 0+ZO
GLVERTEX3F -1+XO, 1+YO, 1+ZO
GLVERTEX3F 0+XO, 1+YO, 0+ZO
GLVERTEX3F 1+XO, 1+YO, -1+ZO
GLVERTEX3F -1+XO, 1+YO, -1+ZO
GLMATERIALFV (GL_FRONT,GL_AMBIENT_AND_DIFFUSE,@FACE2(0))
GLVERTEX3F -1+XO,1+YO,1+ZO
GLVERTEX3F 0+XO,1+YO,0+ZO
GLVERTEX3F -1+XO,1+YO,-1+ZO
GLVERTEX3F 0+XO,1+YO,0+ZO
GLVERTEX3F 1+XO,1+YO,1+ZO
GLVERTEX3F 1+XO,1+YO,-1+ZO
'---------------------------------------------------------------------------
' BOTTOM FACE
'---------------------------------------------------------------------------
GLMATERIALFV (GL_FRONT,GL_AMBIENT_AND_DIFFUSE,@FACE1(0))
GLNORMAL3F 0,-1,0
GLVERTEX3F 0+XO, -1+YO, 0+ZO
GLVERTEX3F 1+XO, -1+YO, 1+ZO
GLVERTEX3F -1+XO, -1+YO, 1+ZO
GLVERTEX3F 0+XO, -1+YO, 0+ZO
GLVERTEX3F -1+XO, -1+YO, -1+ZO
GLVERTEX3F 1+XO, -1+YO, -1+ZO
GLMATERIALFV (GL_FRONT,GL_AMBIENT_AND_DIFFUSE,@FACE2(0))
GLVERTEX3F -1+XO,-1+YO,1+ZO
GLVERTEX3F -1+XO,-1+YO,-1+ZO
GLVERTEX3F 0+XO,-1+YO,0+ZO
GLVERTEX3F 1+XO,-1+YO,1+ZO
GLVERTEX3F 0+XO,-1+YO,0+ZO
GLVERTEX3F 1+XO,-1+YO,-1+ZO
'---------------------------------------------------------------------------
' LEFT FACE
'---------------------------------------------------------------------------
GLMATERIALFV (GL_FRONT,GL_AMBIENT_AND_DIFFUSE,@FACE2(0))
GLNORMAL3F -1, 0,0
GLVERTEX3F -1+XO,-1+YO, 1+ZO
GLVERTEX3F -1+XO, 1+YO, 1+ZO
GLVERTEX3F -1+XO, 0+YO, 0+ZO
GLVERTEX3F -1+XO,-1+YO,-1+ZO
GLVERTEX3F -1+XO, 0+YO, 0+ZO
GLVERTEX3F -1+XO, 1+YO,-1+ZO
GLMATERIALFV (GL_FRONT,GL_AMBIENT_AND_DIFFUSE,@FACE1(0))
GLVERTEX3F -1+XO, 0+YO, 0+ZO
GLVERTEX3F -1+XO, 1+YO, 1+ZO
GLVERTEX3F -1+XO, 1+YO,-1+ZO
GLVERTEX3F -1+XO, -1+YO,-1+ZO
GLVERTEX3F -1+XO, -1+YO, 1+ZO
GLVERTEX3F -1+XO, 0+YO, 0+ZO
'---------------------------------------------------------------------------
' RIGHT FACE
'---------------------------------------------------------------------------
GLMATERIALFV (GL_FRONT,GL_AMBIENT_AND_DIFFUSE,@FACE2(0))
GLNORMAL3F 1 ,0,0
GLVERTEX3F 1+XO, 0+YO, 0+ZO
GLVERTEX3F 1+XO, 1+YO, 1+ZO
GLVERTEX3F 1+XO,-1+YO, 1+ZO
GLVERTEX3F 1+XO, 1+YO,-1+ZO
GLVERTEX3F 1+XO, 0+YO, 0+ZO
GLVERTEX3F 1+XO,-1+YO,-1+ZO
GLMATERIALFV (GL_FRONT,GL_AMBIENT_AND_DIFFUSE,@FACE1(0))
GLVERTEX3F 1+XO, 1+YO,-1+ZO
GLVERTEX3F 1+XO, 1+YO, 1+ZO
GLVERTEX3F 1+XO, 0+YO, 0+ZO
GLVERTEX3F 1+XO, 0+YO, 0+ZO
GLVERTEX3F 1+XO, -1+YO, 1+ZO
GLVERTEX3F 1+XO, -1+YO,-1+ZO
'---------------------------------------------------------------------------
' FRONT FACE
'---------------------------------------------------------------------------
GLMATERIALFV (GL_FRONT,GL_AMBIENT_AND_DIFFUSE,@FACE1(0))
GLNORMAL3F 0,0,1
GLVERTEX3F -1+XO,-1+YO, 1+ZO
GLVERTEX3F 0+XO, 0+YO, 1+ZO
GLVERTEX3F -1+XO, 1+YO, 1+ZO
GLVERTEX3F 0+XO, 0+YO, 1+ZO
GLVERTEX3F 1+XO,-1+YO, 1+ZO
GLVERTEX3F 1+XO, 1+YO, 1+ZO
GLMATERIALFV (GL_FRONT,GL_AMBIENT_AND_DIFFUSE,@FACE2(0))
GLVERTEX3F -1+XO,-1+YO, 1+ZO
GLVERTEX3F 1+XO,-1+YO, 1+ZO
GLVERTEX3F 0+XO, 0+YO, 1+ZO
GLVERTEX3F 0+XO, 0+YO, 1+ZO
GLVERTEX3F 1+XO, 1+YO, 1+ZO
GLVERTEX3F -1+XO, 1+YO, 1+ZO
'---------------------------------------------------------------------------
' BACK FACE
'---------------------------------------------------------------------------
GLMATERIALFV (GL_FRONT,GL_AMBIENT_AND_DIFFUSE,@FACE1(0))
GLNORMAL3F 0, 0, -1
GLVERTEX3F 0+XO, 0+YO, -1+ZO
GLVERTEX3F -1+XO,-1+YO, -1+ZO
GLVERTEX3F -1+XO, 1+YO, -1+ZO
GLVERTEX3F 1+XO,-1+YO, -1+ZO
GLVERTEX3F 0+XO, 0+YO, -1+ZO
GLVERTEX3F 1+XO, 1+YO, -1+ZO
GLMATERIALFV (GL_FRONT,GL_AMBIENT_AND_DIFFUSE,@FACE2(0))
GLVERTEX3F 1+XO,-1+YO, -1+ZO
GLVERTEX3F -1+XO,-1+YO, -1+ZO
GLVERTEX3F 0+XO, 0+YO, -1+ZO
GLVERTEX3F 1+XO, 1+YO, -1+ZO
GLVERTEX3F 0+XO, 0+YO, -1+ZO
GLVERTEX3F -1+XO, 1+YO, -1+ZO
GLEND
END SUB
-
It looks as it does in your image on mine, Is the entire image dark on other systems?
Could be the gamma settings on the graphics card, I just set mine down a bit and while windows still looks ok if a little darker I can hardly see what you're rendering now.
-
I have an ati card, I dont even know how to change the gamma settings on my computer.
But as this intro will be run on a lot of computers it needs to run the same on as many of them as possible. Is there a way of adjusting this do you know please?
-
Go into the ATI control center, right click on desktop->properties->settings->advanced->control center
Go into the control center and go to the colour tab where you can adjust brightness and gamma, adjusting only brightness probably won't do it so you'll need to adjust the gamma setting.
-
Thanks.
-
Ok. I don't have the same options as you Stonemonkey.
I can't expect everyone to adjust the gamma settings on their card to run my intro though. I am wondering it is might be the blend mode I am using?
GLBLENDFUNC(GL_ONE_MINUS_DST_ALPHA,GL_SRC_ALPHA)
-
Is it the whole thing that's dark? if blend is disabled for the background and it's still darker then it's not the blending.
It is a bit of an odd blending function though, you're using the alpha value from the destination but not really specifying how anything is drawn to the alpha channel but I don't think that's the problem.
-
The person/s you have testing this, have they run other opengl progs without this problem?
-
GLBLENDFUNC(GL_ONE_MINUS_DST_ALPHA,GL_SRC_ALPHA)
I think this isn't right. DST_ALPHA is the alpha value from the framebuffer. Is that what you want? Effectively, that will always evaluate to 0, since you clear the alpha of the framebuffer to 1.0.
More traditional blending (and I don't know if this is what you're trying to do - no time to build your sample right now) is
GLBLENDFUNC(GL_ONE_MINUS_SRC_ALPHA,GL_SRC_ALPHA)
or
GLBLENDFUNC(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)
Jim
-
It seems that it was the blending that was at fault because I tried what you suggest there Jim and I got the results I wanted.
I haven't been able to test it on enough pcs yet for me to be confident with it.
I'll post a version of this in the board this weekend and hopefully see if it worked every where.
Thank you all for helping.
-
I would like to suggest you to initialize "pixel format descriptor" like this code below.
It won't solve your problem, but it's more safe and compatible to use this code.
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR)
pfd.nVersion = 1
pfd.dwFlags = PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL or PFD_DOUBLEBUFFER
pfd.dwLayerMask = PFD_MAIN_PLANE
pfd.iPixelType = PFD_TYPE_RGBA
pfd.cColorBits = 32
pfd.cDepthBits = 32
About lightening problem, it doesn't work here either, I got a dark image too. Why not get rid of using gl light? You really don't need light to make this effect just use "glColor3f" for background and "glColor4f" for transparent cubes.
-
I have Karma'd you all :)
Here's what I have now;
'-------------------------------------------------------------------------------
'
' 0X0007 Intro by Electric Druggies.
'
' thx stonemonkey, jim, rbz!
'-------------------------------------------------------------------------------
'-------------------------------------------------------------------------------
' Includes
'-------------------------------------------------------------------------------
#INCLUDE "GL/gl.bi"
#INCLUDE "GL/glu.bi"
#INCLUDE "windows.bi"
'-------------------------------------------------------------------------------
' VARIABLES FOR OPENGL;
'-------------------------------------------------------------------------------
OPTION STATIC
OPTION EXPLICIT
DIM SHARED AS BYTE W_FULLSCREEN =1 : ' 1 = FULLSCREEN
DIM SHARED AS INTEGER W_XO =0 : ' X pos of window
DIM SHARED AS INTEGER W_YO =0 : ' Y pos of window
DIM SHARED AS INTEGER W_XW =800 : ' Width.
DIM SHARED AS INTEGER W_YH =600 : ' Height.
DIM SHARED pfd as PIXELFORMATDESCRIPTOR
DIM SHARED hdc as hDC
DECLARE SUB InitOGL()
DECLARE SUB BATTENBURG()
DECLARE SUB BATTENBURG2()
DECLARE SUB VERT_BORDER()
DECLARE SUB DRAWGLENZECROSS()
DECLARE SUB DRAWGLENZE(BYVAL XO AS DOUBLE,BYVAL YO AS DOUBLE,BYVAL ZO AS DOUBLE)
DIM SHARED RED (0 to 3) AS SINGLE => {0.07, 0.07, 0.07,0.4}
DIM SHARED WHITE(0 to 3) AS SINGLE => {.22, .22, .22,0.1}
DIM SHARED CHECK (0 to 3) AS SINGLE => {0.22, 0.22, 0.12,1.0}
DIM SHARED BORDER(0 to 3) AS SINGLE => {0.93, 0.32, 0.42,0.78}
DIM SHARED LINES (0 to 3) AS SINGLE => {2.0, 2.0, 2.0,1}
InitOGL()
'-------------------------------------------------------------------------------
' VARIABLES;
'-------------------------------------------------------------------------------
DIM SHARED AS DOUBLE XR,YR,ZR,INOUT,XM,YM ,xm2,ym2,zm2,gadd1,gadd2
'-------------------------------------------------------------------------------
' MAIN LOOP;
'-------------------------------------------------------------------------------
WHILE((GetAsyncKeyState(VK_ESCAPE)<>-32767))
gadd1=gadd1+.001
gadd2=gadd2+.0013
XR=XR+.07
YR=YR+.04
ZR=ZR+.05
inout=2.5+.49*sin(xr/14)
XM=.02*SIN(YR/13)
YM=.03*SIN(ZR/12)
XM2=(7.02*SIN(YR/33))
YM2=(6.03*SIN(ZR/37))
ZM2=(2.03*SIN(ZR/42))-15
GLLOADIDENTITY
GLCLEAR(GL_DEPTH_BUFFER_BIT + GL_COLOR_BUFFER_BIT )
GLPUSHMATRIX
BATTENBURG()
BATTENBURG2()
DRAWGLENZECROSS()
VERT_BORDER()
GLPOPMATRIX
SWAPBUFFERS(hDC)
SLEEP 1
WEND
SUB VERT_BORDER()
GLPUSHMATRIX
GLENABLE GL_BLEND
GLTRANSLATEF (0,0,-1)
GLBEGIN GL_QUADS
GLCOLOR4F BORDER(0),BORDER(1),BORDER(2),BORDER(3)
GLVERTEX3F -1 ,-1, 0
GLVERTEX3F -.7,-1, 0
GLVERTEX3F -.7, 1, 0
GLVERTEX3F -1 , 1, 0
GLCOLOR4F BORDER(0),BORDER(1),BORDER(2),BORDER(3)
GLVERTEX3F 1 , 1, 0
GLVERTEX3F .7, 1, 0
GLVERTEX3F .7,-1, 0
GLVERTEX3F 1 ,-1, 0
GLEND
GLDISABLE GL_BLEND
GLCOLOR3F 1,1,1
GLBEGIN GL_LINES
GLCOLOR4F LINES(0),LINES(1),LINES(2),LINES(3)
GLVERTEX3F .7, 1,0
GLVERTEX3F .7,-1,0
GLVERTEX3F -.7, 1,0
GLVERTEX3F -.7,-1,0
GLEND
GLPOPMATRIX
END SUB
SUB BATTENBURG()
DIM AS INTEGER X,Y,YP,XP,XS,YS
GLPUSHMATRIX
'GLTRANSLATEF (0,0,-24.9-(YM2/3))
GLTRANSLATEF (0,-10,-24.9)
glRotatef(0, 1.0, 0.0, 0.0)
glRotatef(0, 0.0, 1.0, 0.0)
glRotatef(120*SIN(gadd1), 0.0, 0.0, 1.0)
XS=0
YS=0
FOR Y=-39 TO 39
XS=XS+1
IF XS>1 THEN XS=0
IF XS=0 THEN
X=-39
ELSE
X=-38
END IF
FOR XP=-39 TO 39 STEP 2
GLBEGIN GL_QUADS
GLCOLOR4F CHECK(0),CHECK(1),CHECK(2),CHECK(3)
GLVERTEX3F -1+X,-1+Y, 0
GLVERTEX3F X ,-1+Y, 0
GLVERTEX3F X , 0+Y, 0
GLVERTEX3F -1+X, 0+Y, 0
GLEND
X=X+2
NEXT
NEXT
GLPOPMATRIX
END SUB
SUB BATTENBURG2()
DIM AS INTEGER X,Y,YP,XP,XS,YS
GLPUSHMATRIX
GLTRANSLATEF (0,0,-22.9-(YM2/2))
glRotatef(0, 1.0, 0.0, 0.0)
glRotatef(0, 0.0, 1.0, 0.0)
glRotatef(160*SIN(gadd1), 0.0, 0.0, 1.0)
XS=0
YS=0
FOR Y=-39 TO 39
XS=XS+1
IF XS>1 THEN XS=0
IF XS=0 THEN
X=-39
ELSE
X=-38
END IF
FOR XP=-39 TO 39 STEP 2
GLBEGIN GL_QUADS
GLCOLOR4F CHECK(0),CHECK(1),CHECK(2),CHECK(3)
GLVERTEX3F -1+X,-1+Y, 0
GLVERTEX3F X ,-1+Y, 0
GLVERTEX3F X , 0+Y, 0
GLVERTEX3F -1+X, 0+Y, 0
GLEND
X=X+2
NEXT
NEXT
GLPOPMATRIX
END SUB
SUB DRAWGLENZECROSS()
GLPUSHMATRIX
glTranslatef(XM2, YM2, ZM2)
glRotatef(XR*3, 1.0, 0.0, 0.0)
glRotatef(YR*2, 0.0, 1.0, 0.0)
glRotatef(ZR, 0.0, 0.0, 1.0)
GLCULLFACE (GL_FRONT)
DRAWGLENZE(INOUT,0,0)
DRAWGLENZE(-INOUT,0,0)
DRAWGLENZE(0,INOUT,0)
DRAWGLENZE(0,-INOUT,0)
DRAWGLENZE(0,0,INOUT)
DRAWGLENZE(0,0,-INOUT)
GLENABLE GL_BLEND
GLCULLFACE (GL_BACK)
DRAWGLENZE(INOUT,0,0)
DRAWGLENZE(-INOUT,0,0)
DRAWGLENZE(0,INOUT,0)
DRAWGLENZE(0,-INOUT,0)
DRAWGLENZE(0,0,INOUT)
DRAWGLENZE(0,0,-INOUT)
GLDISABLE GL_BLEND
GLPOPMATRIX
END SUB
'-------------------------------------------------------------------------------
' SET UP THE SCREEN;
'-------------------------------------------------------------------------------
SUB InitOGL()
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR)
pfd.nVersion = 1
pfd.dwFlags = PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL or PFD_DOUBLEBUFFER
pfd.dwLayerMask = PFD_MAIN_PLANE
pfd.iPixelType = PFD_TYPE_RGBA
pfd.cColorBits = 32
pfd.cDepthBits = 32
IF W_FULLSCREEN=1 THEN hDC = GetDC(CreateWindow( "Edit", "0X0007", WS_POPUP+WS_VISIBLE+WS_MAXIMIZE, 0 , 0 , 0 , 0, 0, 0, 0, 0))
IF W_FULLSCREEN<>1 THEN hDC = GetDC(CreateWindow("Edit", "0X0007", WS_POPUP+WS_VISIBLE+WS_BORDER,W_XO, W_YO, W_XW , W_YH, 0, 0, 0, 0))
SetPixelFormat ( hDC, ChoosePixelFormat ( hDC, @pfd) , @pfd )
wglMakeCurrent ( hDC, wglCreateContext(hDC) )
ShowCursor(FALSE)
GLLOADIDENTITY
IF W_FULLSCREEN=1 THEN
W_XW=GetSystemMetrics(SM_CXSCREEN)
W_YH=GetSystemMetrics(SM_CYSCREEN)
END IF
GLVIEWPORT 0, 0, w_xw, w_yh '' Reset The Current Viewport
GLMATRIXMODE GL_PROJECTION '' Select The Projection Matrix
GLLOADIDENTITY
GLUPERSPECTIVE 70.0, W_XW / W_YH, .1, 100.0 '' Calculate The Aspect Ratio Of The Window
GLMATRIXMODE GL_MODELVIEW '' Select The Modelview Matrix
GLLOADIDENTITY '' Reset The Modelview Matrix
GLSHADEMODEL GL_FLAT '' Enable Smooth Shading
GLCLEARCOLOR .06, .03, 0.04,0
GLCLEARDEPTH 1.0 '' Depth Buffer Setup
GLENABLE GL_DEPTH_TEST '' Enables Depth Testing
GLDEPTHFUNC GL_LEQUAL '' The Type Of Depth Testing To Do
GLHINT GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST '' Really Nice Perspective Calculations
GLBLENDFUNC(GL_ONE_MINUS_SRC_ALPHA,GL_SRC_ALPHA)
GLDISABLE GL_BLEND
GLENABLE GL_CULL_FACE
GLLOADIDENTITY
glDISable(GL_LIGHTING)
GLENABLE GL_SMOOTH
GLENABLE GL_NORMALIZE
GLENABLE GL_FOG
GLHINT (GL_FOG_HINT,GL_NICEST)
GLFOGF (GL_FOG_START, 6.0)
GLFOGF (GL_FOG_END, 20.0)
GLFOGF (GL_FOG_DENSITY, 0.35)
GLFOGI (GL_FOG_MODE,GL_LINEAR)
end sub
SUB DRAWGLENZE(BYVAL XO AS DOUBLE,BYVAL YO AS DOUBLE,BYVAL ZO AS DOUBLE)
GLBEGIN GL_TRIANGLES
'---------------------------------------------------------------------------
' TOP FACE
'---------------------------------------------------------------------------
GLCOLOR4F RED(0),RED(1),RED(2),RED(3)
GLNORMAL3F 0, 1,0
GLVERTEX3F 1+XO, 1+YO, 1+ZO
GLVERTEX3F 0+XO, 1+YO, 0+ZO
GLVERTEX3F -1+XO, 1+YO, 1+ZO
GLVERTEX3F 0+XO, 1+YO, 0+ZO
GLVERTEX3F 1+XO, 1+YO, -1+ZO
GLVERTEX3F -1+XO, 1+YO, -1+ZO
GLCOLOR4F WHITE(0),WHITE(1),WHITE(2),WHITE(3)
GLNORMAL3F 0, 1,0
GLVERTEX3F -1+XO,1+YO,1+ZO
GLVERTEX3F 0+XO,1+YO,0+ZO
GLVERTEX3F -1+XO,1+YO,-1+ZO
GLVERTEX3F 0+XO,1+YO,0+ZO
GLVERTEX3F 1+XO,1+YO,1+ZO
GLVERTEX3F 1+XO,1+YO,-1+ZO
'---------------------------------------------------------------------------
' BOTTOM FACE
'---------------------------------------------------------------------------
GLCOLOR4F RED(0),RED(1),RED(2),RED(3)
GLNORMAL3F 0,-1,0
GLVERTEX3F 0+XO, -1+YO, 0+ZO
GLVERTEX3F 1+XO, -1+YO, 1+ZO
GLVERTEX3F -1+XO, -1+YO, 1+ZO
GLNORMAL3F 0,-1,0
GLVERTEX3F 0+XO, -1+YO, 0+ZO
GLVERTEX3F -1+XO, -1+YO, -1+ZO
GLVERTEX3F 1+XO, -1+YO, -1+ZO
GLCOLOR4F WHITE(0),WHITE(1),WHITE(2),WHITE(3)
GLNORMAL3F 0,-1,0
GLVERTEX3F -1+XO,-1+YO,1+ZO
GLVERTEX3F -1+XO,-1+YO,-1+ZO
GLVERTEX3F 0+XO,-1+YO,0+ZO
GLNORMAL3F 0,-1,0
GLVERTEX3F 1+XO,-1+YO,1+ZO
GLVERTEX3F 0+XO,-1+YO,0+ZO
GLVERTEX3F 1+XO,-1+YO,-1+ZO
'---------------------------------------------------------------------------
' LEFT FACE
'---------------------------------------------------------------------------
GLCOLOR4F WHITE(0),WHITE(1),WHITE(2),WHITE(3)
GLNORMAL3F -1, 0,0
GLVERTEX3F -1+XO,-1+YO, 1+ZO
GLVERTEX3F -1+XO, 1+YO, 1+ZO
GLVERTEX3F -1+XO, 0+YO, 0+ZO
GLNORMAL3F -1, 0,0
GLVERTEX3F -1+XO,-1+YO,-1+ZO
GLVERTEX3F -1+XO, 0+YO, 0+ZO
GLVERTEX3F -1+XO, 1+YO,-1+ZO
GLCOLOR4F RED(0),RED(1),RED(2),RED(3)
GLNORMAL3F -1, 0,0
GLVERTEX3F -1+XO, 0+YO, 0+ZO
GLVERTEX3F -1+XO, 1+YO, 1+ZO
GLVERTEX3F -1+XO, 1+YO,-1+ZO
GLNORMAL3F -1, 0,0
GLVERTEX3F -1+XO, -1+YO,-1+ZO
GLVERTEX3F -1+XO, -1+YO, 1+ZO
GLVERTEX3F -1+XO, 0+YO, 0+ZO
'---------------------------------------------------------------------------
' RIGHT FACE
'---------------------------------------------------------------------------
GLCOLOR4F WHITE(0),WHITE(1),WHITE(2),WHITE(3)
GLNORMAL3F 1 ,0,0
GLVERTEX3F 1+XO, 0+YO, 0+ZO
GLVERTEX3F 1+XO, 1+YO, 1+ZO
GLVERTEX3F 1+XO,-1+YO, 1+ZO
GLNORMAL3F 1 ,0,0
GLVERTEX3F 1+XO, 1+YO,-1+ZO
GLVERTEX3F 1+XO, 0+YO, 0+ZO
GLVERTEX3F 1+XO,-1+YO,-1+ZO
GLCOLOR4F RED(0),RED(1),RED(2),RED(3)
GLNORMAL3F 1 ,0,0
GLVERTEX3F 1+XO, 1+YO,-1+ZO
GLVERTEX3F 1+XO, 1+YO, 1+ZO
GLVERTEX3F 1+XO, 0+YO, 0+ZO
GLNORMAL3F 1 ,0,0
GLVERTEX3F 1+XO, 0+YO, 0+ZO
GLVERTEX3F 1+XO, -1+YO, 1+ZO
GLVERTEX3F 1+XO, -1+YO,-1+ZO
'---------------------------------------------------------------------------
' FRONT FACE
'---------------------------------------------------------------------------
GLCOLOR4F RED(0),RED(1),RED(2),RED(3)
GLNORMAL3F 0,0,1
GLVERTEX3F -1+XO,-1+YO, 1+ZO
GLVERTEX3F 0+XO, 0+YO, 1+ZO
GLVERTEX3F -1+XO, 1+YO, 1+ZO
GLNORMAL3F 0,0,1
GLVERTEX3F 0+XO, 0+YO, 1+ZO
GLVERTEX3F 1+XO,-1+YO, 1+ZO
GLVERTEX3F 1+XO, 1+YO, 1+ZO
GLCOLOR4F WHITE(0),WHITE(1),WHITE(2),WHITE(3)
GLNORMAL3F 0,0,1
GLVERTEX3F -1+XO,-1+YO, 1+ZO
GLVERTEX3F 1+XO,-1+YO, 1+ZO
GLVERTEX3F 0+XO, 0+YO, 1+ZO
GLNORMAL3F 0,0,1
GLVERTEX3F 0+XO, 0+YO, 1+ZO
GLVERTEX3F 1+XO, 1+YO, 1+ZO
GLVERTEX3F -1+XO, 1+YO, 1+ZO
'---------------------------------------------------------------------------
' BACK FACE
'---------------------------------------------------------------------------
GLCOLOR4F RED(0),RED(1),RED(2),RED(3)
GLNORMAL3F 0, 0, -1
GLVERTEX3F 0+XO, 0+YO, -1+ZO
GLVERTEX3F -1+XO,-1+YO, -1+ZO
GLVERTEX3F -1+XO, 1+YO, -1+ZO
GLNORMAL3F 0, 0, -1
GLVERTEX3F 1+XO,-1+YO, -1+ZO
GLVERTEX3F 0+XO, 0+YO, -1+ZO
GLVERTEX3F 1+XO, 1+YO, -1+ZO
GLCOLOR4F WHITE(0),WHITE(1),WHITE(2),WHITE(3)
GLNORMAL3F 0, 0, -1
GLVERTEX3F 1+XO,-1+YO, -1+ZO
GLVERTEX3F -1+XO,-1+YO, -1+ZO
GLVERTEX3F 0+XO, 0+YO, -1+ZO
GLNORMAL3F 0, 0, -1
GLVERTEX3F 1+XO, 1+YO, -1+ZO
GLVERTEX3F 0+XO, 0+YO, -1+ZO
GLVERTEX3F -1+XO, 1+YO, -1+ZO
GLEND
END SUB
-
Nice solution :)