SuperBible 5th First program problems with Linux

Hi, i’m very new to OpenGl. I recently bought the 5th edition book and am very frustrated as they dont provide any instruction for linux users on how to set up a project.

I have opengl set up, i have GLUT set up

I also downloaded the source directory for 5th edition with the GLTools and grew libraries in a fodler called ‘SB5’

I copied the Makefile from the linux src files and the .cpp from the windows src files (there is no .cpp provided in the linux folder)

I get one error when compiling:

make: *** No rule to make target ‘all’.

Resource: Triangle
Location line 0
Type: C/C++ Problem

I believe the problem may have to do with the directories being referenced for ‘SRCPATH’ ‘SHAREDPATH’ and ‘SHAREDINCPATH’.

I have all the source files in a folder named ‘SB5’. Is there a specific place this should be kept on my drive?

Do i have to edit the …/…/…/ part of the makefile?

Heres my Makefile:

MAIN = Triangle
SRCPATH = ../../../Src/Chapter02/$(MAIN)/
SHAREDPATH = ../../../Src/GLTools/src/
SHAREDINCPATH = ../../../Src/GLTools/include/
LIBDIRS = -L/usr/X11R6/lib -L/usr/X11R6/lib64 -L/usr/local/lib
INCDIRS = -I/usr/include -I/usr/local/include -I/usr/include/GL -I$(SHAREDINCPATH)  -I$(SHAREDINCPATH)GL

CC = g++
LIBS = -lX11 -lglut -lGL -lGLU -lm

prog : $(MAIN)

$(MAIN).o : $(SRCPATH)$(MAIN).cpp
glew.o    : $(SHAREDPATH)glew.c
GLTools.o    : $(SHAREDPATH)GLTools.cpp
GLBatch.o    : $(SHAREDPATH)GLBatch.cpp
GLTriangleBatch.o    : $(SHAREDPATH)GLTriangleBatch.cpp
GLShaderManager.o    : $(SHAREDPATH)GLShaderManager.cpp
math3d.o    : $(SHAREDPATH)math3d.cpp

$(MAIN) : $(MAIN).o glew.o
	$(CC) $(CFLAGS) -o $(MAIN) $(LIBDIRS) $(SRCPATH)$(MAIN).cpp $(SHAREDPATH)glew.c $(SHAREDPATH)GLTools.cpp $(SHAREDPATH)GLBatch.cpp $(SHAREDPATH)GLTriangleBatch.cpp $(SHAREDPATH)GLShaderManager.cpp $(SHAREDPATH)math3d.cpp $(LIBS)

	rm -f *.o

I dont think it has anything to do with the .cpp since its the exact source given, but in any case for reference here is my Triangle.cpp:

// 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
#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 );

	// 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);

// Called to draw scene
void RenderScene(void)
	// Clear the window with current clearing color

	GLfloat vRed[] = { 1.0f, 0.0f, 0.0f, 1.0f };
	shaderManager.UseStockShader(GLT_SHADER_IDENTITY, vRed);

	// Perform the buffer swap to display back buffer

