primo
01-01-2016, 21:13
i was trying to cast a texture to a 3D curve points cloud. so every point have a corresponding color from the texture. ie i don't want to make quads or triangles or whatever to connect the points , just points cloud, and it seems the only way the texture appears real is to make the points thicker, and the number of points more and more. i have used a mixture of opengl and TBGL since the opengl example was ready, i only have added the easy texturing from a TBGL example. in fact i seek Petr comments and suggestions about my approach, Thanks
Happy New Year for All
Uses "tbgl", "MATH"
#INCLUDE "%app_includepath%\thinbasic_gl.inc"
#INCLUDE "%app_includepath%\thinbasic_glu.inc"
Type Point3D
x As Single
y As Single
z As Single
red As Single
green As Single
blue As Single
tu As Single
tv As Single
End Type
Dim hwnd As DWord
Global NbX As Integer = 200
Global NbZ As Integer = 200
Global Vertex(NbX, NbX) As Point3D
'msgbox 0, SizeOf(Point3D))
hwnd = TBGL_CreateWindowEx("glDrawArrays example - esc to exit", 600, 600, 32, 0)
TBGL_ShowWindow
TBGL_ResetKeyState()
glPointSize( 2 ) ' just to show the curve in bold
TBGL_LoadTexture APP_Path+"SampleScripts\TBGL\Sprites\Textures\ship3.tga", 1, %TBGL_TEX_MIPMAP
TBGL_UseTexturing(%TRUE)
TBGL_BindTexture(1)
FillArray ' fill Vertex(...) with position data and color data
While TBGL_IsWindow(hwnd)
TBGL_ClearFrame
'TBGL_Camera(0, 3, 4, 0, 0, 0)
display
TBGL_DrawFrame
If TBGL_GetWindowKeyState( hwnd, %VK_ESCAPE) Then Exit While
Wend
TBGL_DestroyWindow
'=================================================================================
Sub display()
glMatrixMode(%GL_PROJECTION)
glLoadIdentity()
gluPerspective(90.0, 800/600, 1.0, 60.0)
glMatrixMode(%GL_MODELVIEW)
glTranslatef(0, 0, -20)
glShadeModel(%GL_SMOOTH)
glEnable(%GL_DEPTH_TEST)
gluLookAt( 0, 1.5, 1,
0, 1, 0,
0, 1, 0 )
glclear(%gl_color_buffer_bit)
TBGL_Rotate GetTickCount/30,0,1,0
glClear(%GL_COLOR_BUFFER_BIT Or %GL_DEPTH_BUFFER_BIT)
glClearColor(1, 1, 1, 1)
glEnableClientState(%GL_VERTEX_ARRAY )
glEnableClientState(%GL_COLOR_ARRAY)
glEnableClientState(%GL_TEXTURE_COORD_ARRAY)
glVertexPointer(3, %GL_FLOAT,SizeOf(Point3D),VarPtr(Vertex(1,1).x))
glColorPointer(3, %GL_FLOAT, SizeOf(Point3D), VarPtr(Vertex(1,1).red))
glTexCoordPointer(2, %GL_FLOAT, SizeOf(Point3D), VarPtr(Vertex(1,1).tu))
glDrawArrays(%GL_POINTS, 1, NbX*NbX )'40000 points
glDisableClientState(%GL_COLOR_ARRAY)
glDisableClientState(%GL_VERTEX_ARRAY)
'**************************************************
End Sub
Sub FillArray()
Single x, y, z, tu, tv, xMin, yMin, zMin, xMax, yMax, zMax, range, step1
'**********************************
xMin = -12 : yMin = -12: zMin = -12 : xMax = 12: yMax = 12 : zMax = 12
range = xMax - xMin
step1 = range / NbX
x = xMin: z = zMin : y = yMin
Integer b, a
For b=1 To NbZ
For a=1 To NbX
'y =(1 - x*x -z*z) * Exp(-1/2 * (x*x + z*z)) ' Hat
'y = Sin(10*(x^2+z^2))/5
y = Sin(Sqr(x*x+ z*z)) / Sqr(x*x + z*z)
Vertex(a,b).x = x*1
Vertex(a,b).y = y*5
Vertex(a,b).z = z*1
Vertex(a,b).red = 1 :Vertex(a,b).green = 1 :Vertex(a,b).blue = 1
Vertex(a,b).tu = a/NbX
Vertex(a,b).tv = b/NbZ
x + step1
Next a
x = xMin
z + step1
Next b
'**********************************
End Sub
Happy New Year for All
Uses "tbgl", "MATH"
#INCLUDE "%app_includepath%\thinbasic_gl.inc"
#INCLUDE "%app_includepath%\thinbasic_glu.inc"
Type Point3D
x As Single
y As Single
z As Single
red As Single
green As Single
blue As Single
tu As Single
tv As Single
End Type
Dim hwnd As DWord
Global NbX As Integer = 200
Global NbZ As Integer = 200
Global Vertex(NbX, NbX) As Point3D
'msgbox 0, SizeOf(Point3D))
hwnd = TBGL_CreateWindowEx("glDrawArrays example - esc to exit", 600, 600, 32, 0)
TBGL_ShowWindow
TBGL_ResetKeyState()
glPointSize( 2 ) ' just to show the curve in bold
TBGL_LoadTexture APP_Path+"SampleScripts\TBGL\Sprites\Textures\ship3.tga", 1, %TBGL_TEX_MIPMAP
TBGL_UseTexturing(%TRUE)
TBGL_BindTexture(1)
FillArray ' fill Vertex(...) with position data and color data
While TBGL_IsWindow(hwnd)
TBGL_ClearFrame
'TBGL_Camera(0, 3, 4, 0, 0, 0)
display
TBGL_DrawFrame
If TBGL_GetWindowKeyState( hwnd, %VK_ESCAPE) Then Exit While
Wend
TBGL_DestroyWindow
'=================================================================================
Sub display()
glMatrixMode(%GL_PROJECTION)
glLoadIdentity()
gluPerspective(90.0, 800/600, 1.0, 60.0)
glMatrixMode(%GL_MODELVIEW)
glTranslatef(0, 0, -20)
glShadeModel(%GL_SMOOTH)
glEnable(%GL_DEPTH_TEST)
gluLookAt( 0, 1.5, 1,
0, 1, 0,
0, 1, 0 )
glclear(%gl_color_buffer_bit)
TBGL_Rotate GetTickCount/30,0,1,0
glClear(%GL_COLOR_BUFFER_BIT Or %GL_DEPTH_BUFFER_BIT)
glClearColor(1, 1, 1, 1)
glEnableClientState(%GL_VERTEX_ARRAY )
glEnableClientState(%GL_COLOR_ARRAY)
glEnableClientState(%GL_TEXTURE_COORD_ARRAY)
glVertexPointer(3, %GL_FLOAT,SizeOf(Point3D),VarPtr(Vertex(1,1).x))
glColorPointer(3, %GL_FLOAT, SizeOf(Point3D), VarPtr(Vertex(1,1).red))
glTexCoordPointer(2, %GL_FLOAT, SizeOf(Point3D), VarPtr(Vertex(1,1).tu))
glDrawArrays(%GL_POINTS, 1, NbX*NbX )'40000 points
glDisableClientState(%GL_COLOR_ARRAY)
glDisableClientState(%GL_VERTEX_ARRAY)
'**************************************************
End Sub
Sub FillArray()
Single x, y, z, tu, tv, xMin, yMin, zMin, xMax, yMax, zMax, range, step1
'**********************************
xMin = -12 : yMin = -12: zMin = -12 : xMax = 12: yMax = 12 : zMax = 12
range = xMax - xMin
step1 = range / NbX
x = xMin: z = zMin : y = yMin
Integer b, a
For b=1 To NbZ
For a=1 To NbX
'y =(1 - x*x -z*z) * Exp(-1/2 * (x*x + z*z)) ' Hat
'y = Sin(10*(x^2+z^2))/5
y = Sin(Sqr(x*x+ z*z)) / Sqr(x*x + z*z)
Vertex(a,b).x = x*1
Vertex(a,b).y = y*5
Vertex(a,b).z = z*1
Vertex(a,b).red = 1 :Vertex(a,b).green = 1 :Vertex(a,b).blue = 1
Vertex(a,b).tu = a/NbX
Vertex(a,b).tv = b/NbZ
x + step1
Next a
x = xMin
z + step1
Next b
'**********************************
End Sub