Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: Need help with setting up libraries for OpenGL Programming Guide: The Official Guide

  1. #1
    Newbie Newbie
    Join Date
    Jun 2013
    Posts
    3

    Need help with setting up libraries for OpenGL Programming Guide: The Official Guide

    Im trying to get the code to compile but had no luck.
    I'm running windows 7 with vs 2012 on C++ code.
    OpenGL Programming Guide: The Official Guide to Learning OpenGL, Version 4.3: 8th Edition
    the book also includes some code and lib at this web
    opengl-redbook.com
    All of the programs contained within this book use the OpenGL Utility
    Toolkit (GLUT), originally authored by Mark Kilgard. For this edition, we use the open-source version of the GLUT interface from the folks
    developing the freeglut project. They have enhanced Mark’s original work
    (which is thoroughly documented in his book, OpenGL Programming for the
    X Window System, Addison-Wesley, 1997). You can find their open-source
    project page at the following address:
    freeglut.sourceforge.net
    ///////////////////////////////////////////////////////////////////////
    //
    // triangles.cpp
    //
    ///////////////////////////////////////////////////////////////////////
    #include <iostream>
    using namespace std;
    #include "vgl.h"
    #include "LoadShaders.h"
    enum VAO_IDs { Triangles, NumVAOs };
    enum Buffer_IDs { ArrayBuffer, NumBuffers };
    enum Attrib_IDs { vPosition = 0 };
    GLuint VAOs[NumVAOs];
    GLuint Buffers[NumBuffers];
    const GLuint NumVertices = 6;
    //---------------------------------------------------------------------
    //
    // init
    //
    void
    init(void)
    {
    glGenVertexArrays(NumVAOs, VAOs);
    glBindVertexArray(VAOs[Triangles]);
    GLfloat vertices[NumVertices][2] = {
    { -0.90, -0.90 }, // Triangle 1
    { 0.85, -0.90 },
    { -0.90, 0.85 },
    { 0.90, -0.85 }, // Triangle 2
    { 0.90, 0.90 },
    { -0.85, 0.90 }
    };
    glGenBuffers(NumBuffers, Buffers);
    glBindBuffer(GL_ARRAY_BUFFER, Buffers[ArrayBuffer]);
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices),
    vertices, GL_STATIC_DRAW);
    ShaderInfo shaders[] = {
    { GL_VERTEX_SHADER, "triangles.vert" },
    { GL_FRAGMENT_SHADER, "triangles.frag" },
    { GL_NONE, NULL }
    };
    GLuint program = LoadShaders(shaders);
    glUseProgram(program);
    glVertexAttribPointer(vPosition, 2, GL_FLOAT,
    GL_FALSE, 0, BUFFER_OFFSET(0));
    glEnableVertexAttribArray(vPosition);
    }
    //---------------------------------------------------------------------
    //
    // display
    //
    void
    display(void)
    {
    glClear(GL_COLOR_BUFFER_BIT);
    glBindVertexArray(VAOs[Triangles]);
    glDrawArrays(GL_TRIANGLES, 0, NumVertices);
    glFlush();
    }
    //---------------------------------------------------------------------
    //
    // main
    //
    int
    main(int argc, char** argv)
    {
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGBA);
    glutInitWindowSize(512, 512);
    glutInitContextVersion(4, 3);
    glutInitContextProfile(GLUT_CORE_PROFILE);
    glutCreateWindow(argv[0]);
    if (glewInit()) {
    cerr << "Unable to initialize GLEW ... exiting" << endl;
    exit(EXIT_FAILURE);
    }
    init();
    glutDisplayFunc(display);
    glutMainLoop();
    }

  2. #2
    Newbie Newbie
    Join Date
    Dec 2012
    Posts
    1
    Since you did not show any errors you are getting, I assume you have installed all the necessary dependancies.
    Here is a working version of that same triangles.cpp code taken from SO answer to similar question.

    #include <GL/glew.h>
    #include <GL/freeglut.h>
    #include <vector>
    #include <iostream>

    struct Program {

    static GLuint Load( const char* vert, const char* geom, const char* frag )
    {
    GLuint prog = glCreateProgram();
    if( vert ) AttachShader( prog, GL_VERTEX_SHADER, vert );
    if( geom ) AttachShader( prog, GL_GEOMETRY_SHADER, geom );
    if( frag ) AttachShader( prog, GL_FRAGMENT_SHADER, frag );
    glLinkProgram( prog );
    CheckStatus( prog );
    return prog;
    }

    private:
    static void CheckStatus( GLuint obj )
    {
    GLint status = GL_FALSE, len = 10;
    if( glIsShader(obj) ) glGetShaderiv( obj, GL_COMPILE_STATUS, &status );
    if( glIsProgram(obj) ) glGetProgramiv( obj, GL_LINK_STATUS, &status );
    if( status == GL_TRUE ) return;
    if( glIsShader(obj) ) glGetShaderiv( obj, GL_INFO_LOG_LENGTH, &len );
    if( glIsProgram(obj) ) glGetProgramiv( obj, GL_INFO_LOG_LENGTH, &len );
    std::vector< char > log( len, 'X' );
    if( glIsShader(obj) ) glGetShaderInfoLog( obj, len, NULL, &log[0] );
    if( glIsProgram(obj) ) glGetProgramInfoLog( obj, len, NULL, &log[0] );
    std::cerr << &log[0] << std::endl;
    exit( -1 );
    }

    static void AttachShader( GLuint program, GLenum type, const char* src )
    {
    GLuint shader = glCreateShader( type );
    glShaderSource( shader, 1, &src, NULL );
    glCompileShader( shader );
    CheckStatus( shader );
    glAttachShader( program, shader );
    glDeleteShader( shader );
    }
    };


    #define GLSL(version, shader) "#version " #version "\n" #shader


    const char* vert = GLSL
    (
    400 core,
    layout( location = 0 ) in vec4 vPosition;
    void main()
    {
    gl_Position = vPosition;
    }
    );

    const char* frag = GLSL
    (
    400 core,
    out vec4 fColor;
    void main()
    {
    fColor = vec4( 0.0, 0.0, 1.0, 1.0 );
    }
    );

    enum VAO_IDs { Triangles, NumVAOs };
    enum Buffer_IDs { ArrayBuffer, NumBuffers };
    enum Attrib_IDs { vPosition = 0 };

    GLuint VAOs[NumVAOs];
    GLuint Buffers[NumBuffers];

    //const GLuint NumVertices = 9;
    const GLuint NumVertices = 6;

    void init(void)
    {
    glGenVertexArrays(NumVAOs, VAOs);
    glBindVertexArray(VAOs[Triangles]);

    GLfloat vertices[NumVertices][2] = {
    { -0.70, -0.70 }, // Triangle 1
    { 0.65, -0.70 },
    { -0.70, 0.65 },
    { 0.70, -0.65 }, // Triangle 2
    { 0.70, 0.70 },
    { -0.65, 0.70 }

    // ,
    // { 0.75, 0.95 }, // Triangle 3
    // { 0.75, 0.75 },
    // { 0.70, 0.75 }
    };

    glGenBuffers(NumBuffers, Buffers);
    glBindBuffer(GL_ARRAY_BUFFER, Buffers[ArrayBuffer]);
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

    GLuint program = Program::Load( vert, NULL, frag );
    glUseProgram(program);

    glVertexAttribPointer(vPosition, 2, GL_FLOAT, GL_FALSE, 0, (void*)(0) );
    glEnableVertexAttribArray(vPosition);
    }

    void display(void)
    {
    glClear(GL_COLOR_BUFFER_BIT);

    glBindVertexArray(VAOs[Triangles]);
    glDrawArrays(GL_TRIANGLES, 0, NumVertices);

    glutSwapBuffers();
    }

    int main(int argc, char** argv)
    {
    glutInit(&argc, argv);
    glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE );
    glutInitWindowSize(512, 512);
    glutInitContextVersion(4, 0);
    glutInitContextProfile(GLUT_CORE_PROFILE);
    glutCreateWindow(argv[0]);

    glewExperimental = GL_TRUE;
    if( GLEW_OK != glewInit() )
    exit(EXIT_FAILURE);

    init();

    glutDisplayFunc(display);
    glutMainLoop();
    }


    Hope this helps.

  3. #3
    Newbie Newbie
    Join Date
    Jun 2013
    Posts
    3
    the code that comes with the book include the include and lib, media, makefile.
    I might be asking for to much but i can not get it to work, i made a folder like this
    Documents\Visual Studio 2012\Projects\OpenGLRedBook\Libraries\ for both include and libs folder just like it came in the site and i included them in the included directories.
    I only linked freeglut.lib,

    Unhandled exception at 0x74C2C9F5 in FirstOpenGL.exe: 0xC0000005: Access violation executing location 0x00000000.
    'FirstOpenGL.exe' (Win32): Loaded 'C:\Users\Alfredo Ruiz\Documents\Visual Studio 2012\Projects\OpenGLRedBook\FirstOpenGL\Debug\Firs tOpenGL.exe'. Symbols loaded.
    'FirstOpenGL.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Symbols loaded.
    'FirstOpenGL.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Symbols loaded.
    'FirstOpenGL.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. Symbols loaded.
    'FirstOpenGL.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp110d.dll'. Symbols loaded.
    'FirstOpenGL.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcr110d.dll'. Symbols loaded.
    'FirstOpenGL.exe' (Win32): Loaded 'C:\Windows\SysWOW64\opengl32.dll'. Symbols loaded.
    'FirstOpenGL.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcrt.dll'. Symbols loaded.
    'FirstOpenGL.exe' (Win32): Loaded 'C:\Windows\SysWOW64\advapi32.dll'. Symbols loaded.
    'FirstOpenGL.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sechost.dll'. Symbols loaded.
    'FirstOpenGL.exe' (Win32): Loaded 'C:\Windows\SysWOW64\rpcrt4.dll'. Symbols loaded.
    'FirstOpenGL.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sspicli.dll'. Symbols loaded.
    'FirstOpenGL.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cryptbase.dll'. Symbols loaded.
    'FirstOpenGL.exe' (Win32): Loaded 'C:\Windows\SysWOW64\gdi32.dll'. Symbols loaded.
    'FirstOpenGL.exe' (Win32): Loaded 'C:\Windows\SysWOW64\user32.dll'. Symbols loaded.
    'FirstOpenGL.exe' (Win32): Loaded 'C:\Windows\SysWOW64\lpk.dll'. Symbols loaded.
    'FirstOpenGL.exe' (Win32): Loaded 'C:\Windows\SysWOW64\usp10.dll'. Symbols loaded.
    'FirstOpenGL.exe' (Win32): Loaded 'C:\Windows\SysWOW64\glu32.dll'. Symbols loaded.
    'FirstOpenGL.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ddraw.dll'. Symbols loaded.
    'FirstOpenGL.exe' (Win32): Loaded 'C:\Windows\SysWOW64\dciman32.dll'. Symbols loaded.
    'FirstOpenGL.exe' (Win32): Loaded 'C:\Windows\SysWOW64\setupapi.dll'. Symbols loaded.
    'FirstOpenGL.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cfgmgr32.dll'. Symbols loaded.
    'FirstOpenGL.exe' (Win32): Loaded 'C:\Windows\SysWOW64\oleaut32.dll'. Symbols loaded.
    'FirstOpenGL.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ole32.dll'. Symbols loaded.
    'FirstOpenGL.exe' (Win32): Loaded 'C:\Windows\SysWOW64\devobj.dll'. Symbols loaded.
    'FirstOpenGL.exe' (Win32): Loaded 'C:\Windows\SysWOW64\dwmapi.dll'. Symbols loaded.
    'FirstOpenGL.exe' (Win32): Loaded 'C:\Windows\SysWOW64\winmm.dll'. Symbols loaded.
    'FirstOpenGL.exe' (Win32): Loaded 'C:\Windows\SysWOW64\imm32.dll'. Symbols loaded.
    'FirstOpenGL.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msctf.dll'. Symbols loaded.
    'FirstOpenGL.exe' (Win32): Loaded 'C:\Windows\SysWOW64\nvinit.dll'. Cannot find or open the PDB file.
    'FirstOpenGL.exe' (Win32): Loaded 'C:\PROGRA~2\BROWSE~1\SPROTE~1.DLL'. Module was built without symbols.
    'FirstOpenGL.exe' (Win32): Unloaded 'C:\PROGRA~2\BROWSE~1\SPROTE~1.DLL'
    'FirstOpenGL.exe' (Win32): Loaded 'C:\Windows\SysWOW64\uxtheme.dll'. Symbols loaded.
    'FirstOpenGL.exe' (Win32): Loaded 'C:\Windows\SysWOW64\nvoglv32.dll'. Cannot find or open the PDB file.
    'FirstOpenGL.exe' (Win32): Loaded 'C:\Windows\SysWOW64\shell32.dll'. Symbols loaded.
    'FirstOpenGL.exe' (Win32): Loaded 'C:\Windows\SysWOW64\shlwapi.dll'. Symbols loaded.
    'FirstOpenGL.exe' (Win32): Loaded 'C:\Windows\SysWOW64\version.dll'. Symbols loaded.
    'FirstOpenGL.exe' (Win32): Loaded 'C:\Windows\SysWOW64\wintrust.dll'. Symbols loaded.
    'FirstOpenGL.exe' (Win32): Loaded 'C:\Windows\SysWOW64\crypt32.dll'. Symbols loaded.
    'FirstOpenGL.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msasn1.dll'. Symbols loaded.
    'FirstOpenGL.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntmarta.dll'. Symbols loaded.
    'FirstOpenGL.exe' (Win32): Loaded 'C:\Windows\SysWOW64\Wldap32.dll'. Symbols loaded.
    The thread 0x3314 has exited with code 0 (0x0).
    'FirstOpenGL.exe' (Win32): Loaded 'C:\Windows\SysWOW64\powrprof.dll'. Symbols loaded.
    The thread 0x29cc has exited with code 1 (0x1).
    The thread 0x2d3c has exited with code 0 (0x0).
    'FirstOpenGL.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\powrprof.dll'
    The thread 0x30bc has exited with code 1 (0x1).
    'FirstOpenGL.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ole32.dll'. Symbols loaded.
    'FirstOpenGL.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\ole32.dll'
    'FirstOpenGL.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ole32.dll'. Symbols loaded.
    'FirstOpenGL.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\ole32.dll'
    'FirstOpenGL.exe' (Win32): Loaded 'C:\Windows\SysWOW64\clbcatq.dll'. Symbols loaded.
    First-chance exception at 0x00000000 in FirstOpenGL.exe: 0xC0000005: Access violation executing location 0x00000000.
    Unhandled exception at 0x74C2C9F5 in FirstOpenGL.exe: 0xC0000005: Access violation executing location 0x00000000.
    The program '[13052] FirstOpenGL.exe' has exited with code 0 (0x0).
    //---------------------------------------------------------------------
    //
    // init
    //
    void
    init(void)
    {
    glGenVertexArrays(NumVAOs, VAOs);
    glBindVertexArray(VAOs[Triangles]);
    GLfloat vertices[NumVertices][2] = {
    { -0.90, -0.90 }, // Triangle 1
    { 0.85, -0.90 },
    { -0.90, 0.85 },
    { 0.90, -0.85 }, // Triangle 2
    { 0.90, 0.90 },
    { -0.85, 0.90 }
    };
    <--- I get a red dot here
    glGenBuffers(NumBuffers, Buffers);
    glBindBuffer(GL_ARRAY_BUFFER, Buffers[ArrayBuffer]);
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices),
    vertices, GL_STATIC_DRAW);
    ShaderInfo shaders[] = {
    { GL_VERTEX_SHADER, "triangles.vert" },
    { GL_FRAGMENT_SHADER, "triangles.frag" },
    { GL_NONE, NULL }
    };
    GLuint program = LoadShaders(shaders);
    glUseProgram(program);
    glVertexAttribPointer(vPosition, 2, GL_FLOAT,
    GL_FALSE, 0, BUFFER_OFFSET(0));
    glEnableVertexAttribArray(vPosition);
    }
    i went in to tools->options->Debugging->symbols and added microsoft symbols but im still getting this error. Im going to try to start a new empty project and try to go step by step, if anyone has a list of instruction or a link to help me set it up i would greatly appreciate it.
    thanks

  4. #4
    Newbie Newbie
    Join Date
    Jun 2013
    Posts
    3
    i did not get the book code to run but i did get openGL glew and freeglut to run a simular program, i might try an online tutorials since alot of people say its a better option for now.
    thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •