Linker Error During OpenGL: SuperBible Tutorial - opengl

I'm currently trying to decide between DirectX and OpenGL by programming a little DirectX 10 and OpenGL 3.3. I already have the setup for DirectX finished, it was fairly easy to link and compile. OpenGl is... harder.
The OpenGL Superbible has a beginning example called Triangle.cpp in which we link two libraries freeglut_static.lib and GLTools.lib. This isn't a problem; I have also gone to the Project Directories and included the Include/ and lib/ path of all necessary OpenGL extensions (GLEE, Glew, Glut, FreeGlut, GLTools- damn, is that enough?).
First I had several linker errors, because my code generation was set on DLL, not Static. I have fixed this and also added LIBC.lib to the list of ignored libraries in the Linker (not sure if setting the code generation to static fixed this as well).
Now I still have two linker errors remaining which I cannot get rid of:
1>Triangle.obj : error LNK2019: unresolved external symbol ___glutInitWithExit referenced in function _glutInit_ATEXIT_HACK
1>Triangle.obj : error LNK2019: unresolved external symbol ___glutCreateWindowWithExit referenced in function _glutCreateWindow_ATEXIT_HACK
I searched this problem on google, and many people commented on the static nature of the program (which I have fixed) as well as a particular problem with a conflicting version between Glut.h and Glut.lib. However, I even used an older version of Glut (3.6) and the linker error still remains.
Other searches in google don't really come up with anything reasonable to work with. So, I'm asking here: How do I fix this?
Info
Code Generation: Multithreaded
C++ Preprocessor Command: FREEGLUT_STATIC
IDE: Visual Studio 2008 and 2010. (Testing on both- same error on both)
Ignored Libraries: LIBC.lib
Triangle.cpp code (a simple copy/paste from the code in the book):
// Triangle.cpp
// Our first OpenGL program that will just draw a triangle on the screen.
#include <GLTools.h> // OpenGL toolkit
#include <GLShaderManager.h> // Shader Manager Class
//#define FREEGLUT_STATIC
#include <GL/glut.h> // Windows FreeGlut equivalent
GLBatch triangleBatch;
GLShaderManager shaderManager;
///////////////////////////////////////////////////////////////////////////////
// Window has changed size, or has just been created. In either case, we need
// to use the window dimensions to set the viewport and the projection matrix.
void ChangeSize(int w, int h)
{
glViewport(0, 0, w, h);
}
///////////////////////////////////////////////////////////////////////////////
// This function does any needed initialization on the rendering context.
// This is the first opportunity to do any OpenGL related tasks.
void SetupRC()
{
// Blue background
glClearColor(0.0f, 0.0f, 1.0f, 1.0f );
shaderManager.InitializeStockShaders();
// Load up a triangle
GLfloat vVerts[] = { -0.5f, 0.0f, 0.0f,
0.5f, 0.0f, 0.0f,
0.0f, 0.5f, 0.0f };
triangleBatch.Begin(GL_TRIANGLES, 3);
triangleBatch.CopyVertexData3f(vVerts);
triangleBatch.End();
}
///////////////////////////////////////////////////////////////////////////////
// Called to draw scene
void RenderScene(void)
{
// Clear the window with current clearing color
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
GLfloat vRed[] = { 1.0f, 0.0f, 0.0f, 1.0f };
shaderManager.UseStockShader(GLT_SHADER_IDENTITY, vRed);
triangleBatch.Draw();
// Perform the buffer swap to display the back buffer
glutSwapBuffers();
}
///////////////////////////////////////////////////////////////////////////////
// Main entry point for GLUT based programs
int main(int argc, char* argv[])
{
gltSetWorkingDirectory(argv[0]);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL);
glutInitWindowSize(800, 600);
glutCreateWindow("Triangle");
glutReshapeFunc(ChangeSize);
glutDisplayFunc(RenderScene);
GLenum err = glewInit();
if (GLEW_OK != err) {
fprintf(stderr, "GLEW Error: %s\n", glewGetErrorString(err));
return 1;
}
SetupRC();
glutMainLoop();
return 0;
}

Alright, here is the answer:
I had to add the following commands:
#pragma (lib, "freeglut_static.lib")
#pragma (lib, "gltools.lib")
after putting in the library path of the needed files in the Project Directories. After that I also needed to include glut32.dll in my Solution directory (as I had also linked to Glut32), and then it worked.
Hope this helps someone!

