Author Topic: Freeglut excursions  (Read 7094 times)

0 Members and 1 Guest are viewing this topic.

Arnold

  • Guest
Freeglut excursions
« on: September 19, 2016, 01:17:07 AM »
Hi Charles,

I assume to run projectsA\Freeglut\GlProcTexture.o2bas the last lines should be:

'char    *argv
'int     argc
main 0,0  '' argc,argv

otherwise I suppose an approach like in tests\Constructs\ArgcArgv.o2bas must be used?

And it seems to me that in inc\glo2\freeglut.inc only the GLUT_(font...) constants can be used. (See my example Lh08.o2bas).

I could not resist and replaced lib\freeglut.dll and used the latest header files of
freeglut-MinGW.zip which can be found at transmissionzero.co.uk
The homepage of freeglut is: http://freeglut.sourceforge.net/

Only three changes were necessary in freeglut_std.h (two were claimed by O2 and one addition for GLUT_(fonts...) and another change in freeglut_ext.h.
So I could replace in the demo apps and in fgUtil.inc the line
include "$/inc/glo2/freeglut.inc"   
with:
Code: OxygenBasic
  1. #case capital
  2. def NULL null
  3. '
  4. #define WINGDIAPI
  5. #define APIENTRY
  6.  
  7. typedef word wchar_t
  8. typedef sys ptrdiff_t
  9.  
  10. library       "opengl32.dll"
  11. includepath   "$/inc/glo2/"
  12. include  once "gl/gl.h"
  13. 'include once "gl/glext.h"
  14. library       "glu32.dll"
  15. include  once "gl/glu.h"
  16. include  once "gl/wgl.inc"
  17. includepath   ""
  18.  
  19. 'typedef bool GLBoolean
  20.  
  21. extern lib "$/lib/freeglut.dll"
  22. includepath  + "include/"
  23. include "freeglut.h"
  24.  
  25. extern cdecl   'callbacks
  26. indexbase   0
  27.  

and this works very fine on my system using Oxygen.dll of 07/06/2016. Will these demos (and the Iup examples) run with the forthcoming O2 version too or must there be some corrections?

Roland

.

Charles Pegge

  • Guest
Re: Freeglut excursions
« Reply #1 on: September 19, 2016, 12:17:56 PM »
Hi Roland,

The next o2 release maintains compatibility with previous versions except for operator overloading, which will be based on dotted macro sets, instead of function calls. This will substantially improve the performance for complex number maths, making it practical to render fractals etc using complex number notation. (without decomposing to primitives).

I'm not a great fan of FreeGlut, since it assists only in a tiny fraction of the tasks required to build an OpenGL-based application. But I will check for any compatibility breakages.

Painlessly accessing arguments from the CommandLine:
Code: [Select]
include     "console.inc"
include     "sysutil.inc"
CreateArgv
CreateMainCall


function main cdecl (int argc,cstring*argv) as int
================================================
  printl "Arguments " argc
  printl "List:"
  for i=1 to argc
    printl argv[i]
  next
end function

waitkey


Arnold

  • Guest
Re: Freeglut excursions
« Reply #2 on: September 20, 2016, 12:56:50 AM »
Hi Charles,

the purpose with this topic is to check if the header files of freeglut can be used and then compare this approach with \inc\glo2\freeglut.inc. Until now I think it works quite nice.
Unfortunately I know almost nothing about OpenGl or free(glut). I first learned about the possibilities by using OxygenBasic. You mentioned earlier that it will take some years to master OpenGl so I will need some time. At the moment I am trying to run some Glut examples with O2, most of them do not run the way I would like. I also started to read the preface of "OpenGL Programming Guide" 7th edition and learned that I will need some other toolkits like freeglut in order to focus on OpenGL graphics functions.

Which other dynamic libraries could be recommended instead of using freeglut?

Roland

JRS

  • Guest
Re: Freeglut excursions
« Reply #3 on: September 20, 2016, 07:42:25 AM »
Quote
Which other dynamic libraries could be recommended instead of using freeglut?

Have you looked at the IUP wrapper for graphics? (OpenGL, IM, ...)

Charles Pegge

  • Guest
Re: Freeglut excursions
« Reply #4 on: September 20, 2016, 11:31:34 AM »
Hi John,

We have some opengl/IUP demos on board though they require some geometry repairs.

Hi Roland,

I have now tested your more recent freeglut.dll with the C header files, and they work with your examples and all the other examples included in projectsA/freeglut.

I moved all the freeglut headers into projectsA\freeglut\include. As per your scheme.

This is the new freeglut.inc which pulls in both opengl and freeglut:

Code: [Select]
#case capital
def NULL null
'
#define WINGDIAPI
#define APIENTRY
'
typedef word wchar_t
typedef sys ptrdiff_t
'
library       "opengl32.dll"
includepath   "$/inc/glo2/"
include  once "gl/gl.h"
'include once "gl/glext.h"
library       "glu32.dll"
include  once "gl/glu.h"
include  once "gl/wgl.inc"

includepath   "include/"

'typedef bool GLBoolean

extern lib "$/lib/freeglut.dll"
include "freeglut.h"
end extern

includepath ""

PS

Quote
Which other dynamic libraries could be recommended instead of using freeglut?

You must ask our resident expert, Mike Lobanovsky who is very knowledgable on all matters concerning Opengl :)
« Last Edit: September 21, 2016, 12:20:05 AM by Charles Pegge »

