Freeglut Troubles

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
Post Reply
DarkKoder
Posts: 18
Joined: Apr 08, 2009 1:03

Freeglut Troubles

Post by DarkKoder »

im trying to compile this to create a window using glut but im not sure why it works i get the error "Unable to locate component freeglut.dll" and i dont understand why i get an error using glutdisplayfunc () so i commented it out
do i still need to pass the gl flag to freebasic as well? Im using djpeters freeglut 2.4 for freebasic
any help will be apreciated
DarkKoder
Posts: 18
Joined: Apr 08, 2009 1:03

Post by DarkKoder »

can anyone help..? plz.?
Sisophon2001
Posts: 1706
Joined: May 27, 2005 6:34
Location: Cambodia, Thailand, Lao, Ireland etc.
Contact:

Post by Sisophon2001 »

Do you have the correct DLL's installed? I suggest you post a code sample that does not work, so others can check it.

Garvan
D.J.Peters
Posts: 8631
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

here are my version of FreeGLUT
(take a look to test02.bas)
download: fFBFreeGlut.zip
if your code makes trouble feel free and post it here

http://freeglut.sourceforge.net/

Joshy

EDIT: i tranlated this nice C example in 5 minutes to fb code

test01.bas

Code: Select all

/'
 * one.c
 *
 * Hey! This was the original file where freeglut development started. Just
 * note what I have written here at the time. And see the creation date :)
 *
 * : This is a wrapper. I still have to figure out
 * : how to build shared libraries under *nix :)
 *
 * Copyright (c) 1999 by Pawel W. Olszta
 * Written by Pawel W. Olszta, <olszta@sourceforge.net>
 * Creation date: czw gru  2 11:58:41 CET 1999
 '/


#include "freeglut.bi"

#define  GLUT_BITMAP_HELVETICA_18 cptr(any ptr,&H0008)

dim shared as integer g_LeaveGameMode = 0
dim shared as integer g_InGameMode = 1

/'
 * Call this function to have some text drawn at given coordinates
 '/
sub PrintText(nX as integer,nY as integer,Text as string)
    dim as integer lines
    dim as integer l=len(Text)
    if l<1 then return
    l-=1

    /'
     * Prepare the OpenGL state
     '/
    glDisable( GL_LIGHTING )
    glDisable( GL_DEPTH_TEST )
    glMatrixMode( GL_PROJECTION )
    glPushMatrix()
    glLoadIdentity()

    /'
     * Have an orthogonal projection matrix set
     '/
    glOrtho( 0, glutGet( GLUT_WINDOW_WIDTH ), _
             0, glutGet( GLUT_WINDOW_HEIGHT ), _
             -1, +1)

    /'
     * Now the matrix mode
     '/
    glMatrixMode( GL_MODELVIEW )
    glPushMatrix()
    glLoadIdentity()

    /'
     * Now the main text
     '/
    glColor3ub( 0, 0, 0 )
    glRasterPos2i( nX, nY )

    for i as integer = 0 to l
      dim as integer char=text[i]
      if (char=13) then
        lines+=1
        glRasterPos2i( nX, nY-(lines*18) )
      end if
      glutBitmapCharacter( GLUT_BITMAP_HELVETICA_18,char)
    next

    /'
     * Revert to the old matrix modes
     '/
    glMatrixMode( GL_PROJECTION )
    glPopMatrix()

    glMatrixMode( GL_MODELVIEW )
    glPopMatrix()

    /'
     * Restore the old OpenGL states
     '/
    glColor4f( 1.0, 1.0, 1.0, 1.0 )
    glEnable( GL_DEPTH_TEST )
    glEnable( GL_LIGHTING )
end sub

/'
 * This is the display routine for our sample FreeGLUT windows
 '/
dim shared as single g_fTime = 0.0

