3

I've recently started learning OpenGl through the SB fifth edition, unfortunately got stuck right at the first example they provide.

Here's the code:

#include <GLTools.h>
#include <GLShaderManager.h>
#include <GL/glew.h>
#include <GL/glut.h>


GLShaderManager shaderManager;
GLBatch triangleBatch;
void ChangeSize(GLsizei w, GLsizei h);

void ChangeSize(int w, int h){
    glViewport(0,0,w,h);
}

void SetupRC(){
    //background
    glClearColor(0.0f, 0.0f, 1.0f, 1.0f);


    shaderManager.InitializeStockShaders();

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

}

void RenderScene(void){

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


    glutSwapBuffers();
}


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;
}    

Though, I don't think the problem lies in the code because I've simply copy pasted it from the book. I've added the libraries included in the book's contents and also installed freeglut. So now he finds all the headers I need however there is a huge list of issues not related to triangle.cpp in itself, when I try to build. Here are some:

1>c:\users\whatever\desktop\sb5\src\gltools\include\gltools.h(183): warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
1>c:\users\whatever\desktop\sb5\src\gltools\include\gltools.h(183): error C2059: syntax error : ')'
1>c:\users\whatever\desktop\sb5\src\gltools\include\gltools.h(184): error C2146: syntax error : missing ')' before identifier 'width'
1>c:\users\whatever\desktop\sb5\src\gltools\include\gltools.h(184): error C2182: 'gltGenerateOrtho2DMat' : illegal use of type 'void'
1>c:\users\whatever\desktop\sb5\src\gltools\include\gltools.h(184): error C2059: syntax error : ')'
1>c:\users\whatever\desktop\sb5\src\gltools\include\gl\glew.h(234): error C2378: 'GLuint' : redefinition; symbol cannot be overloaded with a typedef
1>          c:\users\whatever\desktop\sb5\src\gltools\include\gltools.h(177) : see declaration of 'GLuint'
1>c:\users\whatever\desktop\sb5\src\gltools\include\gl\glew.h(235): error C2378: 'GLint' : redefinition; symbol cannot be overloaded with a typedef
1>c:\users\whatever\desktop\sb5\src\gltools\include\gltools.h(162) : see declaration of 'GLint'
1>c:\users\whatever\desktop\sb5\src\gltools\include\gl\glew.h(238): error C2378: 'GLbyte' : redefinition; symbol cannot be overloaded with a typedef
1>          c:\users\whatever\desktop\sb5\src\gltools\include\gltools.h(153) : see declaration of 'GLbyte'
1>c:\users\whatever\desktop\sb5\src\gltools\include\gl\glew.h(804): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\whatever\desktop\sb5\src\gltools\include\gl\glew.h(804): error C2143: syntax error : missing ',' before '*'
1>c:\users\whatever\desktop\sb5\src\gltools\include\gl\glew.h(805): error C2146: syntax error : missing ')' before identifier 'i'
1>c:\users\whatever\desktop\sb5\src\gltools\include\gl\glew.h(805): warning C4229: anachronism used : modifiers on data are ignored
1>c:\users\whatever\desktop\sb5\src\gltools\include\gl\glew.h(805): error C2182: 'glArrayElement' : illegal use of type 'void'
1>c:\users\whatever\desktop\sb5\src\gltools\include\gl\glew.h(805): error C2491: 'glArrayElement' : definition of dllimport data not allowed
1>c:\users\whatever\desktop\sb5\src\gltools\include\gl\glew.h(805): error C2059: syntax error : ')'
1>c:\users\whatever\desktop\sb5\src\gltools\include\gl\glew.h(807): error C2061: syntax error : identifier 'GLuint'
1>c:\users\whatever\desktop\sb5\src\gltools\include\gl\glew.h(810): error C2146: syntax error : missing ')' before identifier 'list'
1>c:\users\whatever\desktop\sb5\src\gltools\include\gl\glew.h(810): warning C4229: anachronism used : modifiers on data are ignored
1>c:\users\whatever\desktop\sb5\src\gltools\include\gl\glew.h(810): error C2182: 'glCallList' : illegal use of type 'void'
1>c:\users\whatever\desktop\sb5\src\gltools\include\gl\glew.h(810): error C2491: 'glCallList' : definition of dllimport data not allowed
1>c:\users\whatever\desktop\sb5\src\gltools\include\gl\glew.h(810): error C2059: syntax error : ')'
1>c:\users\whatever\desktop\sb5\src\gltools\include\gl\glew.h(817): error C2146: syntax error : missing ')' before identifier 's'
1>c:\users\whatever\desktop\sb5\src\gltools\include\gl\glew.h(817): warning C4229: anachronism used : modifiers on data are ignored
1>c:\users\whatever\desktop\sb5\src\gltools\include\gl\glew.h(817): error C2182: 'glClearStencil' : illegal use of type 'void'
1>c:\users\whatever\desktop\sb5\src\gltools\include\gl\glew.h(817): error C2491:     'glClearStencil' : definition of dllimport data not allowed

I really can't make anything out of this. It looks as if the errors are in the header themselves. Like these there are hundred more and from other header files. I hope I was explicit enough with the problem I'm trying to expose. If something was not clear please feel free to ask. I'll try to be less vague

Also, I'm using Microsoft Visual C++ 2010.

Sergey K.
  • 24,894
  • 13
  • 106
  • 174
Paraphiliac Ostrich
  • 1,270
  • 2
  • 11
  • 25
  • 1
    Have you tried [downloading the source code](http://code.google.com/p/oglsuperbible5/) and just compiling it directly, rather than copying into your own projects? – Nicol Bolas Feb 19 '12 at 16:17
  • 1
    I have. And the odd (or not) thing is that even though in that particular file I get the same problem, other projects build and run just fine. – Paraphiliac Ostrich Feb 19 '12 at 17:34

1 Answers1

2

Since you're working on Windows, you will have to include windows.h before gl.h. I'm not sure about the other headers you've included, but make sure check for that. A different order will usually cause these warnings and errors to appear.

Bart
  • 19,692
  • 7
  • 68
  • 77
  • wow. as simple as that. One would think they'd mention it somewhere. then again, maybe the book is not intended for complete amateurs such as myself. Thanks! however, a new problem came to replace the one you just solved: 1>triangle.obj : error LNK2019: unresolved external symbol "public: void __thiscall GLBatch::End(void)" (?End@GLBatch@@QAEXXZ) referenced in function "void __cdecl SetupRC(void)" (?SetupRC@@YAXXZ) 12 more errors similar to that have shown. I've done a quick search and that's related to some missing librarys? thought I had everything in order, apparently not. any ideas? – Paraphiliac Ostrich Feb 19 '12 at 17:13
  • Having a quick look at your second problem, it seems something similar has been asked before: http://stackoverflow.com/questions/4123082/linker-error-during-opengl-superbible-tutorial In short, you will need to link against gltools.lib, which I assume is a library belonging to the book's sources... – Bart Feb 19 '12 at 17:21
  • Unfortunately, the suggested solution in that thread did not work for me. I've done all what's stated part from the "include glut32.dll in my Solution directory" bit because I think that's beside the scope of the problem. But the LNK errors remain – Paraphiliac Ostrich Feb 19 '12 at 17:40