Results 1 to 7 of 7

Thread: Setting Up opengl

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2011
    Posts
    4

    Setting Up opengl

    I am having an unusual problem with setting opengl and visual C++ 2010. I have download bothe gltools and freeglut 2.6 and I have added the header files to my project properties under the c++ -> general -> additional include libraries and library files under linker -> input -> additonal dependencies.

    I've made the following calls to the headers in my cpp file as follows:

    #include <stdio.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

    (I am following an example in the book OPengl superbible 5th edition)

    This is boderline frustrating at his point because the project will not build, refusing to identify some of the functions. I will paste the code below

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


    Also here are the errors i am receiving

    1>c:\users\****\documents\visual studio 2010\triangle.cpp(53): error C2065: '“Triangle”' : undeclared identifier
    1>c:\users\****\documents\visual studio 2010\triangle.cpp(5: error C2065: '“GLEW' : undeclared identifier
    1>c:\users\****\documents\visual studio 2010\triangle.cpp(5: error C2146: syntax error : missing ')' before identifier 'Error'
    1>c:\users\****\documents\visual studio 2010\triangle.cpp(5: error C2017: illegal escape sequence
    1>c:\users\****\documents\visual studio 2010\triangle.cpp(5: error C2059: syntax error : ')'



    Any help would be greatly appreciated. Thanks.

  2. #2
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,674

    Re: Setting Up opengl

    Also here are the errors i am receiving
    You didn't post the file that these errors are happening in. It looks like you forget a #include in that file.

    Also, use code tags to wrap the source code you post with.

  3. #3
    Junior Member Newbie
    Join Date
    Apr 2011
    Posts
    2

    Re: Setting Up opengl

    Hey guys I'm new to OpenGL still making the odd and ends and making this stuff work...
    To help on your problem I ran your source code on Visual 2008 since 2010 is to different to work but I found that the line in your code
    fprintf(stderr, “GLEW Error: %s\n”, glewGetErrorString(err));

    the “GLEW Error: %s\n” does not have the correct "" around them I wasn't sure if it was just a text conversion when you pasted it. So I then removed the "" on GLEW Error: %s\n and still received exact same errors

    For the '“Triangle”' : undeclared identifier

    I found that on the line
    glutCreateWindow(“Triangle”);

    On the “Triangle” the "" were also wrong

    After them Two line changes in your code your stuff worked

  4. #4
    Junior Member Newbie
    Join Date
    Apr 2011
    Posts
    4

    Re: Setting Up opengl

    Thank you for the responses.

    Wolfdog, i actually figured that out shortly after i posted this but my code still will not run, I not sure if i fixed the problem because when i forced the program to run with the build errors from before i am pretty sure that i got the follwing errors as well.

    Here is error

    Error:

    Unhandled exception at 0x00000000 in Triangle.exe: 0xC0000005: Access violation.

    Break Point:
    <code>
    GLfloat vVerts[] = { -0.5f, 0.0f, 0.0f,
    0.5f, 0.0f, 0.0f,
    0.0f, 0.5f, 0.0f };
    </code>

  5. #5
    Junior Member Newbie
    Join Date
    Apr 2011
    Posts
    2

    Re: Setting Up opengl

    Can you repost your current source code because I was able to run your source code from the first post to display a red triangle with blue background.

  6. #6
    Junior Member Newbie
    Join Date
    Apr 2011
    Posts
    4

    Re: Setting Up opengl

    <code>

    #include <stdio.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 the 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, "Fatal Error in foo(): value of bar is %p\n", glewGetErrorString(err));
    return 1;
    }
    SetupRC();
    glutMainLoop();
    return 0;
    }

    </code>

  7. #7
    Junior Member Newbie
    Join Date
    Apr 2011
    Posts
    4

    Re: Setting Up opengl

    I'm wondering if it's a graphics card issue.

    I using eee pc 1005 ha, with Mobile Intel 945 Express Chipset graphics.

    I've checked an it does say that it supports opengl but maybe i have an incompatible opengl version?

    I am having a hard time believing that this might really be the issue though.

Similar Threads

  1. Setting up OpenGL in VC++
    By oliver_kenny in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 03-23-2015, 10:42 PM
  2. Setting up Opengl
    By in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 07-14-2004, 09:29 AM
  3. Setting up OpenGl under VC7
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 02-22-2004, 11:38 AM
  4. Setting up OpenGL
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 10-23-2002, 05:23 PM
  5. help setting up openGL!!
    By in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 02-28-2002, 02:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean