FB+Glu+rotate problem

New to FreeBASIC? Post your questions here.
Post Reply
PavelUT
Posts: 78
Joined: Jun 14, 2021 14:42

FB+Glu+rotate problem

Post by PavelUT »

Raspberry 4B system, OS Linux
Hello! I have a question about using Glut.
Moreover, I want to preserve "sort of compatibility" with the C language and use the glu functions.
I want the rectangle to rotate, and it does, but only when I resize the window.
I have the impression that glutMainLoop( ) in freebasic
it works incorrectly.
I'm right? Or just something needs to be changed in the program?

Code: Select all

'' Issue: Rectangle only rotates when window is resized
''Need: constant rotation
#include once "\GL\glut.bi"
'' glutMainLoop( ) doesn't seem to work properly???
Dim shared As Single rtri=0  ''Rotation angle for rectangle
sub display cdecl( )  '' GLUT callbacks are always CDECL
    glClear( GL_COLOR_BUFFER_BIT ) 

    glBegin( GL_POLYGON ) 
    	glColor3ub 0,0,255 'blue square
        glVertex3f( -0.5, -0.5, 0 ) 
        glVertex3f( -0.5, 0.5, 0 ) 
        glVertex3f( 0.5, 0.5, 0 ) 
        glVertex3f( 0.5, -0.5, 0 ) 
    glEnd( ) 
    	glRotatef (rtri, 0, 1, 0)
         'rtri=rtri+5
    glFlush( ) 
    rtri=rtri+5
end sub

'int main ;)
    '' this is needed to make GLUT happy, passing 0 and NULL won't work
    glutInit( 1, strptr( " " ) )

    glutCreateWindow( "simple" ) 
    glutDisplayFunc( @display ) 

    glutMainLoop( ) 
' end main
end
PavelUT
Posts: 78
Joined: Jun 14, 2021 14:42

Re: FB+Glu+rotate problem

Post by PavelUT »

Hello, I managed to get the triangle to rotate. Here is the program. Any additions or suggestions?

Code: Select all

#include once "\GL\glut.bi"

Dim shared As Single rtri=0 ''Угол поворота для треугольника
sub renderScene()  
glClear(GL_COLOR_BUFFER_BIT)
glPushMatrix()
glRotatef(rtri,0.0,1.0,0.0)
'glColor3f(1.0,1.0,1.0)
	glBegin(GL_TRIANGLES)
		glColor3ub 0,0,255 'blue triangle
		glVertex3f(-0.5,-0.5,0.0)
		glVertex3f(0.0,0.5,0.0)
		glVertex3f(0.5,-0.5,0.0)
	glEnd( ) 
glPopMatrix()
glutSwapBuffers()
end sub

sub SetupOpGl()
	glClearColor (0.5f, 0.5f, 0.5f, 1.0f) 'установка цвета заднего фона
end sub

sub SpinTriangle()
rtri=rtri+0.2
'rtri=rtri+0.00005
glutPostRedisplay()
end sub

'int main ;)
    '' this is needed to make GLUT happy, passing 0 and NULL won't work
    glutInitDisplayMode(GLUT_DEPTH or GLUT_DOUBLE or GLUT_RGBA)
    glutInitWindowPosition(100,100)
    glutInitWindowSize(800,600)
    glutInit( 1, strptr( " " ) )

    glutCreateWindow( "rotate2" ) 
    glutDisplayFunc( @renderScene() )
    SetupOpGl()
    glutIdleFunc(@SpinTriangle())
    glutMainLoop( ) 
' end main ;)
end

Post Reply