Estoy intentando usar OpenGL pero no a través del componente INCOMPLETO de gambas, sino directamente con las librerías. Me pregunto si es posible. He hecho la consulta ne la lista internacional sin respuestas.
' (se necesita tener instaladas las librerias: libglut.so.3.9.0 - libGL.so - libGLU.so.1.3.1)
Private anguloCuboX As Single ' angulo del cubo
Private anguloCuboY As Single ' "
Private anguloEsfera As Single ' "
Private hazPerspectiva As Integer
Library "libglut:3.9.0"
Private Const GLUT_RGB As Integer = 0
Private Const GLUT_DOUBLE As Integer = 2
' void glutInit(int *argcp, char **argv)
' Initialize the GLUT library.
Private Extern glutInit(pargc As Pointer, argv As Pointer)
' void glutInitDisplayMode(unsigned int mode)
' Sets the initial display mode.
Private Extern glutInitDisplayMode(mode As Integer)
' void glutInitWindowPosition(int x, int y)
' Sets the initial window position.
Private Extern glutInitWindowPosition(x As Integer, y As Integer)
' void glutInitWindowSize(int width, int height)
' Sets the initial window size.
Private Extern glutInitWindowSize(width As Integer, height As Integer)
' int glutCreateWindow(char *name)
' Creates a top-level window.
Private Extern glutCreateWindow(name As String) As Integer
' void glutWireSphere( GLdouble radius, GLint slices, GLint stacks )
' Renders a solid or wireframe sphere respectively.
Private Extern glutWireSphere(radius As Float, slices As Integer, stacks As Integer)
' void glutSwapBuffers(void)
' Swaps the buffers of the current window if double buffered.
Private Extern glutSwapBuffers()
Library "libGL"
Private Const GL_DEPTH_TEST As Integer = &0B71
Private Const GL_COLOR_BUFFER_BIT As Integer = &4000
Private Const GL_DEPTH_BUFFER_BIT As Integer = &100
Private Const GL_QUADS As Integer = 7
Private Const GL_PROJECTION As Integer = &1701
Private Const GL_MODELVIEW As Integer = &1700
' void glClearColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha )
' Specify clear values for the color buffers.
Private Extern glClearColor(red As Single, green As Single, blue As Single, alpha As Single)
' void glEnable( GLenum cap )
' Enable or disable server-side GL capabilities.
Private Extern glEnable(cap As Integer)
' void glClear( GLbitfield mask)
' Clear buffers to preset values.
Private Extern glClear(mask As Integer)
' void glLoadIdentity( void )
' Replace the current matrix with the identity matrix.
Private Extern glLoadIdentity()
' void glTranslatef( GLfloat x, GLfloat y, GLfloat z )
' Multiply the current matrix by a translation matrix.
Private Extern glTranslatef(x As Single, y As Single, z As Single)
' void glRotatef( GLfloat angle, GLfloat x, GLfloat y, GLfloat z )
' Multiply the current matrix by a rotation matrix.
Private Extern glRotatef(GLangle As Single, x As Single, y As Single, z As Single)
' void glColor3f( GLfloat red, GLfloat green, GLfloat blue )
' Sets the current color.
Private Extern glColor3f(red As Single, green As Single, blue As Single)
' void glBegin( GLenum mode)
' Delimits the vertices of a primitive or a group of like primitives.
Private Extern glBegin(mode As Integer)
' void glVertex3f( GLfloat x, GLfloat y, GLfloat z )
' Specify a vertex.
Private Extern glVertex3f(x As Single, y As Single, z As Single)
' void glEnd( void )
' Delimit the vertices of a primitive or a group of like primitives.
Private Extern glEnd()
' void glFlush( void )
' Force execution of GL commands in finite time.
Private Extern glFlush()
' void glViewport( GLint x, GLint y, GLsizei width, GLsizei height )
' Set the viewport.
Private Extern glViewport(x As Integer, y As Integer, width As Integer, height As Integer)
' void glMatrixMode( GLenum mode )
' Specify which matrix is the current matrix.
Private Extern glMatrixMode(mode As Integer)
' void glOrtho( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near_val, GLdouble far_val )
' Multiply the current matrix with an orthographic matrix.
Private Extern glOrtho(GLleft As Float, GLright As Float, bottom As Float, top As Float, near_val As Float, far_val As Float)
Library "libGLU:1.3.1"
' void gluPerspective (GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar)
' Set up a perspective projection matrix.
Private Extern gluPerspective(fovy As Float, aspect As Float, zNear As Float, zFar As Float)
Public Sub Main()
Dim argcp As Pointer
glutInit(VarPtr(argcp), 0)
glutInitDisplayMode(GLUT_DOUBLE Or GLUT_RGB)
glutInitWindowPosition(100, 100)
glutInitWindowSize(400, 400)
glutCreateWindow("Cubo")
glClearColor(0, 0, 0, 0)
glEnable(GL_DEPTH_TEST)
While True
Display()
Reshape(400, 400)
Wend
End
Private Procedure Display()
glClear(GL_COLOR_BUFFER_BIT Or GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
glTranslatef(0.0, 0.0, -5.0)
glRotatef(anguloCuboX, 1.0, 0.0, 0.0)
glRotatef(anguloCuboY, 0.0, 1.0, 0.0)
drawCube()
glLoadIdentity()
glTranslatef(0.0, 0.0, -5.0)
glRotatef(anguloEsfera, 0.0, 1.0, 0.0)
glTranslatef(3.0, 0.0, 0.0)
glColor3f(1.0, 1.0, 1.0)
glutWireSphere(0.5, 8, 8)
glFlush()
glutSwapBuffers()
anguloCuboX += 0.1
anguloCuboY += 0.1
anguloEsfera += 0.2
End
Private Procedure drawCube()
glColor3f(1.0, 0.0, 0.0)
glBegin(GL_QUADS) ' cara frontal
glVertex3f(-1.0, -1.0, 1.0)
glVertex3f(1.0, -1.0, 1.0)
glVertex3f(1.0, 1.0, 1.0)
glVertex3f(-1.0, 1.0, 1.0)
glEnd()
glColor3f(0.0, 1.0, 0.0)
glBegin(GL_QUADS) ' cara trasera
glVertex3f(1.0, -1.0, -1.0)
glVertex3f(-1.0, -1.0, -1.0)
glVertex3f(-1.0, 1.0, -1.0)
glVertex3f(1.0, 1.0, -1.0)
glEnd()
glColor3f(0.0, 0.0, 1.0)
glBegin(GL_QUADS) ' cara lateral izq
glVertex3f(-1.0, -1.0, -1.0)
glVertex3f(-1.0, -1.0, 1.0)
glVertex3f(-1.0, 1.0, 1.0)
glVertex3f(-1.0, 1.0, -1.0)
glEnd()
glColor3f(1.0, 1.0, 0.0)
glBegin(GL_QUADS) ' cara lateral dcha
glVertex3f(1.0, -1.0, 1.0)
glVertex3f(1.0, -1.0, -1.0)
glVertex3f(1.0, 1.0, -1.0)
glVertex3f(1.0, 1.0, 1.0)
glEnd()
glColor3f(0.0, 1.0, 1.0)
glBegin(GL_QUADS) ' cara arriba
glVertex3f(-1.0, 1.0, 1.0)
glVertex3f(1.0, 1.0, 1.0)
glVertex3f(1.0, 1.0, -1.0)
glVertex3f(-1.0, 1.0, -1.0)
glEnd()
glColor3f(1.0, 0.0, 1.0)
glBegin(GL_QUADS) ' cara abajo
glVertex3f(1.0, -1.0, -1.0)
glVertex3f(1.0, -1.0, 1.0)
glVertex3f(-1.0, -1.0, 1.0)
glVertex3f(-1.0, -1.0, -1.0)
glEnd()
End
Private Procedure Reshape(width As Integer, height As Integer)
glViewport(0, 0, width, height)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
If hazPerspectiva Then
gluPerspective(60.0, CSingle(width) / CSingle(height), 1.0, 20.0)
Else
glOrtho(-4, 4, -4, 4, 1, 10)
Endif
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
End
'' Referencias:
' https://www.opengl.org/documentation/specs/glut/spec3/spec3.html
' https://www.opengl.org/sdk/docs/man/html/indexflat.php
' http://sabia.tic.udc.es/gc/Tutorial%20OpenGL/index.htm
Private anguloCuboX As Single ' angulo del cubo
Private anguloCuboY As Single ' "
Private anguloEsfera As Single ' "
Private hazPerspectiva As Integer
Library "libglut:3.9.0"
Private Const GLUT_RGB As Integer = 0
Private Const GLUT_DOUBLE As Integer = 2
' void glutInit(int *argcp, char **argv)
' Initialize the GLUT library.
Private Extern glutInit(pargc As Pointer, argv As Pointer)
' void glutInitDisplayMode(unsigned int mode)
' Sets the initial display mode.
Private Extern glutInitDisplayMode(mode As Integer)
' void glutInitWindowPosition(int x, int y)
' Sets the initial window position.
Private Extern glutInitWindowPosition(x As Integer, y As Integer)
' void glutInitWindowSize(int width, int height)
' Sets the initial window size.
Private Extern glutInitWindowSize(width As Integer, height As Integer)
' int glutCreateWindow(char *name)
' Creates a top-level window.
Private Extern glutCreateWindow(name As String) As Integer
' void glutWireSphere( GLdouble radius, GLint slices, GLint stacks )
' Renders a solid or wireframe sphere respectively.
Private Extern glutWireSphere(radius As Float, slices As Integer, stacks As Integer)
' void glutSwapBuffers(void)
' Swaps the buffers of the current window if double buffered.
Private Extern glutSwapBuffers()
Library "libGL"
Private Const GL_DEPTH_TEST As Integer = &0B71
Private Const GL_COLOR_BUFFER_BIT As Integer = &4000
Private Const GL_DEPTH_BUFFER_BIT As Integer = &100
Private Const GL_QUADS As Integer = 7
Private Const GL_PROJECTION As Integer = &1701
Private Const GL_MODELVIEW As Integer = &1700
' void glClearColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha )
' Specify clear values for the color buffers.
Private Extern glClearColor(red As Single, green As Single, blue As Single, alpha As Single)
' void glEnable( GLenum cap )
' Enable or disable server-side GL capabilities.
Private Extern glEnable(cap As Integer)
' void glClear( GLbitfield mask)
' Clear buffers to preset values.
Private Extern glClear(mask As Integer)
' void glLoadIdentity( void )
' Replace the current matrix with the identity matrix.
Private Extern glLoadIdentity()
' void glTranslatef( GLfloat x, GLfloat y, GLfloat z )
' Multiply the current matrix by a translation matrix.
Private Extern glTranslatef(x As Single, y As Single, z As Single)
' void glRotatef( GLfloat angle, GLfloat x, GLfloat y, GLfloat z )
' Multiply the current matrix by a rotation matrix.
Private Extern glRotatef(GLangle As Single, x As Single, y As Single, z As Single)
' void glColor3f( GLfloat red, GLfloat green, GLfloat blue )
' Sets the current color.
Private Extern glColor3f(red As Single, green As Single, blue As Single)
' void glBegin( GLenum mode)
' Delimits the vertices of a primitive or a group of like primitives.
Private Extern glBegin(mode As Integer)
' void glVertex3f( GLfloat x, GLfloat y, GLfloat z )
' Specify a vertex.
Private Extern glVertex3f(x As Single, y As Single, z As Single)
' void glEnd( void )
' Delimit the vertices of a primitive or a group of like primitives.
Private Extern glEnd()
' void glFlush( void )
' Force execution of GL commands in finite time.
Private Extern glFlush()
' void glViewport( GLint x, GLint y, GLsizei width, GLsizei height )
' Set the viewport.
Private Extern glViewport(x As Integer, y As Integer, width As Integer, height As Integer)
' void glMatrixMode( GLenum mode )
' Specify which matrix is the current matrix.
Private Extern glMatrixMode(mode As Integer)
' void glOrtho( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near_val, GLdouble far_val )
' Multiply the current matrix with an orthographic matrix.
Private Extern glOrtho(GLleft As Float, GLright As Float, bottom As Float, top As Float, near_val As Float, far_val As Float)
Library "libGLU:1.3.1"
' void gluPerspective (GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar)
' Set up a perspective projection matrix.
Private Extern gluPerspective(fovy As Float, aspect As Float, zNear As Float, zFar As Float)
Public Sub Main()
Dim argcp As Pointer
glutInit(VarPtr(argcp), 0)
glutInitDisplayMode(GLUT_DOUBLE Or GLUT_RGB)
glutInitWindowPosition(100, 100)
glutInitWindowSize(400, 400)
glutCreateWindow("Cubo")
glClearColor(0, 0, 0, 0)
glEnable(GL_DEPTH_TEST)
While True
Display()
Reshape(400, 400)
Wend
End
Private Procedure Display()
glClear(GL_COLOR_BUFFER_BIT Or GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
glTranslatef(0.0, 0.0, -5.0)
glRotatef(anguloCuboX, 1.0, 0.0, 0.0)
glRotatef(anguloCuboY, 0.0, 1.0, 0.0)
drawCube()
glLoadIdentity()
glTranslatef(0.0, 0.0, -5.0)
glRotatef(anguloEsfera, 0.0, 1.0, 0.0)
glTranslatef(3.0, 0.0, 0.0)
glColor3f(1.0, 1.0, 1.0)
glutWireSphere(0.5, 8, 8)
glFlush()
glutSwapBuffers()
anguloCuboX += 0.1
anguloCuboY += 0.1
anguloEsfera += 0.2
End
Private Procedure drawCube()
glColor3f(1.0, 0.0, 0.0)
glBegin(GL_QUADS) ' cara frontal
glVertex3f(-1.0, -1.0, 1.0)
glVertex3f(1.0, -1.0, 1.0)
glVertex3f(1.0, 1.0, 1.0)
glVertex3f(-1.0, 1.0, 1.0)
glEnd()
glColor3f(0.0, 1.0, 0.0)
glBegin(GL_QUADS) ' cara trasera
glVertex3f(1.0, -1.0, -1.0)
glVertex3f(-1.0, -1.0, -1.0)
glVertex3f(-1.0, 1.0, -1.0)
glVertex3f(1.0, 1.0, -1.0)
glEnd()
glColor3f(0.0, 0.0, 1.0)
glBegin(GL_QUADS) ' cara lateral izq
glVertex3f(-1.0, -1.0, -1.0)
glVertex3f(-1.0, -1.0, 1.0)
glVertex3f(-1.0, 1.0, 1.0)
glVertex3f(-1.0, 1.0, -1.0)
glEnd()
glColor3f(1.0, 1.0, 0.0)
glBegin(GL_QUADS) ' cara lateral dcha
glVertex3f(1.0, -1.0, 1.0)
glVertex3f(1.0, -1.0, -1.0)
glVertex3f(1.0, 1.0, -1.0)
glVertex3f(1.0, 1.0, 1.0)
glEnd()
glColor3f(0.0, 1.0, 1.0)
glBegin(GL_QUADS) ' cara arriba
glVertex3f(-1.0, 1.0, 1.0)
glVertex3f(1.0, 1.0, 1.0)
glVertex3f(1.0, 1.0, -1.0)
glVertex3f(-1.0, 1.0, -1.0)
glEnd()
glColor3f(1.0, 0.0, 1.0)
glBegin(GL_QUADS) ' cara abajo
glVertex3f(1.0, -1.0, -1.0)
glVertex3f(1.0, -1.0, 1.0)
glVertex3f(-1.0, -1.0, 1.0)
glVertex3f(-1.0, -1.0, -1.0)
glEnd()
End
Private Procedure Reshape(width As Integer, height As Integer)
glViewport(0, 0, width, height)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
If hazPerspectiva Then
gluPerspective(60.0, CSingle(width) / CSingle(height), 1.0, 20.0)
Else
glOrtho(-4, 4, -4, 4, 1, 10)
Endif
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
End
'' Referencias:
' https://www.opengl.org/documentation/specs/glut/spec3/spec3.html
' https://www.opengl.org/sdk/docs/man/html/indexflat.php
' http://sabia.tic.udc.es/gc/Tutorial%20OpenGL/index.htm