Arnold

  • Guest
Re: Freeglut excursions
« Reply #5 on: September 21, 2016, 04:26:52 AM »
Quote from: John
Have you looked at the IUP wrapper for graphics? (OpenGL, IM, ...)

This would be the glcontrols demo done with OxygenBasic. The problem is: you will need iup.dll, iupcontrols.dll, iupgl.dll, iupglcontrols.dll, ftgl.dll, iupcd.dll, cd.dll, zlib1.dll and freetype6.dll to run this example. I think this is two much oversized for starting with OpenGL. But for creating major projects this could be an interesting option.

I think in the beginning phase I will use freeglut for my experiments with OpenGL. There are already some basic functions available to manage windows, mouse and keyboard which is sufficient for me at the moment.

Roland

.

JRS

  • Guest
Re: Freeglut excursions
« Reply #6 on: September 21, 2016, 08:11:13 AM »
The big advantage to IUP is write once and run on multiple OS platforms.

If Windows is your only interest, there are plenty of options to help you paint yourself into a corner.  ;)

Arnold

  • Guest
Re: Freeglut excursions
« Reply #7 on: September 24, 2016, 03:32:43 AM »
Hi Charles, Mike,

can you help out with this issue?

I have ported the first 5 Nehe tutorials to OxygenBasic using freeglut. Lesson 6 will be the next exciting journey.

Lesson5.o2bas can be run in projectsA\freeglut folder. Using freeglut saved about 240 lines of code. The program does a little bit more and runs better than the original code when using F1. There are two open questions though:

Searching in Internet for glPushMatrix and glPopMatrix I noticed that these functions are considered to be deprecated. What would be a better solution?

Pressing F1 toggles between fullscreen and windowed mode. But the window moves a little bit downwards each time. Should I do something different in sub savePos() or is this a problem of freeglut?

It will take some time to understand OpenGL better. But I begin to recognize a basic systematics.

Roland

