Loving BMax more and more.I only have a few more days on the demo.Can not wait till i buy it.Here is some more tinkering.
Still learning OpenGL.
I have that BUZZ again.You can not beat the BUZZ.
all the best Mark.
'Example Code 'Simple Shadows in OpenGL 'Original Code :Do not know. 'Code:Nice_But_Dim SuperStrict Framework brl.GLGraphics SetGraphicsDriver GLGraphicsDriver() I would love true Bool in BlitzMax. Global ScreenWidth:Int=800 Global ScreenHeight:Int=600 Global ScreenDepth:Int=0 Global ScreenHertz:Int=60 Global SIDES_NUM:Int=100 Global light_position:Float[] = [-1.0, 3.0, 0.0, 1.0] Global LX:Float= light_position[0] Global LY:Float= light_position[1] Global LZ:Float= light_position[2] Global shadow_matrix:Float[] = [LY,0.0,0.0,0.0,-LX,0.0,-LZ,-1.0,0.0,0.0,LY,0.0,0.0,0.0,0.0,LY] Global light_diffuse:Float[] = [ 0.7, 1.0, 0.7, 1.0 ] Global material_diffuse:Float[] = [ 0.0, 0.5, 0.0, 1.0 ] Global material_specular:Float[] = [1.0, 1.0, 1.0, 1.0 ] Global material_shininess:Float[] = [ 10.0 ] Global alpha:Float Graphics(ScreenWidth,ScreenHeight,ScreenDepth,ScreenHertz,GRAPHICS_BACKBUFFER | GRAPHICS_DEPTHBUFFER) Start_GL() 'MAIN Repeat Render() Flip Until AppTerminate() Or KeyHit (KEY_ESCAPE) End 'END MAIN Function Start_GL() glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(45.0,1.3333,1.0,1000.0) glMatrixMode(GL_MODELVIEW) glLoadIdentity() glTranslatef(0,0,-8) glRotatef(30,1,0,0) glShadeModel(GL_SMOOTH) glDepthFunc(GL_LEQUAL) glLightfv(GL_LIGHT0, GL_POSITION, light_position) glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse) glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, material_diffuse) glMaterialfv(GL_FRONT, GL_SPECULAR, material_specular) glMaterialfv(GL_FRONT, GL_SHININESS, material_shininess) glEnable(GL_LIGHTING) glEnable(GL_LIGHT0) glEnable(GL_DEPTH_TEST) glEnable(GL_CULL_FACE) glPolygonOffset(-1, 0) End Function Function DrawCylinder(alpha:Float, shadow:Byte=True) glPushMatrix() If shadow glMultMatrixf(shadow_matrix) glDisable(GL_LIGHTING) glDepthMask(GL_FALSE) glEnable(GL_POLYGON_OFFSET_FILL) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glColor4f(0.1,0.1,0.1,1.0) EndIf 'This is the position and rotation of the cylinder. glTranslatef(0,1.5,0) glRotatef(alpha,1.0,0.5,0.3) 'Cylinder sides. glBegin(GL_TRIANGLE_STRIP) For Local i:Int=0 To SIDES_NUM Local x:Double = 0.5*Sin(i*2*Pi) Local y:Double = 0.5*Cos(i*2*Pi) Local d:Double = Sqr(x*x+y*y) glNormal3f(x/d,y/d,0) glVertex3f(x,y,-0.5) glNormal3f(x/d,y/d,0) glVertex3f(x,y, 0.5) Next glEnd() 'Cylinder top cap. glBegin(GL_TRIANGLE_FAN) glNormal3f(0.0,0.0,-1.0) glVertex3f(0.0,0.0,-0.5) For Local i:Int=0 Until SIDES_NUM Local x:Double = 0.5*Sin(i*2*Pi) Local y:Double = 0.5*Cos(i*2*Pi) glVertex3f(x,y,-0.5) Next glEnd() 'Cylinder bottom cap. glBegin(GL_TRIANGLE_FAN) glNormal3f(0.0,0.0, 1.0) glVertex3f(0.0,0.0, 0.5) For Local i:Int=0 Until SIDES_NUM Local x:Double = 0.5*Sin(-i*2*Pi) Local y:Double = 0.5*Cos(-i*2*Pi) glVertex3f(x,y, 0.5) Next glEnd() If shadow glDisable(GL_BLEND) glEnable(GL_LIGHTING) glDepthMask(GL_TRUE) glDisable(GL_POLYGON_OFFSET_FILL) EndIf glPopMatrix() End Function Function DrawLight() glDisable(GL_LIGHTING) glPushMatrix() 'Position the light from the light_position array.LX,LY,LZ glTranslatef(light_position[0], light_position[1], light_position[2]) 'This is the white sphere at the top of the screen. 'The light visually represented,so to speak. Local quadric:Byte Ptr = gluNewQuadric() gluSphere(quadric, 0.1, SIDES_NUM, SIDES_NUM) gluDeleteQuadric(quadric) glPopMatrix() glEnable(GL_LIGHTING) End Function Function DrawGround() 'Self explanetory,do not need to say anymore. 'Draws a quad. 4 sided polygon to you and me. glNormal3f(0,1,0) glBegin(GL_QUADS) glVertex3f(-5,0,-5) glVertex3f(-5,0,+5) glVertex3f(+5,0,+5) glVertex3f(+5,0,-5) glEnd() End Function Function Render() 'FPS Timer alpha:Float = MilliSecs()/30.0 'Change this for faster or slower Times per Tick. 'Clear the Color And Depth Buffers. glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT) 'Call Functions. DrawLight() DrawGround() DrawCylinder(alpha, True) DrawCylinder(alpha, False) End Function
Still learning OpenGL.
I have that BUZZ again.You can not beat the BUZZ.
all the best Mark.