hope that this example of some usage, it is cooked from several examples. the picture is wide, and we can look at different parts of the scene by rotating the camera with left/right keys. there are complex codes in the web about the FishEye and spheric projection, unfortunately mostly written in modern opengl
( GLdouble eyeX, GLdouble eyeY, GLdouble eyeZ, GLdouble centerX, GLdouble centerY, GLdouble centerZ, GLdouble upX, GLdouble upY, GLdouble upZ)
if someone have more to add or to correct please help to enrich the subject.
Code: Select all
Structure Point3D
x.f
y.f
z.f
tu.f
tv.f
r.f
g.f
b.f
EndStructure
UseJPEGImageDecoder()
UseJPEGImageEncoder()
UsePNGImageDecoder()
Declare FillArray()
Define event, quit
Dim *Buffer(1)
LoadImage(1, "arches.jpg")
*Buffer(1) = EncodeImage(1) ; default is: #PB_ImagePlugin_BMP : encode the image in BMP
Dim TexID(1)
OpenWindow(0, 0, 0, 800, 600, "... Up/Down: zoom in/out...Left/Right: rotate the Camera .. 'W': wire frame... ")
SetWindowColor(0, RGB(200,220,200))
OpenGLGadget(0, 10, 10, WindowWidth(0) , WindowHeight(0) , #PB_OpenGL_Keyboard)
;- Generate textures
glGenTextures_(1, @TexID(1))
glBindTexture_(#GL_TEXTURE_2D, TexID(1))
glTexParameteri_(#GL_TEXTURE_2D, #GL_TEXTURE_MIN_FILTER, #GL_LINEAR)
glTexParameteri_(#GL_TEXTURE_2D, #GL_TEXTURE_MAG_FILTER, #GL_LINEAR)
glTexImage2D_(#GL_TEXTURE_2D, 0, 3, ImageWidth(1), ImageHeight(1), 0, #GL_BGR_EXT, #GL_UNSIGNED_BYTE, *Buffer(1))
FreeMemory(*Buffer(1))
glEnable_(#GL_TEXTURE_2D) ; Enable texture mapping
glBindTexture_(#GL_TEXTURE_2D, TexID(1))
glLoadIdentity_();
gluPerspective_(45.0, 800/600, 1.0, 60.0)
glTranslatef_(0, 0, -5)
glEnable_(#GL_DEPTH_TEST)
Global NbX = 100
Global NbY = 100
Global Dim Point3D.Point3D(NbX,NbY)
Global Dim MeshDataInd.PB_MeshFace(60000)
Global indexsize = ArraySize(MeshDataInd()) + 1
Global r.f
Global dist.f = 40
;Debug indexsize
;Debug WindowWidth(0)
;Debug WindowHeight(0)
FillArray()
;Debug indx
;=================================================================================
rot.f = 1
;glPointSize_( 1 )
;glTranslatef_(0.0, 0.0, -30)
SetActiveGadget(0) ; make the openGLgadget active
glPushMatrix_(); to store the current state
glMatrixMode_(#GL_PROJECTION)
glLoadIdentity_();
;gluPerspective_(60.0, WindowWidth(0)/WindowHeight(0), 1.0, 200.0)
gluPerspective_(90.0, 800/5000, 1.0, 200.0)
glMatrixMode_(#GL_MODELVIEW)
;glTranslatef_(0, 0, -5)
glShadeModel_(#GL_SMOOTH)
glEnable_(#GL_DEPTH_TEST)
glViewport_(0, 0, WindowWidth(0), WindowHeight(0))
gluLookAt_( 0, 0, dist, ; the camera looking from position 0,0,dist to 0,0,0 from above
0, 0, 0,
0, 1, 0 )
glPopMatrix_()
Repeat
Event = WindowEvent()
glViewport_(0, 0, WindowWidth(0), WindowHeight(0))
glClearColor_(0.9, 0.9, 0.9, 1)
glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
glEnableClientState_(#GL_VERTEX_ARRAY )
glEnableClientState_(#GL_COLOR_ARRAY)
glEnableClientState_(#GL_TEXTURE_COORD_ARRAY)
;glRotatef_(rot/2, 0, 1, 0);
glVertexPointer_(3, #GL_FLOAT,SizeOf(Point3D),@Point3D(0,0)\x)
glColorPointer_(3, #GL_FLOAT, SizeOf(Point3D), @Point3D(0,0)\r)
glTexCoordPointer_(2, #GL_FLOAT, SizeOf(Point3D), @Point3D(0,0)\tu)
glDrawElements_(#GL_TRIANGLES,indexsize,#GL_UNSIGNED_INT, @MeshDataInd(0)\Index)
;glDrawElements_(#GL_POLYGON,indx,#GL_UNSIGNED_INT, @MeshDataInd(0)\Index)
glDisableClientState_(#GL_TEXTURE_COORD_ARRAY)
glDisableClientState_(#GL_COLOR_ARRAY)
glDisableClientState_(#GL_VERTEX_ARRAY);
If Event = #PB_Event_Gadget And EventGadget() = 0
If EventType() = #PB_EventType_KeyDown ; like KeyboardReleased
key = GetGadgetAttribute(0,#PB_OpenGL_Key )
If key = #PB_Shortcut_Escape ; Esc key to exit
quit = 1
ElseIf Key = #PB_Shortcut_W; display wire Frame or solid frame
If fill
glPolygonMode_(#GL_FRONT_AND_BACK, #GL_FILL )
fill ! 1
Else
glPolygonMode_(#GL_FRONT_AND_BACK, #GL_LINE )
fill ! 1
EndIf
ElseIf Key = #PB_Shortcut_Up
dist - 0.2
glLoadIdentity_()
gluLookAt_( 0, 0.1, dist, r, 0, 0, 0, 1, 0 )
;glScalef_(1.05,1.05,1.05)
ElseIf Key = #PB_Shortcut_Down
dist + 0.2
glLoadIdentity_()
gluLookAt_( 0, 0.1, dist, r, 0, 0, 0, 1, 0 )
;glScalef_(0.95,0.95,0.95)
ElseIf Key = #PB_Shortcut_Right
r+0.05
;glMatrixMode_(#GL_MODELVIEW);
glLoadIdentity_()
gluLookAt_( 0, 0.1, dist, r, 0, 0, 0, 1, 0 )
ElseIf Key = #PB_Shortcut_Left
r-0.05
;glMatrixMode_(#GL_MODELVIEW);
glLoadIdentity_()
gluLookAt_( 0, 0.1, dist, r, 0, 0, 0, 1, 0 )
EndIf
EndIf
EndIf
SetGadgetAttribute(0, #PB_OpenGL_FlipBuffers, #True)
Delay(5)
Until Event = #PB_Event_CloseWindow Or quit = 1
glDeleteTextures_(1, @TexID(1))
Procedure FillArray()
xMin.f = -20 : yMin.f = -20: zMin.f = -20 : xMax.f = 20: yMax = 20 : zMax = 20
range.f = xMax - xMin
step1.f = range*1 / NbX
x.f = xMin: z.f = zMin : y.f = yMin : tu.f: tv.f
For b=0 To NbY
t.f=0
For a=0 To NbX
t + #PI/(NbX+1)
z.f = 0 ;-40*Sin(t)+Cos(t)
;**********************************************************************
Point3D(a,b)\x = x*1
Point3D(a,b)\y = y*1.5 ; change to 2 to amplify the height
Point3D(a,b)\z = z*1
Point3D(a,b)\tu = a/NbX
Point3D(a,b)\tv = b/NbY
Point3D(a,b)\r = 1 :Point3D(a,b)\g = 1 :Point3D(a,b)\b = 1
x.f + step1
Next a
x = xMin
y.f + step1
Next b
;ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
Nb=NbX+1
For b=0 To NbY-1
For a=0 To NbX-1
P1=a+(b*Nb)
P2=P1+1
P3=a+(b+1)*Nb
P4=P3+1
;MeshFace(P3, P2, P1)
;MeshFace(P2, P3, P4)
MeshDataInd(indx)\Index = P3
MeshDataInd(indx+1)\Index = P2
MeshDataInd(indx+2)\Index = P1
MeshDataInd(indx+3)\Index = P2
MeshDataInd(indx+4)\Index = P3
MeshDataInd(indx+5)\Index = P4
indx+6
Next
Next
EndProcedure