the following example works nicely with PB 32 bit, but when trying it in PB x64 it display erroneous shape, precisely half of the shape and erroneous connections between the points.
Code: Select all
Global Dim MeshDataInd(0)
glVertexPointer_(3, #GL_FLOAT, SizeOf(VertexData), @vertex(0,0)\x)
glDrawElements_(#GL_QUADS, indexsize, #GL_UNSIGNED_INT, @MeshDataInd(0))
all the time i was thinking the default variable type is Long and not Integer as the case now. so i left the Global Dim MeshDataInd(0) without the .l and in reality it is .i
looking at the Help file : By default, when a data type is not indicated, the data is an integer
Long .l 4 bytes -2147483648 to +2147483647
Integer .i 4 bytes (using 32-bit compiler) -2147483648 to +2147483647
Integer .i 8 bytes (using 64-bit compiler) -9223372036854775808 to +9223372036854775807
so the Integer type is different in PB 32 than PB x64 this is why i get half of the shape
below is the code works in PBx32 and PBx64 correctly, i have only changed to type long explicitly
Global Dim MeshDataInd.l(0)
Code: Select all
Structure VertexData
x.f
y.f
z.f
r.f
g.f
b.f
tx.f
ty.f
EndStructure
Declare FPS(timer.l)
Declare FillArray()
Define event, quit
ExamineDesktops()
OpenWindow(0, 0, 0, DesktopWidth(0), DesktopHeight(0), ".. Up/Down: zoom in/out... 'W': wire frame... 'A'/'Z': change Camera view")
SetWindowColor(0, RGB(200,220,200))
OpenGLGadget(0, 5, 5, WindowWidth(0) , WindowHeight(0) , #PB_OpenGL_Keyboard)
glMatrixMode_(#GL_PROJECTION)
glLoadIdentity_();
gluPerspective_(45.0, 800/600, 1.0, 60.0)
glMatrixMode_(#GL_MODELVIEW)
glTranslatef_(0, 0, -5)
glShadeModel_(#GL_SMOOTH)
glEnable_(#GL_DEPTH_TEST)
;glEnable_(#GL_CULL_FACE)
glColor3f_(1.0, 0.3, 0.0)
glViewport_(0, 0, 800, 600)
;resolution of the graphics grid
Global NbX=100
Global NbZ=100
Global VertexCount = (NbX+1)*(NbZ+1)
Global TexID.i
Global Dim vertex.VertexData(NbX,NbZ)
Global Dim MeshDataInd.l(0)
;Draw to texture
Dim texDat.c(512)
For i = 0 To 511
texDat(i) = ((i + (i / 8)) % 2) * 128 + 127
Next
*Buffer = @texDat(0)
glTexParameteri_(#GL_TEXTURE_2D, #GL_TEXTURE_MIN_FILTER, #GL_NEAREST)
glTexParameteri_(#GL_TEXTURE_2D, #GL_TEXTURE_MAG_FILTER, #GL_NEAREST)
glTexImage2D_(#GL_TEXTURE_2D, 0, #GL_RGB, 16, 16, 0, #GL_RGB, #GL_UNSIGNED_BYTE, *Buffer)
glEnable_(#GL_TEXTURE_2D) ; Enable texture mapping
Global indexsize
FillArray()
;wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
glVertexPointer_(3, #GL_FLOAT, SizeOf(VertexData), @vertex(0,0)\x) ;Vertex data is at the start of our structure VertexData
glColorPointer_(3, #GL_FLOAT, SizeOf(VertexData), @vertex(0,0)\r) ;The color data is 12 bytes below the start
glTexCoordPointer_(2, #GL_FLOAT, SizeOf(VertexData), @vertex(0,0)\tx) ;The texture data is 12 bytes below the color start
rot.f = 1
;glTranslatef_(0.0, 0.0, -2)
glViewport_(0, 0, WindowWidth(0), WindowHeight(0))
glPointSize_(3)
;the following is the camera or your eye, 0,2,3 your eyes__ 0,0,0; the object__ 0,1,0 direction
gluLookAt_( 0, 2, 3,
0, 0, 0,
0, 1, 0 )
SetActiveGadget(0) ; make the openGLgadget active so the keyboard can be used with it
glEnableClientState_(#GL_VERTEX_ARRAY )
glEnableClientState_(#GL_COLOR_ARRAY)
glEnableClientState_(#GL_TEXTURE_COORD_ARRAY)
a$=".. Up/Down: zoom in/out... 'W': wire frame... 'A'/'Z': change Camera view"
Repeat
fps$ = Str(FPS(1000))
SetWindowTitle(0,"FPS = " +fps$+ " "+a$)
;glClearColor_(0.1, 0.1, 0.5, 1) ; color of the window
glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
glRotatef_(rot/2, 0, 1, 0);
;glPointSize_(2)
glDrawElements_(#GL_QUADS, indexsize, #GL_UNSIGNED_INT, @MeshDataInd(0))
;glDrawElements_(#GL_POINTS,indexsize,#GL_UNSIGNED_INT, @MeshDataInd(0))
Repeat
event = WindowEvent()
If event = #PB_Event_CloseWindow
quit = #True
EndIf
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 = 0
glPolygonMode_(#GL_FRONT_AND_BACK, #GL_LINE )
fill ! 1
Else
glPolygonMode_(#GL_FRONT_AND_BACK, #GL_FILL)
fill ! 1
EndIf
ElseIf Key = #PB_Shortcut_Up
glScalef_(1.05,1.05,1.05)
ElseIf Key = #PB_Shortcut_Down
glScalef_(0.95,0.95,0.95)
ElseIf Key = #PB_Shortcut_A
glMatrixMode_(#GL_MODELVIEW);
glLoadIdentity_() ;
;gluLookAt_(0, 40, 14, 0,0,0, 0,1,0 )
gluLookAt_(0, 5, 1, 0,0,0, 0,1,0 )
ElseIf Key = #PB_Shortcut_Z
glMatrixMode_(#GL_MODELVIEW);
glLoadIdentity_();
;gluLookAt_(0, 0.3, 0.5, 0,0,0, 0,1,0 )
gluLookAt_(0, 3, 5, 0,0,0, 0,1,0 )
EndIf
EndIf
EndIf
Until event = 0 Or quit = #True
SetGadgetAttribute(0, #PB_OpenGL_FlipBuffers, #True)
Delay(1)
Until quit = #True
glDisableClientState_(#GL_TEXTURE_COORD_ARRAY)
glDisableClientState_(#GL_COLOR_ARRAY)
glDisableClientState_(#GL_VERTEX_ARRAY)
Procedure FillArray()
xMin.f = -2 : yMin.f = -2: zMin.f = -2 : xMax.f = 2: yMax = 2 : zMax = 2
range = xMax - xMin
step1.f = range / NbX
x.f = xMin: z.f = zMin : y.f = yMin : v.l = 0
For b=0 To NbZ
For a=0 To NbX
y.f = Cos(x*x+z*z)
;**********************************************************************
vertex(a,b)\x = x*1
vertex(a,b)\y = y*1 ; just amplify the height
vertex(a,b)\z = z*1
vertex(a,b)\tx = a/NbX
vertex(a,b)\ty = b/NbZ
vertex(a,b)\r = 1 :vertex(a,b)\g = 1 :vertex(a,b)\b = 1
If y > 0.5
;vertex(a,b)\r = 0.9 :vertex(a,b)\g = 0.0 :vertex(a,b)\b = 0
ElseIf y>=-0.3
;vertex(a,b)\r = 0.2 :vertex(a,b)\g = 0.9 :vertex(a,b)\b = 0
Else
;vertex(a,b)\r = 1.0 :vertex(a,b)\g = 1.0 :vertex(a,b)\b = 0
EndIf
x.f + step1
Next a
x = xMin
z.f + step1
Next b
;ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
Nb=NbX+1
For b=0 To NbZ-1
For a=0 To NbX-1
P1=a+(b*Nb)
P2=P1+1
P3=a+(b+1)*Nb
P4=P3+1
MeshDataInd(indx) = P3
ReDim MeshDataInd(indx+2)
MeshDataInd(indx+1) = P4
ReDim MeshDataInd(indx+3)
MeshDataInd(indx+2) = P2
ReDim MeshDataInd(indx+4)
MeshDataInd(indx+3)= P1;P2
indx+4
Next
Next
indexsize = ArraySize(MeshDataInd()) + 1
EndProcedure
Procedure FPS(timer.l) ; the code is from the forum somewhere
Static FPSCount.l, FPS.l
Static delay.l
Protected t.l
If timer = 0
ProcedureReturn -1
EndIf
t = ElapsedMilliseconds()
If t-delay > timer
FPS = FPSCount*1000/timer
FPSCount = 0
delay = t
Else
FPSCount+1
EndIf
ProcedureReturn FPS
EndProcedure