Code: OxygenBasic
  1. '     http://nehe.gamedev.net/
  2. /*
  3.  *    This Code Was Created By Jeff Molofee 2000
  4.  *    Lesson5: 3D Shapes
  5.  *    Using freeglut  
  6.  *    Modified and ported to OxygenBasic
  7.  */
  8.  
  9. $ FileName "Lesson5.exe"
  10.  
  11. 'include "$/inc/RTL32.inc"
  12. 'include "$/inc/console.inc"
  13.  
  14. include "../include/freeglut.inc"
  15.  
  16. // Global variables
  17. ' Title in windowed mode
  18. string title = "NeHe's OpenGL Framework - 3D Shapes"
  19. int windowWidth  = 640     ' Windowed mode's width
  20. int windowHeight = 480     ' Windowed mode's height
  21. int windowPosX   = 50      ' Windowed mode's top-left corner x
  22. int windowPosY   = 50      ' Windowed mode's top-left corner y
  23.  
  24. bool fullscreen = false     // Fullscreen mode ON/OFF
  25.  
  26. GLfloat    rtri          // Angle For The Triangle
  27. GLfloat    rquad         // Angle For The Quad
  28. int millsec = 15;        // refresh interval in milliseconds
  29.  
  30. sub initGL()                                            // All setup for OpenGL goes Here    
  31.    glShadeModel(GL_SMOOTH)                              // Enable smooth shading              
  32.    glClearColor(0.0f, 0.0f, 0.0f, 0.5f)                 // Black background                  
  33.    glClearDepth(1.0f)                                   // Depth buffer setup                
  34.    glEnable(GL_DEPTH_TEST)                              // Enables depth testing              
  35.    glDepthFunc(GL_LEQUAL)                               // Type of depth testing to do    
  36.    glEnable(GL_COLOR_MATERIAL)
  37.    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)    // Really nice perspective calculation            
  38. end sub
  39.  
  40. sub display()   // Create The Display Function
  41.    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)   // Clear Screen And Depth Buffer
  42.    glLoadIdentity();                                    // Reset The Current Modelview Matrix
  43.                
  44.    glTranslatef(-1.5f,0.0f,-6.0f)      // Move Left 1.5 Units And Into The Screen 6.0
  45.    glRotatef(rtri,0.0f,1.0f,0.0f)      // Rotate The Triangle On The Y axis
  46.  
  47.    glPushMatrix()
  48.  
  49.    glBegin(GL_TRIANGLES)               // Start Drawing A Triangle
  50.    glColor3f(1.0f,0.0f,0.0f)           // Red
  51.    glVertex3f( 0.0f, 1.0f, 0.0f)       // Top Of Triangle (Front)
  52.    glColor3f(0.0f,1.0f,0.0f)           // Green
  53.    glVertex3f(-1.0f,-1.0f, 1.0f)       // Left Of Triangle (Front)
  54.    glColor3f(0.0f,0.0f,1.0f)           // Blue
  55.    glVertex3f( 1.0f,-1.0f, 1.0f)       // Right Of Triangle (Front)
  56.  
  57.    glColor3f(1.0f,0.0f,0.0f)           // Red
  58.    glVertex3f( 0.0f, 1.0f, 0.0f)       // Top Of Triangle (Right)
  59.    glColor3f(0.0f,0.0f,1.0f)           // Blue
  60.    glVertex3f( 1.0f,-1.0f, 1.0f)       // Left Of Triangle (Right)
  61.    glColor3f(0.0f,1.0f,0.0f)           // Green
  62.    glVertex3f( 1.0f,-1.0f, -1.0f)      // Right Of Triangle (Right)
  63.  
  64.    glColor3f(1.0f,0.0f,0.0f)           // Red
  65.    glVertex3f( 0.0f, 1.0f, 0.0f)       // Top Of Triangle (Back)
  66.    glColor3f(0.0f,1.0f,0.0f)           // Green
  67.    glVertex3f( 1.0f,-1.0f, -1.0f)      // Left Of Triangle (Back)
  68.    glColor3f(0.0f,0.0f,1.0f)           // Blue
  69.    glVertex3f(-1.0f,-1.0f, -1.0f)      // Right Of Triangle (Back)
  70.  
  71.    glColor3f(1.0f,0.0f,0.0f)           // Red
  72.    glVertex3f( 0.0f, 1.0f, 0.0f)       // Top Of Triangle (Left)
  73.    glColor3f(0.0f,0.0f,1.0f)           // Blue
  74.    glVertex3f(-1.0f,-1.0f,-1.0f)       // Left Of Triangle (Left)
  75.    glColor3f(0.0f,1.0f,0.0f)           // Green
  76.    glVertex3f(-1.0f,-1.0f, 1.0f)       // Right Of Triangle (Left)
  77.    glEnd()                             // Done Drawing The Pyramid
  78.  
  79.  
  80.    glLoadIdentity()                    // Reset The Current Modelview Matrix
  81.    glTranslatef(1.5f,0.0f,-7.0f)       // Move Right 1.5 Units And Into The Screen 7.0
  82.    glRotatef(rquad,1.0f,0.0f,0.0f)     // Rotate The Quad On The X axis
  83.    glColor3f(0.5f,0.5f,1.0f);          // Set The Color To Blue One Time Only
  84.  
  85.  
  86.    glBegin(GL_QUADS)                   // Draw A Quad
  87.    glColor3f(0.0f,1.0f,0.0f)           // Set The Color To Green
  88.    glVertex3f( 1.0f, 1.0f,-1.0f)       // Top Right Of The Quad (Top)
  89.    glVertex3f(-1.0f, 1.0f,-1.0f)       // Top Left Of The Quad (Top)
  90.    glVertex3f(-1.0f, 1.0f, 1.0f)       // Bottom Left Of The Quad (Top)
  91.    glVertex3f( 1.0f, 1.0f, 1.0f)       // Bottom Right Of The Quad (Top)
  92.  
  93.    glColor3f(1.0f,0.5f,0.0f)           // Set The Color To Orange
  94.    glVertex3f( 1.0f,-1.0f, 1.0f)       // Top Right Of The Quad (Bottom)
  95.    glVertex3f(-1.0f,-1.0f, 1.0f)       // Top Left Of The Quad (Bottom)
  96.    glVertex3f(-1.0f,-1.0f,-1.0f)       // Bottom Left Of The Quad (Bottom)
  97.    glVertex3f( 1.0f,-1.0f,-1.0f)       // Bottom Right Of The Quad (Bottom)
  98.  
  99.    glColor3f(1.0f,0.0f,0.0f)           // Set The Color To Red
  100.    glVertex3f( 1.0f, 1.0f, 1.0f)       // Top Right Of The Quad (Front)
  101.    glVertex3f(-1.0f, 1.0f, 1.0f)       // Top Left Of The Quad (Front)
  102.    glVertex3f(-1.0f,-1.0f, 1.0f)       // Bottom Left Of The Quad (Front)
  103.    glVertex3f( 1.0f,-1.0f, 1.0f)       // Bottom Right Of The Quad (Front)
  104.  
  105.    glColor3f(1.0f,1.0f,0.0f)           // Set The Color To Yellow
  106.    glVertex3f( 1.0f,-1.0f,-1.0f)       // Top Right Of The Quad (Back)
  107.    glVertex3f(-1.0f,-1.0f,-1.0f)       // Top Left Of The Quad (Back)
  108.    glVertex3f(-1.0f, 1.0f,-1.0f)       // Bottom Left Of The Quad (Back)
  109.    glVertex3f( 1.0f, 1.0f,-1.0f)       // Bottom Right Of The Quad (Back)
  110.  
  111.    glColor3f(0.0f,0.0f,1.0f)           // Set The Color To Blue
  112.    glVertex3f(-1.0f, 1.0f, 1.0f)       // Top Right Of The Quad (Left)
  113.    glVertex3f(-1.0f, 1.0f,-1.0f)       // Top Left Of The Quad (Left)
  114.    glVertex3f(-1.0f,-1.0f,-1.0f)       // Bottom Left Of The Quad (Left)
  115.    glVertex3f(-1.0f,-1.0f, 1.0f)       // Bottom Right Of The Quad (Left)
  116.  
  117.    glColor3f(1.0f,0.0f,1.0f)           // Set The Color To Violet
  118.    glVertex3f( 1.0f, 1.0f,-1.0f)       // Top Right Of The Quad (Right)
  119.    glVertex3f( 1.0f, 1.0f, 1.0f)       // Top Left Of The Quad (Right)
  120.    glVertex3f( 1.0f,-1.0f, 1.0f)       // Bottom Left Of The Quad (Right)
  121.    glVertex3f( 1.0f,-1.0f,-1.0f)       // Bottom Right Of The Quad (Right)
  122.    glEnd()                             // Done Drawing The Quad
  123.  
  124.    glPopMatrix()
  125.  
  126.    rtri  += 0.4f            // Increase The Rotation Variable For The Triangle
  127.    rquad -= 0.3f            // Decrease The Rotation Variable For The Quad
  128.  
  129.    glutSwapBuffers()        // Swap the buffers not to be left with a frozen Screen (will need task manager)
  130.  
  131. end sub
  132.  
  133. /* Called back when timer expired */
  134. sub timer(int value)
  135.    glutPostRedisplay()               // Post re-paint request to activate display()
  136.    glutTimerFunc(millsec, @timer, 0) // next timer call milliseconds later
  137. end sub
  138.  
  139. // Reshaping handler (required even in fullscreen mode)
  140. sub reshape(int w, int h)
  141.    if h = 0 then h = 1               // Prevent divide by zero
  142.    GLfloat aspect = (GLfloat)w / (GLfloat)h;
  143.  
  144.    glViewport(0, 0, w, h)            // Reset the current viewport
  145.    glMatrixMode(GL_PROJECTION)       // Select the projection matrix
  146.    glLoadIdentity()                  // Reset the projection matrix
  147.  
  148.    // Calculate the aspect ratio and set the clipping Volume
  149.    gluPerspective(45.0f, aspect, 0.1f, 100.0f)  
  150.  
  151.    glMatrixMode(GL_MODELVIEW)        // Select the modelview matrix
  152.    glLoadIdentity()                  // Reset the modelview matrix
  153. end sub
  154.  
  155. // Keyboard handler (Normal keys)
  156. sub keyboard(int key, int x, int y)
  157.    select key
  158.  
  159.    case 27            // When Escape Is Pressed...
  160.       glutExit()      // Exit The Program
  161.    case else
  162.      
  163.    end select
  164. end sub
  165.  
  166. sub savePos()
  167.     windowPosX   = glutGet(GLUT_WINDOW_X) ' Save parameters for restoring later
  168.    windowPosY   = glutGet(GLUT_WINDOW_Y)
  169.     windowWidth  = glutGet(GLUT_WINDOW_WIDTH)
  170.     windowHeight = glutGet(GLUT_WINDOW_HEIGHT)      
  171. end sub
  172.  
  173. // Keyboard Handler for special keys (Like arrow Keys and function keys)
  174. sub arrow_keys(int a_keys, int x, int y)  // Create Special Function (required for arrow keys)
  175.    select a_keys
  176.  
  177.    case GLUT_KEY_F1                       // Is F1 Being Pressed?
  178.       // We can switch between windowed mode and fullscreen mode
  179.       fullscreen = not fullscreen         // Toggle fullscreen flag
  180.       if fullscreen then
  181.         savePos()                         // save position and size
  182.         glutFullScreen()                  // Change in fullscreen mode
  183.       else
  184.         glutReshapeWindow(windowWidth, windowHeight) // Switch into windowed mode
  185. '        glutPositionWindow(windowPosX, windowPosY)   // Position top-left
  186.      end if
  187.    case GLUT_KEY_UP      // When Up Arrow Is Pressed...
  188.       savePos()          // save position and size
  189.       glutFullScreen()   // Go Into Full Screen Mode
  190.       fullscreen = -1    // fullscreen flag true
  191.     case GLUT_KEY_DOWN:  // When Down Arrow Is Pressed...
  192.       glutReshapeWindow(windowWidth, windowHeight)    // Switch into windowed mode
  193. '      glutPositionWindow(windowPosX, windowPosY)      // Position top-left
  194.      fullscreen = 0     // fullscreen flag false
  195.    case else
  196.      
  197.    end select
  198. end sub
  199.  
  200. sub main()
  201.    glutInit(0,0)  
  202.  
  203.    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE)     // Display Mode
  204.    glutInitWindowSize(windowWidth, windowHeight)    // If glutFullScreen wasn't called this is the window size
  205.   glutInitWindowPosition(windowPosX, windowPosY)   // Window position
  206.    glutCreateWindow(title)                          // Window Title
  207.  
  208.    glutDisplayFunc(@display)      // callbacks
  209.    glutReshapeFunc(@reshape)  
  210.    glutKeyboardFunc(@keyboard)  
  211.    glutSpecialFunc(@arrow_keys)
  212.  
  213. '  either
  214. '   glutIdleFunc(@display)  
  215. '  or better
  216.   glutTimerFunc(0, @timer, 0)      // First timer call immediately
  217.  
  218.    initGL()                         // OpenGL setup
  219.    glutMainLoop()                   // Initialize The Main Loop
  220. end sub
  221.  
  222. main()
  223.  
