instead of contineously calcaulating the points again and again inside the render loop, compile everything to one list then just call that list inside the render loop
Code: Select all
Points = glGenLists_(1)
glNewList_(Points, #GL_COMPILE_AND_EXECUTE)
drawPointsDemo(); call whatever you want
glEndList_()
...
Repeat ...
glCallList_(Points) ; just call the List
Until ...
old Graphics cards will not display Big Points, especialy the points with Alpha, look the very Big tranparent red point
tested with PB v5.71 in xp/32 and win7/x64
Experiment: comment lines 66, 67
glEnable_(#GL_POINT_SMOOTH);
glHint_(#GL_POINT_SMOOTH_HINT, #GL_NICEST);
and you will get square points not round points
Code: Select all
Declare drawPointsDemo()
Structure vertex
x.f ; x position
y.f
z.f
r.f ; red color
g.f
b.f
a.f ; alpha
EndStructure
Macro RandomFloat(Steps)
;https://www.purebasic.fr/english/viewtopic.php?f=13&t=73488#p541153
(1.0 * Random(Steps) / Steps#.0)
EndMacro
Global v1.vertex
Global rot.f
Global Points.l
Define event, quit
ExamineDesktops()
Global width.f = DesktopWidth(0)-40
Global height.f = DesktopHeight(0)-40
OpenWindow(0, 0, 0, DesktopWidth(0), DesktopHeight(0), "OpenGL demo ... Display List with Big Points, different sizes and colors")
SetWindowColor(0, RGB(200,220,200))
OpenGLGadget(0, 0, 0, width , height, #PB_OpenGL_Keyboard )
Points = glGenLists_(1)
glNewList_(Points, #GL_COMPILE_AND_EXECUTE)
drawPointsDemo();
glEndList_()
SetActiveGadget(0)
glOrtho_(-150,150,-150,150,-150,150)
;glOrtho_(-100,100,-100,100,-100,100)
gluLookAt_( 0, 30, 35, ; the camera looking from position 0,0,dist to 0,0,0 from above
0, 0, 0,
0, 1, 0 )
Repeat
Repeat
event = WindowEvent()
If event = #PB_Event_CloseWindow
quit = #True
EndIf
key = GetGadgetAttribute(0,#PB_OpenGL_Key )
If key = #PB_Shortcut_Escape ; Esc key to exit
quit = #True
EndIf
Until event = 0 Or quit = #True
glEnable_(#GL_POINT_SMOOTH);
glHint_(#GL_POINT_SMOOTH_HINT, #GL_NICEST);
glEnable_(#GL_BLEND);
glBlendFunc_(#GL_SRC_ALPHA, #GL_ONE_MINUS_SRC_ALPHA);
glClear_(#GL_COLOR_BUFFER_BIT)
glMatrixMode_(#GL_MODELVIEW);
glLoadIdentity_();
rot+1
If rot=361:rot=0:EndIf
glRotatef_(rot, 0,1,0)
glCallList_(Points)
SetGadgetAttribute(0, #PB_OpenGL_FlipBuffers, #True)
Delay(5)
Until Event = #PB_Event_CloseWindow Or quit = #True
glDeleteLists_(Points, 1)
Procedure drawPointsDemo()
size.f = 5
R.f = 30.0; // Radius of helix.
t.f = -30*#PI; // Angle parameter along helix.
;For i=1 To 20
While t <= 30 * #PI
v1\x = R * Cos(t): v1\y= t : v1\z = R * Sin(t) - 0.0
v1\r=RandomFloat(3) : v1\g=RandomFloat(3): v1\b =RandomFloat(3) : v1\a = 1
;draw a point with size, color, And location
glPointSize_(size);
glBegin_(#GL_POINTS);
glColor4f_(v1\r, v1\g, v1\b, v1\a);
glVertex3f_(v1\x, v1\y, v1\z)
glEnd_();
t = t+(#PI/5)
size = Random(15, 5)
Wend
glPointSize_(70);
glBegin_(#GL_POINTS);
glColor4f_(1, 0.3, 0.1, 0.7);
glVertex3f_(0, 70,0)
glEnd_();
glLineWidth_(3)
glBegin_(#GL_LINES)
glColor4f_(1,0,0,1)
glVertex3f_(-30, 0, 0);
glVertex3f_(30, 0, 0)
glColor4f_(1,1,1,1)
glVertex3f_(0, -60,0);
glVertex3f_(0, 60,0);
glEnd_()
EndProcedure