簡體   English   中英

OpenGL SuperBible 5版的另一個設置問題

[英]Another OpenGL SuperBible 5th edition set-up problems

好吧,我剛剛買了這本opengl精美圖書(第5版)。 不幸的是,我在第一章偶然發現了如何設置opengl本身。 這是我所做的步驟。

(1)首先,我安裝了Microsoft Visual Studio 2010 C ++ Express

(2)我下載了所需的庫,為此,我直接從opengl superbible的官方網站下載: http : //www.starstonesoftware.com/files/SB5.zip 然后,我將文件提取到本地文件夾中。

(3)然后我創建一個新的空項目。
文件->新建->項目-> Visual C ++安裝的模板->常規->空項目

(4)為freeglut和gltools文件頭添加其他包含目錄路徑。
項目->屬性->配置屬性->(然后設置配置=所有配置)-> C / C ++->常規->其他包含目錄。
在這里我添加兩個目錄:
(a)freeglut:[我的本地路徑] \\ SB5 \\ freeglut-2.6.0 \\ include
(b)gltools:[我的本地路徑] \\ SB5 \\ Src \\ GLTools \\ include

(5)為freeglut和gltools文件頭添加附加的依賴路徑。
項目->屬性->配置屬性->(然后設置配置=所有配置)->鏈接器->輸入->其他依賴項。
(a)freeglut_static.lib
(b)GLTools.lib

(6)添加庫目錄。
項目->屬性->配置屬性->(然后我設置配置=所有配置)-> VC ++目錄->庫目錄。 在這里,我設置freeglut_static.lib和GLTools.lib目錄的位置
(a)freeglut_static.lib:[我的本地路徑] \\ SB5 \\ freeglut-2.6.0 \\ VisualStudio2008Static \\ Release
(b)GLTools.lib:[我的本地路徑] \\ SB5 \\ VisualStudio2008 \\ GLTools \\ Release

(7)之后,我復制了源代碼(Triangle.cpp),但我沒有忘記在第一行中包含windows.h

// 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)在第7步之后,我構建了項目,一切仍然順利進行。 這是構建結果:

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)我運行程序時出現問題。 我收到運行時錯誤。 有一個警告對話框,顯示以下消息:

Unhandled exception at 0x00000000 in superbible1.exe: 0xC0000005: Access violation reading location 0x00000000.

當我選擇中斷程序時,光標在此行停止:

   GLfloat vVerts[] = { -0.5f, 0.0f, 0.0f, 
                          0.5f, 0.0f, 0.0f,
                          0.0f, 0.5f, 0.0f };

好吧,如果我用另一個簡單的代碼(來自opengl紅皮書)更改此代碼。 例如這樣:

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

}

該應用程序可以正常運行。 所以我認為代碼可能有問題,或者我想念一些東西。 有誰可以幫忙嗎?

我也是剛剛開始。

如果要遍歷所有示例,最好將所有freeglut / GLTools .h.lib文件復制到VC ++ 2010的相關目錄中。

您仍然必須在源代碼中包含windows.h ,並且仍然必須明確告訴VC ++ 2010使用GLTools.lib (鏈接器,輸入,其他相關性)。

顯然, 說明了如何消除所有困擾您的pdb錯誤。

GLfloat vVerts[] = { -0.5f, 0.0f, 0.0f, ...不會是問題。 但是VisualVisual的綠色調試光標顯示將要執行的NEXT行,因此我懷疑它是shaderManager.InitializeStockShaders();。 崩潰了。

我不知道這是做什么的,但是它可能讀取文件...確保找到了文件。 特別是,根據zip的內容,從似乎合理的目錄中直接從資源管理器中運行.exe。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM