It is currently Thu Sep 19, 2019 3:25 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: OpenGL Display List with Big Colored Points, different sizes
PostPosted: Thu Sep 12, 2019 7:33 am 
Offline
Addict
Addict

Joined: Sun Jun 25, 2006 7:28 pm
Posts: 1368
http://www.songho.ca/opengl/gl_displaylist.html
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:
Points = glGenLists_(1)
glNewList_(Points, #GL_COMPILE_AND_EXECUTE)
drawPointsDemo(); call whatever you want
glEndList_()
...
Repeat ...
 glCallList_(Points) ; just call the List
Until ...


why we need big points of different sizes and colors ? i think it is useful for Data visualization and for Fun

old Graphics cards will not display Big Points, especialy the points with Alpha, look the very Big tranparent red point
Image

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:
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

     
 


Top
 Profile  
Reply with quote  
 Post subject: Re: OpenGL Display List with Big Colored Points, different s
PostPosted: Sat Sep 14, 2019 1:43 pm 
Offline
Always Here
Always Here

Joined: Fri Oct 23, 2009 2:33 am
Posts: 5833
Location: Wales, UK
That's very useful stuff ApplePi

_________________
IdeasVacuum
If it sounds simple, you have not grasped the complexity.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye