Author Topic: GLU-primitives  (Read 3557 times)

0 Members and 1 Guest are viewing this topic.

docgen

  • Guest
GLU-primitives
« on: April 05, 2007 »
Hi!

Just a small demo of OpenGl GLU-primitives variations ( cristalls,triangle,etc..)
Not very spectacular, but not uninteresting.

It based on Relsofts quadrics-example, but is simplified (no SDL,no ligthing,no texturing,etc..)

LMB:change shapes(totally 20) /primitives(gluSphere, gluDisk, gluCylinder, gluPartialDisk)

RMB: change drawmode(GLU_SILHOUETTE,GLU_FILL,GLU_LINE,GLU_POINT)


Greetings
stef

Code: [Select]
'glu_primitives
'by stef
'LMB:change primitive
'RMB:change drawmode

const SCREENW = 800
const SCREENH = 600

screenres SCREENW,SCREENH,32 , 1 ,2 or 1


option explicit

'$include: "GL/gl.bi"
'$include: "GL/glu.bi"


declare sub drawscene()
declare sub getinput()

dim shared drawmode as integer
dim shared mode as integer
dim shared shape as integer=0
dim shared mousestatus as integer
dim shared buttons as integer

 
   glViewport 0, 0, SCREENW, SCREENH
   glMatrixMode GL_PROJECTION
   glLoadIdentity
   
   gluPerspective 20, SCREENW / SCREENH, 1, 100

    dim shared qobj_sphere as GLUquadricObj ptr
    dim shared qobj_Cylinder as GLUquadricObj ptr
    dim shared qobj_Disk as GLUquadricObj ptr
    dim shared qobj_Pdisk as GLUquadricObj ptr
   
    qobj_sphere = gluNewQuadric
    qobj_Cylinder = gluNewQuadric
    qobj_Disk = gluNewQuadric
    qobj_Pdisk = gluNewQuadric
   
 
   do
       
        getinput()

        drawscene()
   
      flip
       
   loop until multikey(1)

    gluDeleteQuadric qObj_sphere
    gluDeleteQuadric qObj_cylinder
    gluDeleteQuadric qObj_disk
    gluDeleteQuadric qObj_pdisk
 
    end


private sub DrawScene

    static angle as single
   
    gluQuadricDrawStyle qobj_sphere, drawmode
    gluQuadricDrawStyle qobj_Cylinder, drawmode
    gluQuadricDrawStyle qobj_Disk, drawmode 
    gluQuadricDrawStyle qobj_Pdisk, drawmode
   
 
    glClear  GL_COLOR_BUFFER_BIT OR GL_DEPTH_BUFFER_BIT
 
    glPushMatrix                   

    glTranslatef 0.0, 0.0, -1.0
    glPushMatrix                   
      glRotatef  angle,  1.0, 0.0, 0.0     
      glRotatef  angle,  0.0, 1.0, 0.0     
      glRotatef  angle,  0.0, 0.0, 1.0     
     
      select case shape
    case 0
        gluSphere qobj_sphere, 1.0, 20, 20  ' sphere
    case 1
        gluSphere qobj_sphere, 1.0, 3, 20
    case 2
        gluSphere qobj_sphere, 1.0, 4, 6 
    case 3
        gluSphere qobj_sphere, 1.0, 3, 2
    case 4
        gluSphere qobj_sphere, 1.0, 6, 3
    case 5
        gluDisk qobj_Disk,0.0, 1.0, 3, 1'triangle   
    case 6
         gluDisk qobj_Disk,0.9, 1.0, 4, 1'square
    case 7
         gluDisk qobj_Disk,0.6, 0.8, 30, 1'ring   
    case 8
         gluDisk qobj_Disk,0.6, 1.0, 5, 1'pentagon
    case 9
         gluDisk qobj_Disk,0.4, 1.0, 8, 1'octagon     
    case 10
         gluCylinder qobj_Cylinder, 0.4, 0.4, 1.0, 20, 20
    case 11
         gluCylinder qobj_Cylinder, 0.4, 0.4, 1.0, 4, 20     
    case 12
         gluCylinder qobj_Cylinder, 0.4, 0.0, 1.0, 20, 20'cone
    case 13
         gluCylinder qobj_Cylinder, 0.4, 0.0, 1.0, 4, 20'pyramid         
    case 14
         gluCylinder qobj_Cylinder, 0.8, 0.4, 1.0, 6, 6
    case 15     
         gluPartialDisk qobj_Pdisk,0.0, 1.0, 30, 1, -45, 270'pacman
    case 16     
         gluPartialDisk qobj_Pdisk,0.0, 1.0, 2, 1, 0, 240'arrow   
    case 17     
         gluPartialDisk qobj_Pdisk,0.6, 1.0, 3, 1,0,270   
    case 18     
         gluPartialDisk qobj_Pdisk,0.8, 1.0, 7, 1,0,300
    case 19     
         gluPartialDisk qobj_Pdisk,0.6, 1.0, 2, 1,0, 240   
         
    end select
       
 
    glPopMatrix
    glFlush

    angle = angle + 0.1 

end sub

sub getinput()
    dim x,y as integer
    GETMOUSE  x,y, , buttons
    locate 1,1
   
    if buttons=0 then
        mousestatus=0
    endif
   
    if mousestatus=0 then
        IF Bit(buttons, 0) THEN
           
            mousestatus=1
            shape = shape+1
            if shape>19 then shape=0
           
        endif

         IF Bit(buttons, 1) THEN
           
            mousestatus=1
            mode +=1
            if mode> 3 then mode=0
           
        endif
       
    endif
   
    select case mode
    case 0
    drawmode= GLU_SILHOUETTE
    case 1
    drawmode= GLU_FILL
    case 2
    drawmode= GLU_LINE
    case 3
    drawmode= GLU_POINT
   
    end select
   
end sub






Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: GLU-primitives
« Reply #1 on: April 05, 2007 »
Groovy ... I love it !!! Another fine code-snippet, Stef !!!
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: GLU-primitives
« Reply #2 on: April 05, 2007 »
Perfect code snippet, I like that very much as it shows how to get some simple opengl stuff moving around so have some good karma :) This will be useful to a lot of people.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: GLU-primitives
« Reply #3 on: April 05, 2007 »
Nice and thanks :)
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won: