Domanda

Di recente ho iniziato a imparare OpenGL attraverso la quinta edizione SB, purtroppo sono rimasto bloccato proprio al primo esempio che forniscono.

Ecco il codice:

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

Tuttavia, non credo che il problema sia nel codice perché l'ho semplicemente copiato incollato dal libro. Ho aggiunto le biblioteche incluse nel contenuto del libro e ho anche installato FreeGlut. Quindi ora trova tutte le intestazioni di cui ho bisogno, tuttavia c'è un enorme elenco di problemi non legati a Triangle.CPP in sé, quando provo a costruire. Eccotene alcune:

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

Non riesco davvero a farne nulla. Sembra che gli errori siano nell'intestazione stessi. Come questi ce ne sono altri centinaia e da altri file di intestazione. Spero di essere abbastanza esplicito con il problema che sto cercando di esporre. Se qualcosa non era chiaro, non esitare a chiedere. Cercherò di essere meno vago

Inoltre, sto usando Microsoft Visual C ++ 2010.

È stato utile?

Soluzione

Dato che stai lavorando su Windows, dovrai includere windows.h prima gl.h. Non sono sicuro delle altre intestazioni che hai incluso, ma assicurati di verificarlo. Un ordine diverso di solito farà apparire questi avvertimenti ed errori.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top