sub SampleDisplay cdecl ()

    /'
     * Clear the screen
     '/
    glClearColor( 0, 0.5, 1, 1 )
    glClear( GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT )

    /'
     * Have the cube rotated
     '/
    glMatrixMode( GL_MODELVIEW )
    glPushMatrix()

    glRotatef( g_fTime, 0, 0, 1 )
    glRotatef( g_fTime, 0, 1, 0 )
    glRotatef( g_fTime, 1, 0, 0 )

    /'
     * And then drawn...
     '/
    glColor3f( 1, 1, 0 )
    ' glutWireCube( 20.0 )
    glutWireTeapot( 20.0 )
    'glutSolidTeapot( 20.0 )
    ' glutWireSpher( 15.0, 15, 15 )
    ' glColor3f( 0, 1, 0 )
    ' glutWireCube( 30.0 )
    ' glutSolidCone( 10, 20, 10, 2 )

    /'
     * Don't forget about the model-view matrix
     '/
    glPopMatrix( )

    /'
     * Draw a silly text
     '/
    if( g_InGameMode = 0 ) then
        PrintText( 20, 20, "Hello there cruel world!" )
    else
        PrintText( 20, 20, "Press ESC to leave the game mode!" )
    end if
    /'
     * And swap this context's buffers
     '/
    glutSwapBuffers( )
end sub

/'
 * This is a sample idle function
 '/
sub SampleIdle cdecl ()

    g_fTime += 0.5

    if( g_LeaveGameMode = 1 ) then
        glutLeaveGameMode( )
        g_LeaveGameMode = 0
        g_InGameMode = 0
    end if
end sub

/'
 * The reshape function
 '/
sub SampleReshape cdecl (nWidth as integer,nHeight as integer)

  dim as GLfloat fAspect = nHeight / nWidth
  dim as GLfloat fPos( 3 ) = { 0.0, 0.0, 10.0, 0.0 }
  dim as GLfloat fCol( 3 ) = { 0.5, 1.0,  0.0, 1.0 }

    /'
     * Update the viewport first
     '/
    glViewport( 0, 0, nWidth, nHeight )

    /'
     * Then the projection matrix
     '/
    glMatrixMode( GL_PROJECTION )
    glLoadIdentity()
    glFrustum( -1.0, 1.0, -fAspect, fAspect, 1.0, 80.0 )

    /'
     * Move back the camera a bit
     '/
    glMatrixMode( GL_MODELVIEW )
    glLoadIdentity( )
    glTranslatef( 0.0, 0.0, -40.0 )

    /'
     * Enable some features...
     '/
    glEnable( GL_CULL_FACE )
    glEnable( GL_DEPTH_TEST )
    glEnable( GL_NORMALIZE )

    /'
     * Set up some lighting
     '/
    glLightfv( GL_LIGHT0, GL_POSITION,@fPos(0))
    glEnable( GL_LIGHTING )
    glEnable( GL_LIGHT0 )

    /'
     * Set up a sample material
     '/
    glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, @fCol(0) )
end sub

/'
 * A sample keyboard callback
 '/
sub SampleKeyboard cdecl( cChar as ubyte, nMouseX as integer, nMouseY as integer)
    print "SampleKeyboard(): keypress " & cChar & " at " & nMouseX & "," & nMouseY
end sub

/'
 * A sample keyboard callback (for game mode window)
 '/
sub SampleGameModeKeyboard cdecl (cChar as ubyte, nMouseX as integer, nMouseY as integer)
    if ( cChar = 27 ) then g_LeaveGameMode = 1
end sub


/'
 * A sample special callback
 '/
sub SampleSpecial cdecl (nSpecial as integer,nMouseX as integer,nMouseY as integer)
  print "SampleSpecial(): keypress " & nSpecial & " at " & nMouseX & "," & nMouseY
end sub

/'
 * A sample menu callback
 '/
sub SampleMenu cdecl (menuID as integer)
    /'
     * Just print something funny
     '/
    print "SampleMenu() callback executed, menuID is " & menuID
end sub

