Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
problem about bucle and opengl... please help.
#1
Well. I make a little code that reads a txt named file.dat , file is a txt file like this:

-1.00000000 -1.00000000 1.00000000
-1.00000000 1.00000000 1.00000000
1.00000000 1.00000000 1.00000000
1.00000000 -1.00000000 1.00000000
-1.00000000 -1.00000000 -1.00000000
-1.00000000 1.00000000 -1.00000000
1.00000000 1.00000000 -1.00000000
1.00000000 -1.00000000 -1.00000000


The code reads the numbers and paint in the screen the points. This code works ok:



Code:
option explicit

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

dim rtri as single, rquad as single
dim x as single, y as single, z as single, n as single

screen 18, 32, , 2

glViewport 0, 0, 640, 480 ' tamaño de la pantalla, hacer tambien elegible
glMatrixMode GL_PROJECTION
glLoadIdentity
gluPerspective 45.0, 640.0/480.0, 0.1, 100.0
glMatrixMode GL_MODELVIEW
glLoadIdentity

glShadeModel GL_flat
glClearColor 0.0, 0.0, 0.0, 1.0
glClearDepth 1.0
glEnable GL_DEPTH_TEST
glDepthFunc GL_LEQUAL
glHint GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST


glClear GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT
    glLoadIdentity
    glTranslatef 0, 0.0, -6.0
                 glpointsize(3)
    
  
For n= 1 to 8 'numero de vertices (el 8)
  
    OPEN "file.dat" FOR INPUT AS #1
    INPUT #1, x ,y ,z
            
        glBegin GL_points
                    glColor3f 1.0, 1, 1
                    glVertex3f x, y, z
            glEnd

next

CLOSE #1
    
    
flip

do
loop while inkey$ = ""

This code works ok, but when I do this bucle:

Code:
option explicit

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

dim rtri as single, rquad as single
dim x as single, y as single, z as single, n as single

screen 18, 32, , 2

glViewport 0, 0, 640, 480 ' tamaño de la pantalla, hacer tambien elegible
glMatrixMode GL_PROJECTION
glLoadIdentity
gluPerspective 45.0, 640.0/480.0, 0.1, 100.0
glMatrixMode GL_MODELVIEW
glLoadIdentity

glShadeModel GL_flat
glClearColor 0.0, 0.0, 0.0, 1.0
glClearDepth 1.0
glEnable GL_DEPTH_TEST
glDepthFunc GL_LEQUAL
glHint GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST

do

  glClear GL_COLOR_BUFFER_BIT or   GL_DEPTH_BUFFER_BIT
    glLoadIdentity
    glTranslatef 0, 0.0, -6.0
   glpointsize(3)
    
  
  For n= 1 to 8 'numero de vertices (el 8)
  
    OPEN "file.dat" FOR INPUT AS #1
    INPUT #1, x ,y ,z
            
         glBegin GL_points
                     glColor3f 1.0, 1, 1
                     glVertex3f x, y, z
                     glEnd

   next
  CLOSE #1

   flip
  
loop while inkey$ = ""

the only change I made is the do loop bucle.
All goes wrong...any help...thanks.
Reply
#2
You are opening a file 8 times and closing it once. I don't even know if it's legal code to open with the same filenumer multiple times w/o closing it first.

Bug here:

Code:
For n= 1 to 8 'numero de vertices (el 8)
    
    OPEN "file.dat" FOR INPUT AS #1
    INPUT #1, x ,y ,z
            
        glBegin GL_points
                     glColor3f 1.0, 1, 1
                     glVertex3f x, y, z
                     glEnd

   next
  CLOSE #1

Try this:

Code:
OPEN "file.dat" FOR INPUT AS #1

For n= 1 to 8 'numero de vertices (el 8)
    
    INPUT #1, x ,y ,z
            
        glBegin GL_points
                     glColor3f 1.0, 1, 1
                     glVertex3f x, y, z
                     glEnd

   next
  CLOSE #1
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#3
uhm i wouldn't start a seperate glbegin/glend for each point dude Smile
quote="NecrosIhsan"]
[Image: yagl1.png]
[/quote]
Reply
#4
Ok, thanks, I try it.

Another question, in freebasic, to start andmanipulate the opengl window, what is the best lib, glx or glut?
Reply
#5
or sdl...
Reply
#6
you can also use the native GFX lib as well.

but out of those 3 i pick sdl just so you can use some of it fuctions like input functions and the timer
Reply
#7
SDL
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)