PDA

View Full Version : FreeGLUT on VirtualBox



8Observer8
05-22-2017, 02:35 AM
Hello,

This code works fine. It draws two line. I run it on Virtual Box, Windows XP, Visual Studio 2010 Express Edition

But it shows this message in console:

freeglut (C:\Projects\Axes_CppOpenGL15FreeGLUT\Debug\Axes_C ppOpenGL15FreeGLUT.ex
e): fgInitGL2: fghGenBuffers is NULL

But when I uncomment this line it draws nothing:

//Enable2D(width, height);

Code with commented line of code on Enable2D, this draws two lines:



#include <GL\freeglut.h>

// Window size
int width = 512;
int height = 512;

void Draw()
{
// clear (has to be done at the beginning)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

// Draw X axis
glBegin(GL_LINES);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex2f(0.0f, 0.0f);
glVertex2f(10.0f, 0.0f);
glEnd();

// Draw X axis
glBegin(GL_LINES);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex2f(0.0f, 0.0f);
glVertex2f(0.5f, 0.5f);
glEnd();

// Swap buffers (has to be done at the end)
glutSwapBuffers();
}

void Enable2D(int width, int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0f, width, 0.0f, height, 0.0f, 1.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

// Program entry point
int main(int argc, char** argv) {
// Initialize opengl (via glut)
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(width, height);
glutCreateWindow("Axes");

glutDisplayFunc(Draw);

// setup scene to 2d mode and set draw color to white
//Enable2D(width, height);
glColor3f(1.0f, 1.0f, 1.0f);

// Start the whole thing
glutMainLoop();
return 0;
}

8Observer8
05-22-2017, 02:53 AM
There was some errors in my code. Now it works correct. But I didn't find in internet why this message is showed:

freeglut (C:\Projects\Axes_CppOpenGL15FreeGLUT\Debug\Axes_C ppOpenGL15FreeGLUT.ex
e): fgInitGL2: fghGenBuffers is NULL

Corrected code:


#include <GL\freeglut.h>

// Window size
int width = 512;
int height = 512;

void Draw()
{
// clear (has to be done at the beginning)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

// Draw X axis
glBegin(GL_LINES);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex2f(-width / 2.0f, 0.0f);
glVertex2f(width / 2.0f, 0.0f);
glEnd();

// Draw X axis
glBegin(GL_LINES);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex2f(0.0f, -height / 2.0f);
glVertex2f(0.0f, height / 2.0f);
glEnd();

// Swap buffers (has to be done at the end)
glutSwapBuffers();
}

void Enable2D(int width, int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-width / 2.0f, width / 2.0f, -height / 2.0f, height / 2.0f, 0.0f, 1.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

// Program entry point
int main(int argc, char** argv)
{
// Initialize opengl (via glut)
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(width, height);
glutCreateWindow("Axes");

glutDisplayFunc(Draw);

// setup scene to 2d mode and set draw color to white
Enable2D(width, height);
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);

// Start the whole thing
glutMainLoop();
return 0;
}

GClements
05-22-2017, 02:47 PM
It just means that you aren't using OpenGL 2.0 or later.

The latest versions of FreeGLUT have two versions of the code for drawing shapes (tetrahedron, cube, etc). If the OpenGL version is prior to 2.0, it uses client-side arrays (which don't work with OpenGL 3.0+ core profile). If it's 2.0 or later, it uses buffer objects (which don't work with OpenGL versions prior to 2.0). To detect which version is being used, it checks for the existence of the functions which the 2.0+ code uses, starting with glGenBuffers(). If any of the function pointers are null, it prints a warning and assumes that a pre-2.0 version is in use.

Silence
05-22-2017, 11:11 PM
I think this is related to the fact that you are using OpenGL threw a virtual machine, on Windows. You might be stuck with OpenGL 1.1.

mhagain
05-23-2017, 02:22 AM
This depends.

The free VMWare Player, for example, provides hardware accelerated OpenGL 2.1 on Windows via Gallium and is capable of running something like Quake at 250 fps on Intel integrated graphics on the host and without hardware virtualization. Other virtualization software may be different; the important point is: it's not because you're using a virtual machine, it's your virtualization software.

Silence
05-23-2017, 02:33 AM
This depends.

The free VMWare Player, for example, provides hardware accelerated OpenGL 2.1 on Windows via Gallium and is capable of running something like Quake at 250 fps on Intel integrated graphics on the host and without hardware virtualization. Other virtualization software may be different; the important point is: it's not because you're using a virtual machine, it's your virtualization software.

Thanks for the precision mhagain.