OpenGL?
Posted: Sun Jul 05, 2015 6:28 pm
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'?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.
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!What exactly is your 'coding question'?
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
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