For future reference you need to supply the names of the libraries you want to link with at the linker stage.
In visual studio for example you'll find this under
Project Properties->Linker->Input
Just add them ';' delimited in the "Additional Dependencies" field.
Personally I like the #pragma comment solution though as you don't need to remember to add the .libs under additional dependencies you just need those #pragma statements somewhere.

Related

OpenGL/Freeglut in Eclipse Problems - Includes Not Being Found?

I am trying to configure OpenGL/Freeglut in Eclipse on Windows. I have installed MinGW as my toolchain, and the Environment maps MINGW_HOME to the correct top level directory on my C:/ Drive (C:/MingGW). My project lists the various includes in the Project Explorer, including the relevant one to my purpose, C:/MinGW/include.
C:/MinGW/include/GL has all the Freeglut header files which detail the functions I want to use as expected. In particular, C:/MinGW/include/GL/glut.h is definitely where it is expected. My simple test code is below:
#include <windows.h> // For MS Windows
#include <GL/glut.h>
void display() {
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Set background color to black and opaque
glClear(GL_COLOR_BUFFER_BIT); // Clear the color buffer
// Draw a Red 1x1 Square centered at origin
glBegin(GL_QUADS); // Each set of 4 vertices form a quad
glColor3f(1.0f, 0.0f, 0.0f); // Red
glVertex2f(-0.5f, -0.5f); // x, y
glVertex2f( 0.5f, -0.5f);
glVertex2f( 0.5f, 0.5f);
glVertex2f(-0.5f, 0.5f);
glEnd();
glFlush(); // Render now
}
int main(int argc, char** argv) {
glutInit(&argc, argv); // Initialize GLUT
glutCreateWindow("OpenGL Setup Test"); // Create a window with the given title
glutInitWindowSize(320, 320); // Set the window's initial width & height
glutInitWindowPosition(50, 50); // Position the window's initial top-left corner
glutDisplayFunc(display); // Register display callback handler for window re-paint
glutMainLoop(); // Enter the infinitely event-processing loop
return 0;
}
None of the functions (except glutInit and glutCreateWindow) are recognized by the program, despite the include lines. What might be causing this? Is there a step I have missed in my configuration?
Please ask if any further details required.
UPDATE: Situation improved. Not sure how to link to the libraries freeglut_std.h requires, as three functions in it (listed in comment below) are throwing errors, but do not appear to be in explicit use. Any advice?
I solved the problem by including the #define GLUT_DISABLE_ATEXIT_HACK define before the #include header!

Hello World OpenGL program: "glEnableVertexAttribArray was not declared it this scope"

It's getting frustrating. I've been trying to get a simple hello world type program to run, but it just isn't happening.
I'm using Windows 7 and my graphics card does support the newer OpenGL stuff.
Writing in C with freeglut, and I am compiling with MinGW and Code::Blocks.
In the linker I have freeglut, opengl32 and glu32.
I keep the freeglut stuff in the freeglut folder that is located in my MinGW folder, so under search directories in my build settings I have "C:\MinGW\freeglut\include" for the compiler and "C:\MinGW\freeglut\lib" for the linker.
Here's my code:
#include <stdlib.h>
#include <GL/glut.h>
void NIAppIdle(void);
void NIAppDisplay(void);
int main(int argc, char *argv[])
{
// Setup windwing
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
glutInitWindowSize(800, 600);
glutCreateWindow("HELLO WORLD");
// Define GLUT callbacks
glutIdleFunc(NIAppIdle);
glutDisplayFunc(NIAppDisplay);
// Enter render loop
glutMainLoop();
return 0;
}
void NIAppIdle(void)
{
glutPostRedisplay();
}
void NIAppDisplay(void)
{
glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
float geometry[] =
{
-0.5f, 0.5f, 0.0f, 1.0f,
0.5f, -5.0f, 0.0f, 1.0f,
0.0f, 0.5f, 0.0f, 1.0f
};
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 4, GL_FLOAT, 0, 0, geometry);
glDrawArrays(GL_TRIANGLES, 0, 3);
glutSwapBuffers();
}
The problem is with the "glEnableVertexAttribArray" and "glVertexAttribPointer" functions.
The compiler says that they are "not declared it this scope".
Program can run without those lines, so I guess OpenGL is linked properly, but I simply can't use those functions for some reason, and I know they are a part of OpenGL.
Is it something to do with the version of OpenGL I have or something?
Anyway, it is my first time learning OpenGL, I've probably done something horribly wrong, so I'm asking for somebody to help me. I'm sorry if this post seems a bit crappy, this is also my first time posting in this site. Also I'm sorry for my grammar, English isn't my first language.
I think you can only get to glEnableVertexAttribArray by manually loading the function pointer for it. If all you want to do is create a simple hello world program, I'd recommend you use GLEW to handle that for you.

