OpenGL?

Just starting out? Need help? Post your questions and find answers here.
Swos2009
Enthusiast
Enthusiast
Posts: 112
Joined: Sat Nov 08, 2008 8:19 pm

OpenGL?

Post by Swos2009 »

I did love learn OpenGl but one things put me off is that there is no Documents or Example or Tutorials for OpenGL.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: OpenGL?

Post by IdeasVacuum »

If you outline what you wish to do, somebody on this forum should be able to help you. If you search the forum, there are a number of posts about OpenGL.
OpenGL Example
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Demivec
Addict
Addict
Posts: 4270
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: OpenGL?

Post by Demivec »

Swos2009 wrote:I did love learn OpenGl but one things put me off is that there is no Documents or Example or Tutorials for OpenGL.
What exactly is your 'coding question'? :mrgreen:
Swos2009
Enthusiast
Enthusiast
Posts: 112
Joined: Sat Nov 08, 2008 8:19 pm

Re: OpenGL?

Post by Swos2009 »

What exactly is your 'coding question'?
I want to learn more about OpenGL as I love the rotation of 3D which make look so easy instead of coding lots of Maths to do it!


I start move round the triangles but why it is slow?

Code: Select all

EnableExplicit
Global RollAxisX.f
Global RollAxisY.f
Global RollAxisZ.f

Global RotateSpeedX.f = 2 ; The speed of the rotation For the 3 axis
Global RotateSpeedY.f = 2
Global RotateSpeedZ.f = 2

OpenWindow(0, 270, 100, 640, 480, "Cross-platform OpenGL demo")
SetWindowColor(0, 0)
OpenGLGadget(0, 0, 0, WindowWidth(0) , WindowHeight(0))

Repeat
  glViewport_(0, 0, WindowWidth(0), WindowHeight(0))
  glMatrixMode_(#GL_PROJECTION)
  glLoadIdentity_()
  gluPerspective_(30.0, Abs(WindowWidth(0) / WindowHeight(0)), 0.1, 500.0)
  glMatrixMode_(#GL_MODELVIEW)
  glLoadIdentity_()
  glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
  glLoadIdentity_()
  glTranslatef_(0.0, 0.0, -8.0)
  glColor3f_(1.0, 1.0, 1.0)
  
  glRotatef_ (RollAxisX, 1.0, 0, 0) ; rotate around X axis
  glRotatef_ (RollAxisY, 0, 1.0, 0) ; rotate around Y axis
  glRotatef_ (RollAxisZ, 0, 0, 1.0) ; rotate around Z axis
 
  RollAxisX + RotateSpeedX 
  RollAxisY + RotateSpeedY 
  RollAxisZ + RotateSpeedZ 

  glBegin_(#GL_TRIANGLES)      ; Start drawing a triangle
  glColor3f_ ( 1.0,  0.0, 0.0) ; Set top point of triangle to Red
  glVertex3f_( 0.0,  1.0, 0.0) ; First point of the triangle
  glColor3f_ ( 0.0,  1.0, 0.0) ; Set left point of triangle to Green
  glVertex3f_(-1.0, -1.0, 0.0) ; Second point of the triangle
  glColor3f_ ( 0.0,  0.0, 1.0) ; Set right point of triangle to Blue
  glVertex3f_( 1.0, -1.0, 0.0) ; Third point of the triangle
  glEnd_()                     ; Done drawing the triangle
 
  SetGadgetAttribute(0, #PB_OpenGL_FlipBuffers, #True)
Until WaitWindowEvent() = #PB_Event_CloseWindow
infratec
Always Here
Always Here
Posts: 7625
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: OpenGL?

Post by infratec »

Hi,

you simply draw it only when an event happen.
So move always your mouse, or ... (possible without code change :mrgreen: )
remove the Wait from WaitWindowEvent(), or ... (easiest way for your code)
create a thread, or ...
use a timer. (demonstrated below)

Code: Select all

EnableExplicit
Global RollAxisX.f
Global RollAxisY.f
Global RollAxisZ.f

Global RotateSpeedX.f = 2 ; The speed of the rotation For the 3 axis
Global RotateSpeedY.f = 2
Global RotateSpeedZ.f = 2

Procedure Draw()
  glViewport_(0, 0, WindowWidth(0), WindowHeight(0))
  glMatrixMode_(#GL_PROJECTION)
  glLoadIdentity_()
  gluPerspective_(30.0, Abs(WindowWidth(0) / WindowHeight(0)), 0.1, 500.0)
  glMatrixMode_(#GL_MODELVIEW)
  glLoadIdentity_()
  glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
  glLoadIdentity_()
  glTranslatef_(0.0, 0.0, -8.0)
  glColor3f_(1.0, 1.0, 1.0)
 
  glRotatef_ (RollAxisX, 1.0, 0, 0) ; rotate around X axis
  glRotatef_ (RollAxisY, 0, 1.0, 0) ; rotate around Y axis
  glRotatef_ (RollAxisZ, 0, 0, 1.0) ; rotate around Z axis
 
  RollAxisX + RotateSpeedX
  RollAxisY + RotateSpeedY
  RollAxisZ + RotateSpeedZ

  glBegin_(#GL_TRIANGLES)      ; Start drawing a triangle
  glColor3f_ ( 1.0,  0.0, 0.0) ; Set top point of triangle to Red
  glVertex3f_( 0.0,  1.0, 0.0) ; First point of the triangle
  glColor3f_ ( 0.0,  1.0, 0.0) ; Set left point of triangle to Green
  glVertex3f_(-1.0, -1.0, 0.0) ; Second point of the triangle
  glColor3f_ ( 0.0,  0.0, 1.0) ; Set right point of triangle to Blue
  glVertex3f_( 1.0, -1.0, 0.0) ; Third point of the triangle
  glEnd_()                     ; Done drawing the triangle
 
  SetGadgetAttribute(0, #PB_OpenGL_FlipBuffers, #True)
EndProcedure


Define Event.i

OpenWindow(0, 270, 100, 640, 480, "Cross-platform OpenGL demo")
SetWindowColor(0, 0)
OpenGLGadget(0, 0, 0, WindowWidth(0) , WindowHeight(0))

AddWindowTimer(0, 1, 25)

Repeat
  
  Event = WaitWindowEvent()
  If Event = #PB_Event_Timer
    If EventTimer() = 1
      Draw()
    EndIf
  EndIf
  
Until Event = #PB_Event_CloseWindow
Bernd
Swos2009
Enthusiast
Enthusiast
Posts: 112
Joined: Sat Nov 08, 2008 8:19 pm

Re: OpenGL?

Post by Swos2009 »

thanks Bernd.

Timer is important to make things smooth :)

One things bugs me that I try do 3D Cubes by using glBegin(#GL_POLYGON) but I get the error saying it isnt functions....
Post Reply