« Last Edit: September 24, 2016, 08:46:15 AM by Arnold »

Mike Lobanovsky

  • Guest
Re: Freeglut excursions
« Reply #8 on: September 24, 2016, 07:07:25 AM »
Hi Charles, Roland,

Quote
Which other dynamic libraries could be recommended instead of using freeglut?

None. The original Glut.dll has been abandoned perhaps two decades ago. Freeglut is its only generally ABI-compatible alternative that's still in use and that's in many cases way faster than its deprecated prototype.

Quote
... glPushMatrix and glPopMatrix ... are considered to be deprecated.

No. This pair is the fastest means to preserve and restore the current states of OpenGL immediate-mode matrices before and after adjusting the 3D parameters of individual objects in the OpenGL scene. An attempt to preserve/restore them in a different way, e.g. locally in the user code, will only result in a noticeably slower execution speed.

We can only speak about attempts to deprecate the entire OpenGL immediate mode that's been constantly taken all the way since about OpenGL 3.0 with the advent of GLSL. But due to its tremendous edicational importance to OpenGL newbies the immediate mode is still preserved, albeit not developed any firther, in every OpenGL implementation I'm aware of.

But the window moves a little bit downwards each time. ... is this a problem of freeglut?

You can try and run the program under your Windows 7's Classic theme. If it cures the problem of restoring the exact position of the window then it's yet another obvious Freeglut glitch. Almost everything that has "free" and/or "open-source" in its PR is usually a linuxoid procreation. But linuxoids have never made an attempt to learn from MS Windows rather than sh*t on it, hence innumerous glitches in almost every piece of linuxoid code ported to Windows verbatim. Linux is a console-oriented no-man's land where Windows theme metrics remains a mystical secret behind seven seals.

Quote
Should I do something different in sub savePos() ... ?

A faithful Windows user would normally declare a RECT and use it with GetWindowRect() to save the window size and position before going full screen, and SetWindowPos() or MoveWindow(), to restore the window afterwards. This will make the code theme independent and fool proof.

Arnold

  • Guest
Re: Freeglut excursions
« Reply #9 on: September 24, 2016, 08:47:31 AM »
Hi Mike,

thank you for the info. I was not sure about glPushMatrix / glPopMatrix but now I am relieved.
It seems that the moving window was caused by me. If I remove the two glutPositionWindow statements in sub arrow_keys() then toggling between fullscreen and window mode works fine.

Roland

JRS

  • Guest
Re: Freeglut excursions
« Reply #10 on: September 24, 2016, 01:57:18 PM »
Quote
Windows theme metrics remains a mystical secret behind seven seals.

Have you thought about writing children's fairytale books as a side gig?

Charles Pegge

  • Guest
Re: Freeglut excursions
« Reply #11 on: September 25, 2016, 01:08:46 AM »
Hi Mike,

I don't see any obvious substitute for classical Opengl for CAD work, where it is necessary to render large numbers of components with true geometry, efficiently, using glPushMatrix, glPopMatrix and glCallList etc. There seems to be a conflict between engineering and gaming here.

Mike Lobanovsky

  • Guest
Re: Freeglut excursions
« Reply #12 on: September 25, 2016, 02:31:32 AM »
@John:

That's exactly what I'm doing! ;D

In fact that paragraph was written especially to tease you, in exchange for your recent attack on Logic BASIC at Retro. Yes, it's a Windows only program and it's been written for Windows users, and those unfortunate people who find themselves under Linux more often than they should, should take for granted that Windows is self sufficient and there's no real insentive for a Windows developer to go an extra mile and write "portable" code. There's so much room under Windows that we don't normally look over the fence. There's practically nothing there that might interest us. For every Linux program there's at least five Windows equivalents of the same or better quality, design, and functionality -- all free to download and use OOTB. Wine is great and so are GCC, 3D Blender, and of course the Linux kernel itself. Everything else -- no thanks, not interested. That's how it is, John, whether you like it or not.


