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 6 of 6

Thread: Using OpenGL with VS 2010

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2012
    Posts
    13

    Unhappy Using OpenGL with VS 2010

    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    #include <GL/GL.h>
    #include <GL/GLU.h>
    #include <GL/glew.h>
    #include <GL/freeglut.h>
    #include <GL/glut.h>
    #include <GL/glxew.h>
    #include <GL/wglew.h>

    #define WINDOW_TITLE_PREFIX "Chapter 1"
    int CurrentWidth = 800,
    CurrentHeight = 600,
    WindowHandle = 0;
    void Initialize(int, char*[]);
    void InitWindow(int, char*[]);
    void ResizeFunction(int, int);
    void RenderFunction(void);

    int main(int argc, char* argv[])
    {
    Initialize(argc, argv);
    glutMainLoop();
    exit(EXIT_SUCCESS);
    }
    void Initialize(int argc, char* argv[])
    {
    InitWindow(argc, argv);
    fprintf(
    stdout,
    "INFO: OpenGL Version: %s\n",
    glGetString(GL_VERSION));
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    }
    void InitWindow(int argc, char* argv[])
    {
    glutInit(&argc, argv);
    glutInitContextVersion(4, 0);
    glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);
    glutInitContextProfile(GLUT_CORE_PROFILE);
    glutSetOption(
    GLUT_ACTION_ON_WINDOW_CLOSE,
    GLUT_ACTION_GLUTMAINLOOP_RETURNS
    );
    glutInitWindowSize(CurrentWidth, CurrentHeight);
    glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
    WindowHandle = glutCreateWindow(WINDOW_TITLE_PREFIX);
    if(WindowHandle < 1) {
    fprintf(
    stderr,
    "ERROR: Could not create a new rendering window.\n"
    );
    exit(EXIT_FAILURE);
    }
    glutReshapeFunc(ResizeFunction);
    glutDisplayFunc(RenderFunction);
    }
    void ResizeFunction(int Width, int Height)
    {
    CurrentWidth = Width;
    CurrentHeight = Height;
    glViewport(0, 0, CurrentWidth, CurrentHeight);
    }

    void RenderFunction(void)
    {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glutSwapBuffers();
    glutPostRedisplay();
    }




    Hi, I am using the code written below, but it gives me glGetString undefined error , glClearColor undefined error, glViewport undefined error, glClear undefined error... how to be? I've installed all required libraries... please help me

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,099
    Please put your code in '['code']' tags before expecting any help.

  3. #3
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,264
    Undefined means that it did not find the definition for glGetString and other GL functions. Try including glew.h before gl.h.
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,099
    V-man: You ruined my therapeutic approach.

    I bet the thread starter is simply forgetting to link to OpenGL32.lib

  5. #5
    Junior Member Newbie
    Join Date
    Jul 2012
    Posts
    13
    thank you so much... V-man

  6. #6
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,099
    I wonder why cl didn't error out in the first place since GLEW.h contains the following lines:

    Code :
    #if defined(__gl_h_) || defined(__GL_H__) || defined(__X_GL_H)
    #error gl.h included before glew.h
    #endif

    BTW, for your purposes glew.h and freeglut.h (and possibly GLU.h) are completely sufficient. GL.h, is never included after glew.h has been preprocessed because the include guard in GL.h will have the preprocessor ignore the contents of GL.h.

    freeglut.h include freeglut_std.h and freeglut_ext.h - glut.h include freeglut_std.h.

    Edit: Forgot glxew.h and wglew.h - these provide functions for the GL extensions to the X Window System and Windows. Since freeGLUT is already handling the stuff you can with these they are equally unnecessary in your case.
    Last edited by thokra; 07-04-2012 at 12:58 AM.

Tags for this Thread

Posting Permissions

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