Strict
Const WIDTH=640,HEIGHT=480,DEPTH=16
Const Star_Count = 100
Const MAX_SIZE = 12
Const MAX_ROTSPD# = 1.5
Global Delta_X#,Delta_Y#, Delta_Ang#=0 ,tick#=0
Type TEntity
Field x#,y#
Method Update() Abstract
EndType
Type Star Extends TEntity
Field s#
Field size#
Field col#,alp#
Field rot#
Field tcol[3]
Field vtype
Method Update()
Local cs# , sn#
Local tx# , ty#
x:+ ( x-319.99999 ) / s
y:+ ( y-239.99999 ) / s
x=x-320
y=y-240
cs = Cos(Delta_Ang)
sn = Sin(Delta_Ang)
tx = x
ty = y
x = tx * cs - ty * sn
y = tx * sn + ty * Cs
x=x +320
y=y +240
'Pitch Horiz and Verti
x = x + Delta_X / s
y = y + Delta_Y / s
If x<0 Or x>WIDTH
x=Rnd(WIDTH)
alp=0
EndIf
If y<0 Or y>HEIGHT
y=Rnd(HEIGHT)
alp=0
EndIf
If alp<1
alp = alp + .05
EndIf
SetBlend LIGHTBLEND
SetRotation rot
SetAlpha alp
rot=rot+5
SetColor tcol[0],tcol[1],tcol[2]
Select vtype
Case 0
SetHandle size*.5,.5
DrawRect x,y,size,1
SetHandle .5,size*.5
DrawRect x,y,1,size
SetHandle 0,0
Case 1
SetHandle size*.5,size*.5
DrawRect x,y,size,size
SetHandle 0,0
End Select
End Method
Function CreateStar:Star()
Local s:Star = New Star
Local r =Rand(128)
s.x=Rnd(640)
s.y=Rnd(480)
s.s=Rnd(150,250)
s.tcol=[r,r,r]
s.size = Rnd(1,MAX_SIZE)
s.vtype = Rnd(1)
Return s
EndFunction
End Type
Function UpdateEntities( list:TList )
Delta_X = 400*Cos(tick)
Delta_Y = 400*Sin(tick)
Delta_Ang = MAX_ROTSPD*Cos( tick )
tick=tick+.5
Local c:TEntity
For c=EachIn list
c.Update
Next
End Function
Graphics WIDTH,HEIGHT,DEPTH
HideMouse
Local StarList:TList = New TList
Local a
Local px1#=30,py1#
Local px2#=WIDTH-30,py2#
Local bx#=WIDTH/2, by#=HEIGHT/2
Local bdx#=Rnd(-8,4)
Local bdy#=3
Local sc1,sc2
For a= 0 To Star_Count-1
StarList.AddLast( star.CreateStar() )
Next
While Not KeyDown( KEY_ESCAPE )
Cls
UpdateEntities StarList
py1=MouseY()
If py1<40 py1=40
If py1>HEIGHT-40 py1=HEIGHT-40
SetBlend SOLIDBLEND
SetColor 255,0,0
SetRotation 0
SetHandle 5,40
DrawRect px1,py1,10,80
DrawRect px2,py2,10,80
SetHandle 0,0
SetColor 0,0,255
SetHandle 2.5,2.5
DrawRect bx,by,5,5
SetHandle 0,0
bx=bx+bdx
by=by+bdy
If by<3 bdy=-bdy
If by>HEIGHT-3 bdy=-bdy
'check players paddle
If bx<px1+10
If by>py1-40 And by<py1+40
bdx=-bdx*Rnd(1.1,1.2)
bdy=-bdy+Rnd(-1,1)
EndIf
EndIf
If bx>px2-10 And bx<px2+10
If by>py2-40 And by<py2+40
bdx=-bdx*Rnd(1.1,1.2)
bdy=-bdy+Rnd(-1,1)
EndIf
EndIf
If bx>WIDTH-3 Or bx<3
bdx= Rnd(-8,8)
bdy= Rnd(-8,8)
If bx>Width-3
sc1:+1
Else
sc2:+1
EndIf
bx=width/2
by=height/2
EndIf
If py2<by
If py2<HEIGHT-40
py2=py2+3
EndIf
EndIf
If py2>by
If py2>40
py2=py2-3
EndIf
EndIf
DrawText sc1,width/2-40,0
DrawText sc2,width/2+40,0
FlushMem
Flip
Wend
yeah. i've tried this and got the same result:
Global mx,my
Global IMG:Timage
Global FPS, RFPS,LastSEcs
bglCreateContext 1024,768
glBindTexture GL_TEXTURE_2D,bglTexFromPixmap( LoadPixmap( "max.png" ) )
bglSetMouseVisible False
Local ax#,ay#
Local cube = glGenLists(1)
GLShadeModel(GL_SMOOTH)
Global light_position#[] = [100.0, 100.0, 50.0, 0.0]
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glNewList(cube, GL_COMPILE)
SizeCube(15)
glEndList
'glEnable(GL_LIGHT0)
While Not KeyDown(KEY_ESCAPE)
glColor3f(1,1,1)
glClearDepth(1.0)
glEnable(GL_DEPTH_TEST)
glDepthFunc(GL_LEQUAL)
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
Begin3D()
glTranslatef 0,0,-100'0
glRotatef my,1,0,0
glRotatef -mx,0,1,0
ax=ax+1
ay=ay+2
glPolygonMode(GL_FRONT, GL_FILL)
GLEnable(GL_DEPTH_TEST)
'GlScalef 0.5,0.5,0.5
GLDisable(GL_BLEND)
glCallList Cube
GlScalef 1.5,1.5,1.5
GLEnable(GL_BLEND)
'glColor4f(1.0,1.0,1.0,0.5)
glColor4f(1.0,1.0,1.0,0.5)
glRotatef -mx,1,0,0
glRotatef my,0,1,0
'GLDisable(GL_DEPTH_TEST)
'GLEnable(GL_DEPTH_TEST)
' glCallList Cube
'glPolygonMode(GL_FRONT, GL_LINE)
'glColor3f(1,1,1)
'End3D()
' SetColor 255,255,255
' SetRotation 0
mx = MouseX()
my = MouseY()
' DrawLine mx-3,my,mx+4,my
' DrawLine mx,my-3,mx,my+4
bglDrawText "Blitzmax Inline OpenGL. "+rfps+" fps.",20,20
checkfps()
FlushMem
bglSwapBuffers
' Flip
Wend
End
Function CheckFPS()
If (MilliSecs()-lastsecs) <1000 Then
fps = fps +1
Else
lastsecs = MilliSecs()
rfps = fps
fps = 0
EndIf
End Function
Function Begin3D()
glEnable(GL_TEXTURE_2D)
'glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR)
Local w#=1024'GraphicsWidth()
Local h#=768'GraphicsHeight()
If h=0 Then h=1
Local aspect# = w/h
glMatrixMode GL_PROJECTION
glLoadIdentity
gluPerspective 45,aspect,0.1,1000
glMatrixMode GL_MODELVIEW
glLoadIdentity
glViewport 0,0,w,h
glFrontFace GL_CW
glCullFace GL_BACK
gldisable GL_CULL_FACE
' GLEnable(GL_LIGHTING)
EndFunction
rem
Function End3D()
Local w#=GraphicsWidth()
Local h#=GraphicsHeight()
glDisable(GL_TEXTURE_2D)
glMatrixMode GL_PROJECTION
glLoadIdentity
'glOrtho 0,w,h,0,-1,1
gluOrtho2D 0,w,h,0
glMatrixMode GL_MODELVIEW
glLoadIdentity
glEnable GL_SCISSOR_TEST
glViewport 0,0,w,h
GLDisable(GL_LIGHTING)
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)
GlEnable(GL_BLEND)
EndFunction
end rem
Function SizeCube(size#)
Local a#=1.0
' glColor3f(1,1,1) 'glColor3f(1,0,0)
' glColor4f(1.0,1.0,1.0,0.6)
glNormal3f( 0.0, 0.0, 1.0)'
glBegin(GL_QUADS) ' {near face}
glTexCoord2f(0.0, 0.0);
glVertex3f( size#, size#,-size#)
glTexCoord2f(1.0, 0.0);
glVertex3f(-size#, size#,-size#)
glTexCoord2f(1.0, 1.0);
glVertex3f(-size#,-size#,-size#)
glTexCoord2f(0.0, 1.0);
glVertex3f( size#,-size#,-size#)
glEnd
glNormal3f( 1.0, 0.0, 0.0)
glBegin(GL_QUADS) ' {right face}
glTexCoord2f(0.0, 0.0);
glVertex3f(-size#, size#,-size#)
glTexCoord2f(1.0, 0.0);
glVertex3f(-size#, size#, size#)
glTexCoord2f(1.0, 1.0);
glVertex3f(-size#,-size#, size#)
glTexCoord2f(0.0, 1.0);
glVertex3f(-size#,-size#,-size#)
glEnd
glNormal3f( -1.0, 0.0, 0.0)
glBegin(GL_QUADS) ' {left face}
glTexCoord2f(0.0, 0.0);
glVertex3f( size#, size#, size#)
glTexCoord2f(1.0, 0.0);
glVertex3f( size#, size#,-size#)
glTexCoord2f(1.0, 1.0);
glVertex3f( size#,-size#,-size#)
glTexCoord2f(0.0, 1.0);
glVertex3f( size#,-size#, size#)
glEnd
glNormal3f( 0.0, 0.0, -1.0)
glBegin(GL_QUADS) ' {back face}
glTexCoord2f(0.0, 0.0);
glVertex3f(-size#, size#, size#)
glTexCoord2f(1.0, 0.0);
glVertex3f( size#, size#, size#)
glTexCoord2f(1.0, 1.0);
glVertex3f( size#,-size#, size#)
glTexCoord2f(0.0, 1.0);
glVertex3f(-size#,-size#, size#)
glEnd
' glColor3f(1,0,1)
glNormal3f( 0.0, -1.0, 0.0)
glBegin(GL_QUADS) ' {bottom face}
glTexCoord2f(0.0, 0.0);
glVertex3f( size#, size#,-size#)
glTexCoord2f(1.0, 0.0);
glVertex3f( size#, size#, size#)
glTexCoord2f(1.0, 1.0);
glVertex3f(-size#, size#, size#)
glTexCoord2f(0.0, 1.0);
glVertex3f(-size#, size#,-size#)
glEnd
' glColor3f(1,1,1)
glNormal3f( 0.0, 1.0, 0.0)
glBegin(GL_QUADS) ' {top face}
glTexCoord2f(0.0, 0.0);
glVertex3f( size#,-size#,-size#)
glTexCoord2f(1.0, 0.0);
glVertex3f(-size#,-size#,-size#)
glTexCoord2f(1.0, 1.0);
glVertex3f(-size#,-size#, size#)
glTexCoord2f(0.0, 1.0);
glVertex3f( size#,-size#, size#)
glEnd
End Function