/'
 * The sample's entry point
 '/

    dim as integer menuID, subMenuA, subMenuB

    glutInitDisplayString( "stencil rgb double depth>=16 samples" )
    glutInitDisplayMode( GLUT_RGB or GLUT_DOUBLE or GLUT_DEPTH )
    glutInitWindowPosition( 100, 100 )
    glutInit(0,0)

    subMenuA = glutCreateMenu(@SampleMenu )
    glutAddMenuEntry( "Sub menu A1 (01)", 1 )
    glutAddMenuEntry( "Sub menu A2 (02)", 2 )
    glutAddMenuEntry( "Sub menu A3 (03)", 3 )

    subMenuB = glutCreateMenu(@SampleMenu )
    glutAddMenuEntry( "Sub menu B1 (04)", 4 )
    glutAddMenuEntry( "Sub menu B2 (05)", 5 )
    glutAddMenuEntry( "Sub menu B3 (06)", 6 )
    glutAddSubMenu( "Going to sub menu A", subMenuA )

    menuID = glutCreateMenu(@SampleMenu )
    glutAddMenuEntry( "Entry one",   1 )
    glutAddMenuEntry( "Entry two",   2 )
    glutAddMenuEntry( "Entry three", 3 )
    glutAddMenuEntry( "Entry four",  4 )
    glutAddMenuEntry( "Entry five",  5 )
    glutAddSubMenu( "Enter sub menu A", subMenuA )
    glutAddSubMenu( "Enter sub menu B", subMenuB )

    glutCreateWindow( "Hello world!" )
    glutDisplayFunc(@SampleDisplay )
    glutReshapeFunc(@SampleReshape )
    glutKeyboardFunc(@SampleKeyboard )
    glutSpecialFunc(@SampleSpecial )
    glutIdleFunc(@SampleIdle )
    glutAttachMenu( GLUT_LEFT_BUTTON )

    glutInitWindowPosition( 200, 200 )
    glutCreateWindow( "I am not Jan B." )
    glutDisplayFunc(@SampleDisplay )
    glutReshapeFunc(@SampleReshape )
    glutKeyboardFunc(@SampleKeyboard )
    glutSpecialFunc(@SampleSpecial )
    glutIdleFunc(@SampleIdle )
    glutAttachMenu( GLUT_LEFT_BUTTON )

    print "Testing game mode string parsing, don't panic!"
    glutGameModeString( "320x240:32@100" )
    glutGameModeString( "640x480:16@72" )
    glutGameModeString( ":32@120" )
    glutGameModeString( "640x480:16@72" )
    glutGameModeString( "1024x768" )

    glutEnterGameMode()
    glutDisplayFunc(@SampleDisplay )
    glutReshapeFunc(@SampleReshape )
    glutKeyboardFunc(@SampleGameModeKeyboard )
    glutIdleFunc(@SampleIdle )
    glutAttachMenu( GLUT_LEFT_BUTTON )

    print "current window is " & _
            glutGet( GLUT_WINDOW_X ) & "," & glutGet( GLUT_WINDOW_Y ) & " " & _
            glutGet( GLUT_WINDOW_WIDTH ) & "," & glutGet( GLUT_WINDOW_HEIGHT )


    /'
     * Enter the main FreeGLUT processing loop
     '/
    glutMainLoop()

    print "glutMainLoop() termination works fine!"
    beep:sleep 3000
    /'
     * This is never reached in FreeGLUT. Is that good?
     '/
    end
Last edited by D.J.Peters on Oct 03, 2017 5:50, edited 2 times in total.
DarkKoder
Posts: 18
Joined: Apr 08, 2009 1:03

Post by DarkKoder »

Thanks for all the help guys, and to djpeters for creating the translations and the example prog that he translated from c, i had merely didnt install the freeglut dll to the system32 folder :P i was very tired that day.
h4tt3n
Posts: 698
Joined: Oct 22, 2005 21:12
Location: Denmark

Post by h4tt3n »

Thanks D.J. :-)
petan
Posts: 683
Joined: Feb 16, 2010 15:34
Location: Europe
Contact:

Post by petan »

Hi,

freeglut_test.zip download link is down.
I am interesting about it.Could you re-upload it ?
Thank you,

Pete
Lionheart2020
Posts: 13
Joined: May 30, 2009 18:12

Post by Lionheart2020 »

hello. I am looking for the "freeglut.bi" file. the file zip above with example from d.j.peter doesn't work here. anybody can help or give another link? thanks! -tom_lion
D.J.Peters
Posts: 8631
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

FBFreeGlut.zip with examples of multiply windows

the link is ok now.

Joshy
Post Reply