@Charles:

Frankly, I don't see any contradiction between modern trends in the gaming industry and classical CAD tasks. Both are all about rendering as much geo as possible, as precisely as possible, and as fast as possible. We are still working in 3D with Patrice and his recent models are simply superb not only artistically but technically as well. Every unit of his car and sci-fi models is no less sophisticated graphically than a part of genuine Ferrari would be.

And yes, we're using lots of glPushMatrix/glPopMatrix'es even though we're working mainly in GLSL. But there's nothing better than the OpenGL good old immediate mode to get the basic feel of graphics primitives -- tris and quads -- before starting to draw them by millions in each render frame.

As for glLists, they were exactly what GLSL/HLSL grew from. :)

JRS

  • Guest
Re: Freeglut excursions
« Reply #13 on: September 25, 2016, 08:33:11 PM »
The problem is Mike I'm more web centric then you and Windows desktop programming has little interest to me any longer. I would revisit the Windows platform again sitting in the back seat with someone else steering. I really like the openness of Linux and the diverse libraries available. Even Microsoft is abandoning Windows for Linux. I'm perfectly happy with my Windows 7 32 bit version of the OS running in a VirtualBox on my Ubuntu 16.04 64 bit development laptop. Runs great!

Arnold

  • Guest
Re: Freeglut excursions - Nehe Lesson 6
« Reply #14 on: September 26, 2016, 12:34:08 AM »
Hi Charles,

maybe this could be interesting? I noticed that it is possible to create a dll from the source code of the SOIL library.
The link for the library is: http://www.lonesock.net/soil.html

To generate the dll I used this small batch file in folder Soil\src\

Code: [Select]
:: soil_gccmake.bat
:: build dynamic library

@echo Build Soil.dll

set flag=-O3
gcc -c image_DXT.c     -o image_DXT.o %flag% 
gcc -c image_helper.c  -o image_helper.o %flag%
gcc -c SOIL.c          -o SOIL.o %flag%       
gcc -c stb_image_aug.c -o stb_image_aug.o %flag%

gcc -o SOIL.dll -s -shared image_DXT.o image_helper.o SOIL.o stb_image_aug.o -lopengl32 -Wl,--subsystem,windows

@echo.
@echo Enter to delete .o files or close window
@echo.
@echo off
pause
echo Deleting files
del image_DXT.o
del image_helper.o
del SOIL.o 
del stb_image_aug.o

I checked the dll with https://www.virustotal.com/ and no virus was reported by 57 scanners, so I think the dll is ok. For creating the soil.inc I used SOIL.bi in folder Soil\support\FreeBasic with only minor changes.

And I think this is so funny: will the syntax of the wrapped functions really work? This would offer a lot of variations.

To create Nehe Lesson 6 I used freeglut and the Soil library. I attached the whole project as a zip file. The app should run everywhere on the disk or USB-stick. I think it works better than the original code.

I would like to try GDIplus with Nehe lesson6 too. Is there an appropriate include file anywhere with OxygenBasic which could be used for this function:

function LoadGLTextures()      // Load Bitmaps And Convert To Textures

Roland

