At first I thought OpenGL was too hard. But I opened up lesson 5 of the NeHe tutorials, read it, copied and pasted the first big chunk of code onto a new source for me.
At first I had no clue what it did. All I knew is that it worked well. After repeated copying and pasting and reading, I figured out what each line does.
Next is the DO loop for whatever you want to draw. the first thing to write down is
!!!!!!!!!!! It will be right before LOOP WHILE. If you don't, your system will crash and you'll have to reboot. I forgot 3 times, and each time my screen had the resolution of 40*40, sometimes went blank, and I had to reboot manually. There won't be any permanrnt damage, just an anoying inconvenience. Remember FLIP right before you loop around.
And in the begining of the loop is glClear GL_COLOR_BUFFER_BIT OR GL_DEPTH_BUFFER_BIT and then glLoadIdentity. The last thing resets your screen (sort of like cls, but it does much more, such as keeping everything from running away).
For more, go to the NeHe website and there are nehe tutorials that come with the FB ide (you may have to dig a little bit).
And prepare to be amazed. I've got some source code for a small maze (no collision detection).
Code: Select all
#include once "GL/gl.bi"
#include once "GL/glu.bi"
screen 18,16,,2
dim as single x=18 'player's x coordinate
dim as single z=21 'player's z coordinate
dim bob as single 'bob angle
dim as short angle=90 'player's facing angle
dim as byte wid=2 'width of the boxes
dim map(2,10,10) as byte 'map array, (level,row,column)
const conv as single=3.14159265/180 'conversion factor for degrees to radians
glViewport 0,0,640,480 'screen mode
glMatrixMode GL_PROJECTION 'projection model
glLoadIdentity 'does something to the models
gluPerspective 45.0, 640.0/480.0, 0.1, 100.0
glMatrixMode GL_MODELVIEW 'viewing model
glLoadIdentity
glClearColor 0.0,0.0,0.0,0.5 'background color?
glClearDepth 1.0 'Clears depth
glEnable GL_DEPTH_TEST ' Enables Depth Testing
glDepthFunc GL_LEQUAL ' The Type Of Depth Testing To Do
glHint GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST
for m=1 to 2
for r=1 to 10
for c=1 to 10
read map(m,r,c)
next c
next r
next m
do
glClear GL_COLOR_BUFFER_BIT OR GL_DEPTH_BUFFER_BIT
glLoadIdentity
glRotatef 90-angle,0,1,0
glTranslatef -x,-1-.2*sin(5*bob*conv),-z
'map
for m=0 to 1 'm is offset back 1
for r=1 to 10
for c=1 to 10
if map(m+1,c,r)=1 then
glBegin GL_QUADS
glColor3f 1.0,1.0,0.0
glVertex3f wid*(r-.5),wid+wid*m,wid*(c+.5) 'front, yellow
glVertex3f wid*(r+.5),wid+wid*m,wid*(c+.5)
glVertex3f wid*(r+.5),wid*m ,wid*(c+.5)
glVertex3f wid*(r-.5),wid*m ,wid*(c+.5)
glColor3f 1.0,0.0,0.0 'back face, red
glVertex3f wid*(r-.5),wid+wid*m,wid*(c-.5)
glVertex3f wid*(r-.5),wid*m ,wid*(c-.5)
glVertex3f wid*(r+.5),wid*m ,wid*(c-.5)
glVertex3f wid*(r+.5),wid+wid*m,wid*(c-.5)
glColor3f 0.0,1.0,1.0 'left face,
glVertex3f wid*(r-.5),wid+wid*m,wid*(c-.5)
glVertex3f wid*(r-.5),wid+wid*m,wid*(c+.5)
glVertex3f wid*(r-.5),wid*m ,wid*(c+.5)
glVertex3f wid*(r-.5),wid*m ,wid*(c-.5)
glColor3f 0.0,0.0,1.0 'right face, blue
glVertex3f wid*(r+.5),wid*m ,wid*(c-.5)
glVertex3f wid*(r+.5),wid*m ,wid*(c+.5)
glVertex3f wid*(r+.5),wid+wid*m,wid*(c+.5)
glVertex3f wid*(r+.5),wid+wid*m,wid*(c-.5)
glEnd
end if
next c
next r
next m
'ground
glBegin GL_QUADS
glColor3f 0.0,0.5,0.0 'dark green
glVertex3f .5*wid ,0.0,wid*10.5
glVertex3f wid*10.5,0.0,wid*10.5
glVertex3f wid*10.5,0.0,wid*.5
glVertex3f .5*wid ,0.0,wid*.5
glEnd
'ceiling
glBegin GL_QUADS
glColor3f .8,.8,1.0 'light blue
glVertex3f .5*wid ,wid,wid*10.5
glVertex3f wid*10.5,wid,wid*10.5
glVertex3f wid*10.5,wid,wid*.5
glVertex3f .5*wid ,wid,wid*.5
glEnd
'2nd ceiling
glBegin GL_QUADS
glColor3f .8,.8,1.0 'light blue
glVertex3f .5*wid ,wid*2,wid*10.5
glVertex3f wid*10.5,wid*2,wid*10.5
glVertex3f wid*10.5,wid*2,wid*.5
glVertex3f .5*wid ,wid*2,wid*.5
glEnd
'walk forward
if multikey(80) then
let x=x-.1*cos(-angle*conv)
let z=z-.1*sin(-angle*conv)
let bob=bob+1
end if
'walk backward
if multikey(72) then
let x=x+.1*cos(-angle*conv)
let z=z+.1*sin(-angle*conv)
let bob=bob-1
end if
'turn left
if multikey(75) then let angle=angle+2
'turn right
if multikey(77) then let angle=angle-2
if bob>=360 then let bob=1
flip
loop while not(multikey(1))
end
'level 1
' 1,2,3,4,5,6,7,8,9,0
data 1,1,1,1,1,1,1,1,1,1 :'1
data 1,0,0,0,0,0,0,0,0,1 :'2
data 1,1,0,1,1,1,1,1,0,1 :'3
data 1,0,0,1,0,0,0,0,0,1 :'4
data 1,0,1,0,0,1,1,1,0,1 :'5
data 1,0,1,0,1,1,0,1,0,1 :'6
data 1,0,1,0,1,0,0,0,0,1 :'7
data 1,0,1,1,1,0,1,1,0,1 :'8
data 1,0,0,1,0,0,0,1,0,1 :'9
data 1,1,1,1,1,1,1,1,0,1 :'10
'level 2
data 1,1,1,1,1,1,1,1,1,1
data 1,0,0,0,0,0,0,0,0,0
data 1,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,1
data 1,1,1,1,1,1,1,1,1,1
You can change wid around. There shouldn't be any problems.