PDA

View Full Version : SuperBible 5th First program problems with Linux



pondwater
10-29-2010, 08:24 PM
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++
CFLAGS = $(COMPILERFLAGS) -g $(INCDIRS)
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)

clean:
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
#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(&amp;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;
}

marshats
10-30-2010, 05:18 PM
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
make
./Triangle


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

Salvo
11-07-2010, 06:02 AM
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
make
./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.

Salvo

Salvo
11-07-2010, 06:17 AM
Well done, but now this is what happen:

Linux/Chapter01/Block$ ./Block
Segmentation fault

I downloaded this sources with:

svn checkout http://oglsuperbible5.googlecode.com/svn/trunk/ oglsuperbible5-read-only

Henry Rust
11-07-2010, 09:37 AM
Well done, but now this is what happen:

Linux/Chapter01/Block$ ./Block
Segmentation fault

I downloaded this sources with:

svn checkout http://oglsuperbible5.googlecode.com/svn/trunk/ 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.

Salvo
11-07-2010, 10:54 AM
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

Henry Rust
11-08-2010, 06:47 AM
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/libGL.so | 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.

Salvo
11-08-2010, 10:10 AM
Ok, in another computer (radeon HD) it is working well.

Thank you.

Salvo