Code: OxygenBasic
  1. '     http://nehe.gamedev.net/
  2. /*
  3.  *    This Code Was Created By Jeff Molofee 2000
  4.  *    Lesson6: Texture Mapping
  5.  *    Using freeglut  
  6.  *    Modified and ported to OxygenBasic
  7.  */
  8.  
  9. $ FileName "Lesson6.exe"
  10.  
  11. 'include "$/inc/RTL32.inc"
  12. 'include "$/inc/console.inc"
  13.  
  14. include "$/inc/glo2/freeglut.inc"
  15. includepath "./"
  16. include "soil.inc"
  17.  
  18. % false=0
  19. % true =1
  20.  
  21. extern cdecl
  22. indexbase 0
  23.  
  24. // Global variables
  25. ' Title in windowed mode
  26. string title = "NeHe's OpenGL Tutorial - Texture Mapping"
  27. int windowWidth  = 640     ' Windowed mode's width
  28. int windowHeight = 480     ' Windowed mode's height
  29. int windowPosX   = 50      ' Windowed mode's top-left corner x
  30. int windowPosY   = 50      ' Windowed mode's top-left corner y
  31.  
  32. bool fullscreen = false     // Fullscreen mode ON/OFF
  33.  
  34. GLfloat xrot                // X Rotation
  35. GLfloat yrot                // Y Rotation
  36. GLfloat zrot                // Z Rotation
  37.  
  38. dim as GLuint texture[1]={0}
  39.  
  40. int millsec = 15               // refresh interval in milliseconds
  41.  
  42. function LoadGLTextures()      // Load Bitmaps And Convert To Textures
  43.    /* load an image file directly as a new OpenGL texture */
  44.  
  45.    texture[0] = SOIL_load_OGL_texture(
  46.         "Data/NeHe.bmp",
  47.         SOIL_LOAD_AUTO,
  48.         SOIL_CREATE_NEW_ID,
  49.         SOIL_FLAG_INVERT_Y)
  50.  
  51.    if texture[0] = 0 then return false
  52.  
  53.    // Typical Texture Generation Using Data From The Bitmap
  54.    glBindTexture(GL_TEXTURE_2D, texture[0])
  55.    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR)
  56.    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR)
  57.  
  58.    return true          // Return Success
  59. end function
  60.  
  61. sub initGL()                                   // All setup for OpenGL goes Here
  62.    if LoadGLTextures()=0 then                  // Jump To Texture Loading Routine
  63.      mbox "LoadGLTextures() failed!"           // If Texture Didn't Load
  64.   end if
  65.    
  66.    glEnable(GL_TEXTURE_2D)                              // Enable Texture Mapping                                                      
  67.    glShadeModel(GL_SMOOTH)                              // Enable smooth shading              
  68.    glClearColor(0.0f, 0.0f, 0.0f, 0.5f)                 // Black background                  
  69.    glClearDepth(1.0f)                                   // Depth buffer setup                
  70.    glEnable(GL_DEPTH_TEST)                              // Enables depth testing              
  71.    glDepthFunc(GL_LEQUAL)                               // Type of depth testing to do    
  72.    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)    // Really nice perspective calculation            
  73. end sub
  74.  
  75. sub display()   // Create The Display /DrawGLScene Function
  76.    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)   // Clear Screen And Depth Buffer
  77.    glLoadIdentity()                                     // Reset The Current Modelview Matrix
  78.  
  79.    glPushMatrix()              
  80.    
  81.    glTranslatef(0.0f,0.0f,-5.0f)      // Move into Screen 5.0
  82.  
  83.    glRotatef(xrot,1.0f,0.0f,0.0f)
  84.    glRotatef(yrot,0.0f,1.0f,0.0f)
  85.    glRotatef(zrot,0.0f,0.0f,1.0f)
  86.  
  87.    glBindTexture(GL_TEXTURE_2D, texture[0])
  88.  
  89.    glBegin(GL_QUADS)
  90.         // Front Face
  91.         glTexCoord2f(0.0f, 0.0f) : glVertex3f(-1.0f, -1.0f,  1.0f)
  92.         glTexCoord2f(1.0f, 0.0f) : glVertex3f( 1.0f, -1.0f,  1.0f)
  93.         glTexCoord2f(1.0f, 1.0f) : glVertex3f( 1.0f,  1.0f,  1.0f)
  94.         glTexCoord2f(0.0f, 1.0f) : glVertex3f(-1.0f,  1.0f,  1.0f)
  95.         // Back Face
  96.         glTexCoord2f(1.0f, 0.0f) : glVertex3f(-1.0f, -1.0f, -1.0f)
  97.         glTexCoord2f(1.0f, 1.0f) : glVertex3f(-1.0f,  1.0f, -1.0f)
  98.         glTexCoord2f(0.0f, 1.0f) : glVertex3f( 1.0f,  1.0f, -1.0f)
  99.         glTexCoord2f(0.0f, 0.0f) : glVertex3f( 1.0f, -1.0f, -1.0f)
  100.         // Top Face
  101.         glTexCoord2f(0.0f, 1.0f) : glVertex3f(-1.0f,  1.0f, -1.0f)
  102.         glTexCoord2f(0.0f, 0.0f) : glVertex3f(-1.0f,  1.0f,  1.0f)
  103.         glTexCoord2f(1.0f, 0.0f) : glVertex3f( 1.0f,  1.0f,  1.0f)
  104.         glTexCoord2f(1.0f, 1.0f) : glVertex3f( 1.0f,  1.0f, -1.0f)
  105.         // Bottom Face
  106.         glTexCoord2f(1.0f, 1.0f) : glVertex3f(-1.0f, -1.0f, -1.0f)
  107.         glTexCoord2f(0.0f, 1.0f) : glVertex3f( 1.0f, -1.0f, -1.0f)
  108.         glTexCoord2f(0.0f, 0.0f) : glVertex3f( 1.0f, -1.0f,  1.0f)
  109.         glTexCoord2f(1.0f, 0.0f) : glVertex3f(-1.0f, -1.0f,  1.0f)
  110.         // Right face
  111.         glTexCoord2f(1.0f, 0.0f) : glVertex3f( 1.0f, -1.0f, -1.0f)
  112.         glTexCoord2f(1.0f, 1.0f) : glVertex3f( 1.0f,  1.0f, -1.0f)
  113.         glTexCoord2f(0.0f, 1.0f) : glVertex3f( 1.0f,  1.0f,  1.0f)
  114.         glTexCoord2f(0.0f, 0.0f) : glVertex3f( 1.0f, -1.0f,  1.0f)
  115.         // Left Face
  116.         glTexCoord2f(0.0f, 0.0f) : glVertex3f(-1.0f, -1.0f, -1.0f)
  117.         glTexCoord2f(1.0f, 0.0f) : glVertex3f(-1.0f, -1.0f,  1.0f)
  118.         glTexCoord2f(1.0f, 1.0f) : glVertex3f(-1.0f,  1.0f,  1.0f)
  119.         glTexCoord2f(0.0f, 1.0f) : glVertex3f(-1.0f,  1.0f, -1.0f)
  120.    glEnd()
  121.  
  122.    glPopMatrix()
  123.  
  124.    xrot+=0.3f
  125.    yrot+=0.2f
  126.    zrot+=0.4f
  127.  
  128.    glutSwapBuffers()        // Swap the buffers not to be left with a blank Screen
  129.  
  130. end sub
  131.  
  132. /* Called back when timer expired */
  133. sub timer(int value)
  134.    glutPostRedisplay()               // Post re-paint request to activate display()
  135.    glutTimerFunc(millsec, @timer, 0) // next timer call milliseconds later
  136. end sub
  137.  
  138. // Reshaping handler (required even in fullscreen mode)
  139. sub reshape(int w, int h)
  140.    if h = 0 then h = 1               // Prevent divide by zero
  141.    GLfloat aspect = (GLfloat)w / (GLfloat)h
  142.  
  143.    glViewport(0, 0, w, h)            // Reset the current viewport
  144.    glMatrixMode(GL_PROJECTION)       // Select the projection matrix
  145.    glLoadIdentity()                  // Reset the projection matrix
  146.  
  147.    // Calculate the aspect ratio and set the clipping Volume
  148.    gluPerspective(45.0f, aspect, 0.1f, 100.0f)  
  149.  
  150.    glMatrixMode(GL_MODELVIEW)        // Select the modelview matrix
  151.    glLoadIdentity()                  // Reset the modelview matrix
  152. end sub
  153.  
  154. // Keyboard handler (Normal keys)
  155. sub keyboard(int key, int x, int y)
  156.    select key
  157.  
  158.    case 27            // When Escape Is Pressed...
  159.       glutExit()      // Exit The Program
  160.    case else
  161.      
  162.    end select
  163. end sub
  164.  
  165. sub savePos()
  166.     windowPosX   = glutGet(GLUT_WINDOW_X) ' Save parameters for restoring later
  167.    windowPosY   = glutGet(GLUT_WINDOW_Y)
  168.     windowWidth  = glutGet(GLUT_WINDOW_WIDTH)
  169.     windowHeight = glutGet(GLUT_WINDOW_HEIGHT)      
  170. end sub
  171.  
  172. // Keyboard Handler for special keys (Like arrow Keys and function keys)
  173. sub special_keys(int s_keys, int x, int y)
  174.    select s_keys
  175.  
  176.    case GLUT_KEY_F1                       // Is F1 Being Pressed?
  177.       // We can switch between windowed mode and fullscreen mode
  178.       fullscreen = not fullscreen         // Toggle fullscreen flag
  179.       if fullscreen then
  180.         savePos()                         // save position and size
  181.         glutFullScreen()                  // Change in fullscreen mode
  182.       else
  183.         glutReshapeWindow(windowWidth, windowHeight) // Switch into windowed mode
  184.       end if
  185.  
  186.    case GLUT_KEY_UP      // When Up Arrow Is Pressed...
  187.       savePos()          // save position and size
  188.       glutFullScreen()   // Go Into Full Screen Mode
  189.       fullscreen = -1    // fullscreen flag true (here: -1)
  190.    case GLUT_KEY_DOWN:   // When Down Arrow Is Pressed...
  191.       glutReshapeWindow(windowWidth, windowHeight)    // Switch into windowed mode
  192.       fullscreen = 0     // fullscreen flag false
  193.    case else
  194.      
  195.    end select
  196. end sub
  197.  
  198. sub main()
  199.    glutInit(0,0)  
  200.  
  201.    glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA)     // Display Mode
  202.    glutInitWindowSize(windowWidth, windowHeight)    // If glutFullScreen wasn't called this is the window size
  203.   glutInitWindowPosition(windowPosX, windowPosY)   // Window position
  204.    glutCreateWindow(title)                          // Window Title
  205.  
  206.    glutDisplayFunc(@display)      // callbacks
  207.    glutReshapeFunc(@reshape)  
  208.    glutKeyboardFunc(@keyboard)  
  209.    glutSpecialFunc(@special_keys)
  210.  
  211. '  either
  212. '   glutIdleFunc(@display)  
  213. '  or better
  214.   glutTimerFunc(0, @timer, 0)      // First timer call immediately
  215.  
  216.    initGL()                         // OpenGL setup
  217.    glutMainLoop()                   // Initialize The Main Loop
  218. end sub
  219.  
  220. main()
  221.  


.