More OpenGL stuff

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by traumatic.
Originally posted by halo

Trauma, your example is not perspective. It's orthogonal, just from a different angle. Objects in the distance would not appear smaller.
I know - I didn't code it...
I just wanted to show you what's going on but I already mentioned you'd better try modelview/gluPerspective().

Danilo showed you a code example how to properly setup a perspective projection (ReSizeGLScene()). You can also use glFrustum() instead of gluPerspective() if you want full control.

Regarding your Glut-Example: I'll have a look at it later, maybe I can find out what's wrong.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by traumatic.
Originally posted by halo
However, it doesn't display anything for me, and I have no idea why.
it's later now :)

this might be the solution:
you didn't initialize the desired display mode, a 'standard' displaymode would be:

Code: Select all

; GLUT Display mode bit masks
#GLUT_RGB     =  0
#GLUT_DOUBLE  =  2
#GLUT_DEPTH   = 16

glutInitDisplayMode_(#GLUT_DOUBLE | #GLUT_RGB | #GLUT_DEPTH)
can you see something now?
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by halo.

Here we go. This should be a helpful example for anyone trying to initialize GLUT. Thanks for the tip:

IncludeFile "OpenGl.pb"

Procedure Display()
glClear_(#GL_COLOR_BUFFER_BIT|#GL_DEPTH_BUFFER_BIT)
glMatrixMode_(#GL_ModelView)
glLoadIdentity_()

x.f=0.5
m.f=-0.5

glBegin_ (#GL_POLYGON)
glNormal3f_(0.0,0.0,-1.0)
glVertex3f_(m,x,m)
glVertex3f_(m,m,m)
glVertex3f_(x,m,m)
glVertex3f_(x,x,m)
glEnd_()

glBegin_ (#GL_POLYGON)
glNormal3f_(0.0,0.0,1.0)
glVertex3f_(m,m,x)
glVertex3f_(m,x,x)
glVertex3f_(x,x,x)
glVertex3f_(x,m,x)
glEnd_()

glBegin_ (#GL_POLYGON)
glNormal3f_(-1.0,0.0,0.0)
glVertex3f_(m,m,m)
glVertex3f_(m,x,m)
glVertex3f_(m,x,x)
glVertex3f_(m,m,x)
glEnd_()

glBegin_ (#GL_POLYGON)
glNormal3f_(1.0,0.0,0.0)
glVertex3f_(x,m,x)
glVertex3f_(x,x,x)
glVertex3f_(x,x,m)
glVertex3f_(x,m,m)
glEnd_()

glBegin_ (#GL_POLYGON)
glNormal3f_(0.0,1.0,0.0)
glVertex3f_(x,x,m)
glVertex3f_(x,x,x)
glVertex3f_(m,x,x)
glVertex3f_(m,x,m)
glEnd_()

glBegin_ (#GL_POLYGON)
glNormal3f_(0.0,-1.0,0.0)
glVertex3f_(m,m,m)
glVertex3f_(m,m,x)
glVertex3f_(x,m,x)
glVertex3f_(x,m,m)
glEnd_()

glutSwapBuffers_()
EndProcedure

Global Argc.l : Argc = 1
Global Argv.s : Argv = ""
glutInit_(@Argc,Argv)
glutInitWindowSize_(200,200 )

#GLUT_RGB = 0
#GLUT_DOUBLE = 2
#GLUT_DEPTH = 16

glutInitDisplayMode_(#GLUT_DOUBLE | #GLUT_RGB | #GLUT_DEPTH)
glutInitWindowPosition_(100,100)
glutCreateWindow_("OpenGL Test")
glClearColor_(0.0,0.0,1.0,0.0)
glShadeModel_(#GL_FLAT)
glutDisplayFunc_(@Display())

glutMainLoop_()
End
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by halo.

GL perspective still gives me a blank screen, though. Not sure what is wrong.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Danilo.

So you have a problem with gluPerspectivef_() ??

Maybe thats the reason my code doesnt work for you (you can try to remove this 1 line).
Did you try to update the OpenGL drivers for your card ??

cya,
...Danilo

(registered PureBasic user)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by halo.

I don't have problems running games in OpenGL. The thing is, I am not sure if it's the code or my machine. If you can see something with the above code with perspective(), then please post it and I'll check.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by traumatic.

gluPerspective() shouldn't be a graphicscard or driver problem.
It's just a glu-implementation of glFrustum() which is supported by every hardware afaik.

Here's a working perspective version of your glut-cube.
I also added some light for you.

To make this work, delete the two lines with glMatrixMode_() and glLoadIdentity_() in your Display()-procedure (you don't change it so you don't need it inside the display loop anyway) and call the following procedure right after the call to glutDisplayFunc_(@Display()).

Code: Select all

Procedure Init()
  ; setup lights
  Dim light_diff.f(3)
    light_diff(0)=1.0
    light_diff(1)=0.0
    light_diff(2)=0.0
    light_diff(3)=1.0

  Dim light_pos.f(3)
    light_pos(0)=1.0
    light_pos(1)=1.0
    light_pos(2)=1.0
    light_pos(3)=0.0

  ; Enable light
  glLightfv_(#GL_LIGHT0, #GL_DIFFUSE, @light_diff())
  glLightfv_(#GL_LIGHT0, #GL_POSITION, @light_pos())
  glEnable_(#GL_LIGHT0)
  glEnable_(#GL_LIGHTING)

  ; depth buffering for hidden surface removal
  glEnable_(#GL_DEPTH_TEST)

  ; this sets up your desired view
  glMatrixMode_(#GL_PROJECTION)
  gluPerspectivef_(40.0, 1.0, 1.0, 10.0)
  glMatrixMode_(#GL_MODELVIEW)

  tz.f=-3.0 ; - play around with this value

  ; just to show it's working
  glTranslatef_(0.0, 0.0, tz)
  glRotatef_(60.0, 1.0, 1.0, 0.0)
EndProcedure
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Rings.

Watch this guy postings in other forums:

http://www.blitzbasic.com/cgi-bin/showp ... opic=12232

in my opinion its wasted time to answer halo's questions.


Its a long way to the top if you wanna .....CodeGuru
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by halo.

Yes, I am going to sell my copy of PB if I can't get this working. Do you have a problem with that?

I think it's bad practice to not post the entire code when dealing with something like this. Now if this exact code works on your machine and not on mine, then there's definitely a hradware problem. I think I did exactly as you said:

IncludeFile "OpenGl.pb"
Global Argc.l : Argc = 1
Global Argv.s : Argv = ""
glutInit_(@Argc,Argv)
glutInitWindowSize_(200,200 )
#GLUT_RGB = 0
#GLUT_DOUBLE = 2
#GLUT_DEPTH = 16
glutInitDisplayMode_(#GLUT_DOUBLE | #GLUT_RGB | #GLUT_DEPTH)
glutInitWindowPosition_(100,100)
glutCreateWindow_("OpenGL Test")
glClearColor_(0.0,0.0,1.0,0.0)
glShadeModel_(#GL_FLAT)

Procedure Init()
; setup lights
Dim light_diff.f(3)
light_diff(0)=1.0
light_diff(1)=0.0
light_diff(2)=0.0
light_diff(3)=1.0

Dim light_pos.f(3)
light_pos(0)=1.0
light_pos(1)=1.0
light_pos(2)=1.0
light_pos(3)=0.0

; Enable light
glLightfv_(#GL_LIGHT0, #GL_DIFFUSE, @light_diff())
glLightfv_(#GL_LIGHT0, #GL_POSITION, @light_pos())
glEnable_(#GL_LIGHT0)
glEnable_(#GL_LIGHTING)

; depth buffering for hidden surface removal
glEnable_(#GL_DEPTH_TEST)

; this sets up your desired view
glMatrixMode_(#GL_PROJECTION)
gluPerspectivef_(40.0, 1.0, 1.0, 10.0)
glMatrixMode_(#GL_MODELVIEW)

tz.f=-3.0 ; - play around with this value

; just to show it's working
glTranslatef_(0.0, 0.0, tz)
glRotatef_(60.0, 1.0, 1.0, 0.0)
EndProcedure

Procedure Display()
init()
glClear_(#GL_COLOR_BUFFER_BIT|#GL_DEPTH_BUFFER_BIT)
;glMatrixMode_(#GL_Projection)
;glLoadIdentity_()
;gluPerspectivef_(80.0,1.0,0.1,100.0)
;glTranslatef_(0.0,5.0,0.0)
;glMatrixMode_(#GL_ModelView)
;glLoadIdentity_()
x.f=0.5
m.f=-0.5
glBegin_ (#GL_POLYGON)
glNormal3f_(0.0,0.0,-1.0)
glVertex3f_(m,x,m)
glVertex3f_(m,m,m)
glVertex3f_(x,m,m)
glVertex3f_(x,x,m)
glEnd_()
glBegin_ (#GL_POLYGON)
glNormal3f_(0.0,0.0,1.0)
glVertex3f_(m,m,x)
glVertex3f_(m,x,x)
glVertex3f_(x,x,x)
glVertex3f_(x,m,x)
glEnd_()
glBegin_ (#GL_POLYGON)
glNormal3f_(-1.0,0.0,0.0)
glVertex3f_(m,m,m)
glVertex3f_(m,x,m)
glVertex3f_(m,x,x)
glVertex3f_(m,m,x)
glEnd_()
glBegin_ (#GL_POLYGON)
glNormal3f_(1.0,0.0,0.0)
glVertex3f_(x,m,x)
glVertex3f_(x,x,x)
glVertex3f_(x,x,m)
glVertex3f_(x,m,m)
glEnd_()
glBegin_ (#GL_POLYGON)
glNormal3f_(0.0,1.0,0.0)
glVertex3f_(x,x,m)
glVertex3f_(x,x,x)
glVertex3f_(m,x,x)
glVertex3f_(m,x,m)
glEnd_()
glBegin_ (#GL_POLYGON)
glNormal3f_(0.0,-1.0,0.0)
glVertex3f_(m,m,m)
glVertex3f_(m,m,x)
glVertex3f_(x,m,x)
glVertex3f_(x,m,m)
glEnd_()
glutSwapBuffers_()
EndProcedure

glutDisplayFunc_(@Display())
glutMainLoop_()
End
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by halo.

Oh, I also tried this:

glutDisplayFunc_(@Display())
init()
glutMainLoop_()
End

Same blank results.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by traumatic.

Yes, this works fine for me and I wanted you to put the call to Init() like this:

Code: Select all

[...]
glClearColor_(0.0,0.0,1.0,0.0) 
glShadeModel_(#GL_FLAT)
glutDisplayFunc_(@Display()) 
Init()
glutMainLoop_()
End
because there's no need to setup everything (lights etc.) every loop... but you did that already.
Yes, I am going to sell my copy of PB if I can't get this working.
You want to sell PureBasic because you can't code?
Well, Go on then!
I think it's bad practice to not post the entire code when dealing with something like this.
Something like what? The obvious?
Sorry but I think it's even worse to spam this forum with useless posts like writing two articles instead of one just because you don't know how to use the 'edit'-feature...
And sorry if you couldn't follow my explanations but hey.... you could! Maybe the problem is that I like people to actually think about what they're doing instead of a simple copy&paste.

Nevertheless, if you can't see anything I'd really like to know what Graphicscard you've got. Think you can tell me?
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by halo.

God, you guys are assholes.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by traumatic.

please, don't say 'you guys' if you're talking about me.
credit to whom it deserves! :)




--------
good programmers don't comment their code. it was hard to write - should be hard to read!
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.
Originally posted by halo

God, you guys are assholes.
Please stop that immediately. I don't care about users which even don't respect elementary courtesy rules. Better sell your copy of PB and never post again on this forum.

Fred - AlphaSND
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Franco.

@halo
I read this topic and I can't see why you are so upset - and use such words.
I suppose you are very young and don't know how to act in a polite way outside the family you are living in.
Some people (with more OpenGL experience that I have...) tryed to help you and to give you some hint's.
But what I can see is, that you are insulting this people in an very arrogant way.
Why?

What I can also see in the Blitz forum is, that some people over there don't share your opinion too.
So think about it and change your behaviour.

YOU CAN'T CUT THE TREE WHERE YOU ARE SITTING. TRY IT AND YOU WILL SEE!

If you have some questions - ask them in a polite way, never be arrogant or insulting.
Otherwise you get no answer - even in the Blitz forum.

BTW: OpenGL is not a easy thing to code.
Some people here try to get it running and are so kind to share their knowledge with others in this forum.
So be polite in the future and think about your behaviour...

Have a nice day...
Franco

Sometimes you have to go a lonely way to accomplish genius things.
Post Reply