Another OpenGL SuperBible 5th edition set-up problems

Well, i have just bought this opengl superbible book (5th edition). Unfortunately, i stumbled upon on first chapter as how to set up the opengl itself. Here is the step that i did.
(1) First of all i installed Microsoft Visual Studio 2010 C++ Express.
(2) I downloaded the libraries needed, as for this i downloaded directly from the official site of opengl superbible : http://www.starstonesoftware.com/files/SB5.zip. Then i extracted the files into my local folder.
(3) And then i create new empty project.
File -> New -> Project -> Visual C++ Installed Templates -> General -> Empty Projects
(4) Adding the additional include directories path for freeglut and gltools files header.
Project -> Properties -> Configuration Properties -> (then i set the configuration = All configuration) -> C/C++ -> General -> Additional Include Directories.
here i add two directories :
(a) freeglut : [my local path]\SB5\freeglut-2.6.0\include
(b) gltools : [my local path]\SB5\Src\GLTools\include
(5) Adding the additional dependencies path for also freeglut and gltools files header.
Project -> Properties -> Configuration Properties -> (then i set the configuration = All configuration) -> Linker -> Input -> Additional dependecies.
(a)freeglut_static.lib
(b)GLTools.lib
(6) Adding the library directories.
Project -> Properties -> Configuration Properties -> (then i set the configuration = All configuration) -> VC++ Directories -> Library Directories.
In here i set the locations of directories of freeglut_static.lib and GLTools.lib
(a)freeglut_static.lib : [my local path]\SB5\freeglut-2.6.0\VisualStudio2008Static\Release
(b)GLTools.lib : [my local path]\SB5\VisualStudio2008\GLTools\Release
(7) After that i copy the source code (Triangle.cpp) but i didn't forget to include windows.h at first line.
// Triangle.cpp
// Our first OpenGL program that will just draw a triangle on the screen.
#include <Windows.h>
#include <GLTools.h> // OpenGL toolkit
#include <GLShaderManager.h> // Shader Manager Class
#ifdef __APPLE__
#include <glut/glut.h> // OS X version of GLUT
#else
#define FREEGLUT_STATIC
#include <GL/glut.h> // Windows FreeGlut equivalent
#endif
GLBatch triangleBatch;
GLShaderManager shaderManager;
///////////////////////////////////////////////////////////////////////////////
// Window has changed size, or has just been created. In either case, we need
// to use the window dimensions to set the viewport and the projection matrix.
void ChangeSize(int w, int h)
{
glViewport(0, 0, w, h);
}
///////////////////////////////////////////////////////////////////////////////
// This function does any needed initialization on the rendering context.
// This is the first opportunity to do any OpenGL related tasks.
void SetupRC()
{
// Blue background
glClearColor(0.0f, 0.0f, 1.0f, 1.0f );
shaderManager.InitializeStockShaders();
// Load up a triangle
GLfloat vVerts[] = { -0.5f, 0.0f, 0.0f,
0.5f, 0.0f, 0.0f,
0.0f, 0.5f, 0.0f };
triangleBatch.Begin(GL_TRIANGLES, 3);
triangleBatch.CopyVertexData3f(vVerts);
triangleBatch.End();
}
///////////////////////////////////////////////////////////////////////////////
// Called to draw scene
void RenderScene(void)
{
// Clear the window with current clearing color
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
GLfloat vRed[] = { 1.0f, 0.0f, 0.0f, 1.0f };
shaderManager.UseStockShader(GLT_SHADER_IDENTITY, vRed);
triangleBatch.Draw();
// Perform the buffer swap to display back buffer
glutSwapBuffers();
}
///////////////////////////////////////////////////////////////////////////////
// Main entry point for GLUT based programs
int main(int argc, char* argv[])
{
gltSetWorkingDirectory(argv[0]);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL);
glutInitWindowSize(800, 600);
glutCreateWindow("Triangle");
glutReshapeFunc(ChangeSize);
glutDisplayFunc(RenderScene);
GLenum err = glewInit();
if (GLEW_OK != err) {
fprintf(stderr, "GLEW Error: %s\n", glewGetErrorString(err));
return 1;
}
SetupRC();
glutMainLoop();
return 0;
}
(8) After step 7 i build the project and everything still went smoothly. Here was the build result :
1>------ Build started: Project: superbible1, Configuration: Debug Win32 ------
1> main.cpp
1>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>GLTools.lib(GLBatch.obj) : warning LNK4099: PDB 'vc90.pdb' was not found with 'GLTools.lib(GLBatch.obj)' or at 'C:\Documents and Settings\Tony\My Documents\Visual Studio 2010\Projects\superbible1\Debug\vc90.pdb'; linking object as if no debug info
1>GLTools.lib(glew.obj) : warning LNK4099: PDB 'vc90.pdb' was not found with 'GLTools.lib(glew.obj)' or at 'C:\Documents and Settings\Tony\My Documents\Visual Studio 2010\Projects\superbible1\Debug\vc90.pdb'; linking object as if no debug info
1>GLTools.lib(GLShaderManager.obj) : warning LNK4099: PDB 'vc90.pdb' was not found with 'GLTools.lib(GLShaderManager.obj)' or at 'C:\Documents and Settings\Tony\My Documents\Visual Studio 2010\Projects\superbible1\Debug\vc90.pdb'; linking object as if no debug info
1>GLTools.lib(GLTools.obj) : warning LNK4099: PDB 'vc90.pdb' was not found with 'GLTools.lib(GLTools.obj)' or at 'C:\Documents and Settings\Tony\My Documents\Visual Studio 2010\Projects\superbible1\Debug\vc90.pdb'; linking object as if no debug info
1>GLTools.lib(GLTriangleBatch.obj) : warning LNK4099: PDB 'vc90.pdb' was not found with 'GLTools.lib(GLTriangleBatch.obj)' or at 'C:\Documents and Settings\Tony\My Documents\Visual Studio 2010\Projects\superbible1\Debug\vc90.pdb'; linking object as if no debug info
1> superbible1.vcxproj -> C:\Documents and Settings\Tony\My Documents\Visual Studio 2010\Projects\superbible1\Debug\superbible1.exe
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
(9) The problem came when i run the program. I get runtime error. There was an alert dialog with this message :
Unhandled exception at 0x00000000 in superbible1.exe: 0xC0000005: Access violation reading location 0x00000000.
When i choose to break the program, the cursor was stoped in this line :
GLfloat vVerts[] = { -0.5f, 0.0f, 0.0f,
0.5f, 0.0f, 0.0f,
0.0f, 0.5f, 0.0f };
Well if i change this code with another simple code (from opengl redbook). For example like this :
#define FREEGLUT_STATIC
#include <Windows.h>
#include <GL\glut.h>
void display(void)
{
/* clear window */
glClear(GL_COLOR_BUFFER_BIT);
/* draw unit square polygon */
glBegin(GL_POLYGON);
glVertex2f(-0.5, -0.5);
glVertex2f(-0.5, 0.5);
glVertex2f(0.5, 0.5);
glVertex2f(0.5, -0.5);
glEnd();
/* flush GL buffers */
glFlush();
}
void init()
{
/* set clear color to black */
/* glClearColor (0.0, 0.0, 0.0, 0.0); */
/* set fill color to white */
/* glColor3f(1.0, 1.0, 1.0); */
/* set up standard orthogonal view with clipping */
/* box as cube of side 2 centered at origin */
/* This is default view and these statement could be removed */
/* glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); */
}
int main(int argc, char** argv)
{
/* Initialize mode and open a window in upper left corner of screen */
/* Window title is name of program (arg[0]) */
/* You must call glutInit before any other OpenGL/GLUT calls */
glutInit(&argc,argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(0,0);
glutCreateWindow("simple");
glutDisplayFunc(display);
init();
glutMainLoop();
}
The application can run well. So i thought maybe there was something wrong with the code or probably there was something that i miss. So anyone can help?
I am just starting on this as well.
If you are going to work through all the examples it is better to copy all the freeglut/GLTools .h and .lib files into the relevant directories of VC++2010.
You will still have to include the windows.h in the source and still have to specifically tell VC++2010 use GLTools.lib(Linker,Input,Additional Dependancies).
This
apparently explains how to get rid of all the pdb errors if they bother you.
GLfloat vVerts[] = { -0.5f, 0.0f, 0.0f, ... can't be the problem. butVisual's green debugging cursor show the NEXT line that will be executed, so I suspect that it's shaderManager.InitializeStockShaders(); that crashes.
I have no idea what this does, but it probably reads files... make sure it finds them. In particular, running the .exe directly from the Explorer from a directory that seems to make sense, depending on the contents of the zip.

Opengl superbible 5th edition code problem

I've started reading superbible 5th edition and I'm stuck at the first program. As I'm using xp & vs2008, I've followed all the instruction provided by the book to setup the vs2008 to run the triangle program, but after compilation process it shows an error and I've no idea why is this happenning. The program is following:
// Triangle.cpp
// Our first OpenGL program that will just draw a triangle on the screen.
#include <GLTools.h> // OpenGL toolkit
#include <GLShaderManager.h> // Shader Manager Class
#ifdef __APPLE__
#include <glut/glut.h> // OS X version of GLUT
#else
#define FREEGLUT_STATIC
#include <GL/glut.h> // Windows FreeGlut equivalent
#endif
GLBatch triangleBatch;
GLShaderManager shaderManager;
///////////////////////////////////////////////////////////////////////////////
// Window has changed size, or has just been created. In either case, we need
// to use the window dimensions to set the viewport and the projection matrix.
void ChangeSize(int w, int h)
{
glViewport(0, 0, w, h);
}
///////////////////////////////////////////////////////////////////////////////
// This function does any needed initialization on the rendering context.
// This is the first opportunity to do any OpenGL related tasks.
void SetupRC()
{
// Blue background
glClearColor(0.0f, 0.0f, 1.0f, 1.0f );
shaderManager.InitializeStockShaders();
// Load up a triangle
GLfloat vVerts[] = { -0.5f, 0.0f, 0.0f,
0.5f, 0.0f, 0.0f,
0.0f, 0.5f, 0.0f };
triangleBatch.Begin(GL_TRIANGLES, 3);
triangleBatch.CopyVertexData3f(vVerts);
triangleBatch.End();
}
///////////////////////////////////////////////////////////////////////////////
// Called to draw scene
void RenderScene(void)
{
// Clear the window with current clearing color
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
GLfloat vRed[] = { 1.0f, 0.0f, 0.0f, 1.0f };
shaderManager.UseStockShader(GLT_SHADER_IDENTITY, vRed);
triangleBatch.Draw();
// Perform the buffer swap to display the back buffer
glutSwapBuffers();
}
///////////////////////////////////////////////////////////////////////////////
// Main entry point for GLUT based programs
int main(int argc, char* argv[])
{
gltSetWorkingDirectory(argv[0]);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL);
glutInitWindowSize(800, 600);
glutCreateWindow("Triangle");
glutReshapeFunc(ChangeSize);
glutDisplayFunc(RenderScene);
GLenum err = glewInit();
if (GLEW_OK != err) {
fprintf(stderr, "GLEW Error: %s\n", glewGetErrorString(err));
return 1;
}
SetupRC();
glutMainLoop();
return 0;
}
And the error displaying is this
1>d:\opengl\SB5\freeglut-2.6.0\VisualStudio2008Static\Release\freeglut_static.lib : fatal error LNK1107: invalid or corrupt file: cannot read at 0x3
1>Build log was saved at "file://c:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\dfdf\Debug\BuildLog.htm"
Could somebody please help me with this problem? Thank you.
I think your problem lays somewhere else than code. I've traced back what is
#define FREEGLUT_STATIC
doing and this popped out:
# ifdef FREEGLUT_STATIC
# define FGAPI
# define FGAPIENTRY
/* Link with Win32 static freeglut lib */
# if FREEGLUT_LIB_PRAGMAS
# pragma comment (lib, "freeglut_static.lib")
# endif
However if you downloaded prepared package from freeglut Windows Development Libraries, you get only freeglut.lib. So either you have to build "freeglut_static.lib" for yourself from freeglut, or don't use static macro and you should be fine. Linker is just saying what it's experiencing - can't find your file so not able to read...
and BTW: What book instructs is one thing but maybe you skipped something or they just didn't included it, but when you download clean freeglut, VisualStudio2008Static folder doesn't contain any library just another folders and visual studio project. You need to open that project, select release version in MSVC (build-> configuration manager) and build project. You get you freeglut_static.lib in release folder.
The error message you're getting indicates that the freeglut_static.lib file is corrupt. You would be best off to reinstall the library to ensure the file was copied correctly, or you could try rebuilding the library from source.
It might be worth trying a prebuilt version from another website, maybe you'll have more luck with the Visual Studio version available here.

OpenGL superbible access violation

Well, I've searched a bit around and the only advice I see people really giving is kind of ambiguous, slightly outdated drivers possibly (mine is the latest Geforce G210m mobile driver). Anyways, I'm just learning OpenGL and having learned some XNA, I feel this will be a good balance but I could do without having such frustration in the beginning.
Anyways, I'm simply using the source straight from Triangle.cpp. I am getting:
Unhandled exception at 0x00000000 in OOGL.exe: 0xC0000005: Access violation.
Right after the call to triangleBatch.Begin().
Can anyone tell me straight forwardly what is up and how to alleviate this?
Here is the source:
// Triangle.cpp
// Our first OpenGL program that will just draw a triangle on the screen.
#include <GLTools.h> // OpenGL toolkit
#include <GLShaderManager.h> // Shader Manager Class
#ifdef __APPLE__
#include <glut/glut.h> // OS X version of GLUT
#else
#define FREEGLUT_STATIC
#include <GL/glut.h> // Windows FreeGlut equivalent
#endif
GLBatch triangleBatch;
GLShaderManager shaderManager;
///////////////////////////////////////////////////////////////////////////////
// Window has changed size, or has just been created. In either case, we need
// to use the window dimensions to set the viewport and the projection matrix.
void ChangeSize(int w, int h)
{
glViewport(0, 0, w, h);
}
///////////////////////////////////////////////////////////////////////////////
// This function does any needed initialization on the rendering context.
// This is the first opportunity to do any OpenGL related tasks.
void SetupRC()
{
// Blue background
glClearColor(0.0f, 0.0f, 1.0f, 1.0f );
shaderManager.InitializeStockShaders();
// Load up a triangle
GLfloat vVerts[] = { -0.5f, 0.0f, 0.0f,
0.5f, 0.0f, 0.0f,
0.0f, 0.5f, 0.0f };
triangleBatch.Begin(GL_TRIANGLES, 3);
triangleBatch.CopyVertexData3f(vVerts);
triangleBatch.End();
}
///////////////////////////////////////////////////////////////////////////////
// Called to draw scene
void RenderScene(void)
{
// Clear the window with current clearing color
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
GLfloat vRed[] = { 1.0f, 0.0f, 0.0f, 1.0f };
shaderManager.UseStockShader(GLT_SHADER_IDENTITY, vRed);
triangleBatch.Draw();
// Perform the buffer swap to display back buffer
glutSwapBuffers();
}
///////////////////////////////////////////////////////////////////////////////
// Main entry point for GLUT based programs
int main(int argc, char* argv[])
{
gltSetWorkingDirectory(argv[0]);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL);
glutInitWindowSize(800, 600);
glutCreateWindow("Triangle");
glutReshapeFunc(ChangeSize);
glutDisplayFunc(RenderScene);
GLenum err = glewInit();
if (GLEW_OK != err) {
fprintf(stderr, "GLEW Error: %s\n", glewGetErrorString(err));
return 1;
}
SetupRC();
glutMainLoop();
return 0;
}
By looking at the code of GLBatch, and looking at the error, it is almost certain that either the GL_ARB_vertex_array_object or GL_ARB_vertex_buffer_object extension is missing on your computer. The code doesn't check, so that is why it falls.
Sollution? If it fails in GLBatch.cpp at the line where glGenVertexArrays() is called, simply #define OPENGL_ES at the beginning of the file, it will disable vertex array objects and everything will be fine (it is a new extension and it might not be supported by your GPU). In case it fails at glGenBuffers(), then there is probably no code remedy. You need to make sure that you have the latest graphics card drivers and that the GL_ARB_vertex_buffer_object extension is supported (you can use OpenGL Extension Viewer).