// Main entry point for GLUT based programs
int main(int argc, char* argv[])
	glutInit(&argc, argv);
	glutInitWindowSize(800, 600);

	GLenum err = glewInit();
	if (GLEW_OK != err) {
		fprintf(stderr, "GLEW Error: %s
", glewGetErrorString(err));
		return 1;

	return 0;

If I download the source and change to the Linux project specific directory and type make then it compiles fine for me on Ubuntu 10.02 ie

cd Linux/Chapter02/Triangle

Does this approach fail for you? If it fails please post the errors you get when running make.

Hi, I have troubles with GLTools.cpp too.

My compiler version in ubuntu 10.10:
cc (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5

My problem:

Linux/Chapter01/Block$ make

…/…/…/Src/GLTools/src/GLTools.cpp:1262: error: jump to label ‘failed’
…/…/…/Src/GLTools/src/GLTools.cpp:1214: error: from here
…/…/…/Src/GLTools/src/GLTools.cpp:1233: error: crosses initialization of ‘int iArgCount’
…/…/…/Src/GLTools/src/GLTools.cpp:1262: error: jump to label ‘failed’
…/…/…/Src/GLTools/src/GLTools.cpp:1208: error: from here
…/…/…/Src/GLTools/src/GLTools.cpp:1233: error: crosses initialization of ‘int iArgCount’
…/…/…/Src/GLTools/src/GLTools.cpp:1262: error: jump to label ‘failed’
…/…/…/Src/GLTools/src/GLTools.cpp:1200: error: from here
…/…/…/Src/GLTools/src/GLTools.cpp:1233: error: crosses initialization of ‘int iArgCount’
…/…/…/Src/GLTools/src/GLTools.cpp:1262: error: jump to label ‘failed’
…/…/…/Src/GLTools/src/GLTools.cpp:1194: error: from here
…/…/…/Src/GLTools/src/GLTools.cpp:1233: error: crosses initialization of ‘int iArgCount’
…/…/…/Src/GLTools/src/GLTools.cpp:1262: error: jump to label ‘failed’
…/…/…/Src/GLTools/src/GLTools.cpp:1187: error: from here
…/…/…/Src/GLTools/src/GLTools.cpp:1233: error: crosses initialization of ‘int iArgCount’
…/…/…/Src/GLTools/src/GLTools.cpp:1262: error: jump to label ‘failed’
…/…/…/Src/GLTools/src/GLTools.cpp:1181: error: from here
…/…/…/Src/GLTools/src/GLTools.cpp:1233: error: crosses initialization of ‘int iArgCount’
make: *** [Block] Errore 1

I am changing the iArgCount declaration to solve this problem.


Well done, but now this is what happen:

Linux/Chapter01/Block$ ./Block
Segmentation fault

I downloaded this sources with:

svn checkout oglsuperbible5-read-only

Are you sure you have installed drivers which support at least OpenGL 3.3. The program uses glew to load the function pointers, but don’t check whether the target version of OpenGL is available. So it may dereference an null pointer which leads to a Segmentation fault.

This is the last line executed before the error in GLTools.cpp:

// Load a pair of shaders, compile, and link together. Specify the complete
// source code text for each shader. Note, there is no support for
// just loading say a vertex program… you have to do both.
GLuint gltLoadShaderPairSrcWithAttributes(const char *szVertexSrc, const char *szFragmentSrc, …)
// Temporary Shader objects
GLuint hVertexShader;
GLuint hFragmentShader;
GLuint hReturn = 0;
GLint testVal;

// Create shader objects

->> hVertexShader = glCreateShader(GL_VERTEX_SHADER);

Program received signal SIGSEGV, Segmentation fault.
0x00000000 in ?? ()
(gdb) bt
#0 0x00000000 in ?? ()
#1 0x08072339 in gltLoadShaderPairSrcWithAttributes (
szVertexSrc=0x8086aac “attribute vec4 vVertex;void main(void) { gl_Position = vVertex; }”,
szFragmentSrc=0x8086af0 “uniform vec4 vColor;void main(void) { gl_FragColor = vColor;}”)
at …/…/…/Src/GLTools/src/GLTools.cpp:1614
#2 0x08074d79 in GLShaderManager::InitializeStockShaders (this=0x808c460)
at …/…/…/Src/GLTools/src/GLShaderManager.cpp:324
#3 0x0804a6b6 in SetupRC () at …/…/…/Src/Chapter01/Block/Block.cpp:247
#4 0x0804bacd in main (argc=1, argv=0xbffff3a4) at …/…/…/Src/Chapter01/Block/Block.cpp:625

It seems that the glCreateShader function in not available with your OpenGL implementation. You can check this with the following command:

nm -D /usr/lib64/ | grep glCreateShader

If this prints anything, glCreateShader should be available and there is some other thing wrong. But if it prints nothing your must upgrade your graphic drivers or depending on which graphic card you have you may even have to buy a new one. That’s why your actual graphic card may not support the necessary OpenGL version. The 5th edition of the Superbible teaches you OpenGL 3.x, but some examples of the book may also work with OpenGL 2.1.

You can easily check your OpenGL version with

glxinfo | grep "OpenGL version"

But for you notice: This only tells you which OpenGL version your driver supports, the version supported by your card could be higher. In this case installing the latest drivers should help.

Ok, in another computer (radeon HD) it is working well.

Thank you.


This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.