Global ScreenWidth:Int=800
Global ScreenHeight:Int=600
Global ScreenDepth:Int=32
Global xrot:Float=0
Global yrot:Float=0
Global zrot:Float=0
Global Checkimage:Byte[256,256,4]
Global Texname:Int
bglCreateContext(ScreenWidth,ScreenHeight,ScreenDepth,0,BGL_BACKBUFFER | BGL_DEPTHBUFFER) '| BGL_FULLSCREEN
InitGl()
While Not KeyHit( KEY_ESCAPE )
nehe6()
glColor3f(1.0,1.0,1.0)
'Framecounter--------------------------------------------
Framecounter_counter=Framecounter_counter+1
If Framecounter_time=0 Then Framecounter_time=MilliSecs()
If Framecounter_time+1001 <MilliSecs() Then
Framecounter_framerate=Framecounter_counter
Framecounter_counter=0
Framecounter_time=MilliSecs()
EndIf
bglDrawText("FPS : "+Framecounter_framerate,ScreenWidth-(8*12),ScreenHeight-16-8)
'--------------------------------------------------------
bglDrawText("Nehe lesson 6",10,24)
FlushMem
bglSwapBuffers
Wend
End
Function InitGl()
LoadGlTextures()
glClearColor(0.0, 0.0, 0.0, 0.0)
glClearDepth 1.0
glDepthFunc(GL_LESS)
glEnable(GL_DEPTH_TEST)
glShadeModel(GL_SMOOTH)
glViewport(0,0,ScreenWidth,ScreenHeight)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(45.0,Float(ScreenWidth)/Float(ScreenHeight),1.0,100.0)
glMatrixMode(GL_MODELVIEW)
End Function
Function LoadGlTextures()
Local PointeurImg:Byte Ptr
Local TexWidth
Local TexHeight
tex01:TPixmap=LoadPixmap("data/logo.bmp")
TexWidth=tex01.Width
TexHeight=tex01.Height
PointeurImg=PixmapPixelPtr(tex01,0,0)
pp=0
For y=TexHeight-1 To 0 Step -1
For x=0 To TexWidth-1
Checkimage[y,x,0]=PointeurImg[pp]
Checkimage[y,x,1]=PointeurImg[pp+1]
Checkimage[y,x,2]=PointeurImg[pp+2]
Checkimage[y,x,3]=100
pp=pp+3
Next
Next
tex01=Null
glPixelStorei(GL_UNPACK_ALIGNMENT,1)
glGenTextures(1, Varptr Texname)
glBindTexture(GL_TEXTURE_2D, Texname)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TexWidth, TexHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, Checkimage)
End Function
Function nehe6()
glClear GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
glEnable(GL_TEXTURE_2D)
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)
glBindTexture GL_TEXTURE_2D,Texname
glLoadIdentity
glTranslatef 0.0,0.0,-5.0
glRotatef xrot,1.0,0.0,0.0 ' Rotate On The X Axis
glRotatef yrot,0.0,1.0,0.0 ' Rotate On The Y Axis
glRotatef zrot,0.0,0.0,1.0 ' Rotate On The Z Axis
glBegin(GL_TRIANGLE_STRIP) ' Build Quad From A Triangle Strip
glTexCoord2d(1,1); glVertex3f(x+0.5,y+0.5,z) ' Top Right
glTexCoord2d(0,1); glVertex3f(x-0.5,y+0.5,z) ' Top Left
glTexCoord2d(1,0); glVertex3f(x+0.5,y-0.5,z) ' Bottom Right
glTexCoord2d(0,0); glVertex3f(x-0.5,y-0.5,z) ' Bottom Left
glEnd() ' Done Building Triangle Strip
xrot = xrot + 0.003 ' X Axis Rotation
yrot = yrot + 0.002 ' Y Axis Rotation
zrot = zrot + 0.004 ' Z Axis Rotation
glDisable(GL_TEXTURE_2D)
End Function
This is the butchered test I did from Nehe tutorials.
The .bmp has to be 256*256.