Results 1 to 3 of 3

Thread: OpenGL shading problem

  1. #1
    Senior Member Regular Contributor
    Join Date
    Jun 2010
    Posts
    162

    OpenGL shading problem

    Hello every body,
    I have installed GLEW from source forge and trying to compile a GLSL porgram on Microsoft Visual Studio 10.0. But i am getting the following errors:
    /************************************************** ****/
    Generating Code...
    1>ogl.obj : error LNK2001: unresolved external symbol __imp____glewUseProgram
    1>ogl.obj : error LNK2001: unresolved external symbol __imp____glewLinkProgram
    1>ogl.obj : error LNK2001: unresolved external symbol __imp____glewAttachShader
    1>ogl.obj : error LNK2001: unresolved external symbol __imp____glewCreateProgram
    1>ogl.obj : error LNK2001: unresolved external symbol __imp____glewCompileShader
    1>ogl.obj : error LNK2001: unresolved external symbol __imp____glewShaderSource
    1>ogl.obj : error LNK2001: unresolved external symbol __imp____glewCreateShader
    1>ogl.obj : error LNK2019: unresolved external symbol __imp__glewIsSupported@4 referenced in function _main
    1>ogl.obj : error LNK2019: unresolved external symbol __imp__glewInit@0 referenced in function _main
    1>C:\Users\MYG741\Documents\Visual Studio 2010\Projects\Shader\Debug\Shader.exe : fatal error LNK1120: 9 unresolved externals
    1>
    1>Build FAILED.
    1>
    1>Time Elapsed 00:00:00.84
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    /************************************************** ***/
    Here is my code downloaded from lighthouse3D website:

    Code :
    #include <windows.h>
    #include <stdio.h>
    #include <stdlib.h>
     
    #include <GL/glew.h>
    #include <GL/glut.h>
    #include "textfile.h"
     
     
    GLuint v,f,f2,p;
    float lpos[4] = {1,0.5,1,0};
     
    void changeSize(int w, int h) {
     
        // Prevent a divide by zero, when window is too short
        // (you cant make a window of zero width).
        if(h == 0)
            h = 1;
     
        float ratio = 1.0* w / h;
     
        // Reset the coordinate system before modifying
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
     
        // Set the viewport to be the entire window
        glViewport(0, 0, w, h);
     
        // Set the correct perspective.
        gluPerspective(45,ratio,1,1000);
        glMatrixMode(GL_MODELVIEW);
     
     
    }
     
     
    void renderScene(void) {
     
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
        glLoadIdentity();
        gluLookAt(0.0,0.0,5.0, 
                  0.0,0.0,-1.0,
                  0.0f,1.0f,0.0f);
     
        glLightfv(GL_LIGHT0, GL_POSITION, lpos);
        glutSolidTeapot(1);
     
        glutSwapBuffers();
    }
     
    void processNormalKeys(unsigned char key, int x, int y) {
     
        if (key == 27) 
            exit(0);
    }
     
     
    void setShaders() {
     
        char *vs = NULL,*fs = NULL,*fs2 = NULL;
     
        v = glCreateShader(GL_VERTEX_SHADER);
        f = glCreateShader(GL_FRAGMENT_SHADER);
        f2 = glCreateShader(GL_FRAGMENT_SHADER);
     
     
        vs = textFileRead("toon.vert");
        fs = textFileRead("toon.frag");
        fs2 = textFileRead("toon2.frag");
     
        const char * ff = fs;
        const char * ff2 = fs2;
        const char * vv = vs;
     
        glShaderSource(v, 1, &vv,NULL);
        glShaderSource(f, 1, &ff,NULL);
        glShaderSource(f2, 1, &ff2,NULL);
     
        free(vs);free(fs);
     
        glCompileShader(v);
        glCompileShader(f);
        glCompileShader(f2);
     
        p = glCreateProgram();
        glAttachShader(p,f);
        glAttachShader(p,f2);
        glAttachShader(p,v);
     
        glLinkProgram(p);
        glUseProgram(p);
    }
     
     
    int main(int argc, char **argv) {
        glutInit(&argc, argv);
        glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
        glutInitWindowPosition(100,100);
        glutInitWindowSize(320,320);
        glutCreateWindow("MM 2004-05");
     
        glutDisplayFunc(renderScene);
        glutIdleFunc(renderScene);
        glutReshapeFunc(changeSize);
        glutKeyboardFunc(processNormalKeys);
     
        glEnable(GL_DEPTH_TEST);
        glClearColor(1.0,1.0,1.0,1.0);
    //    glEnable(GL_CULL_FACE);
     
        glewInit();
        if (glewIsSupported("GL_VERSION_2_0"))
            printf("Ready for OpenGL 2.0\n");
        else {
            printf("OpenGL 2.0 not supported\n");
            exit(1);
        }
        setShaders();
     
        glutMainLoop();
     
        // just for compatibiliy purposes
        return 0;
    }

    Could anyone help me identify the problem?

    I put glew.h file and lib and dll in the proper directories. Why still I am getting problem? Please help me out.

  2. #2
    Newbie Frequent Contributor
    Join Date
    Mar 2016
    Posts
    896
    I put glew.h file and lib and dll in the proper directories.
    That is necessary but not sufficient to make this work, you also need to link with the .lib file. Under Project Settings there is a linker page where you set the libraries to link with.
    As an aside, the .h and .lib files are only needed during the compile and link steps respectively, while the .dll is only needed at runtime.

  3. #3
    Senior Member Regular Contributor
    Join Date
    Jun 2010
    Posts
    162
    Actually I found directly copied binaries from sourceforge site does not work. I compiled and built glew and then used the generated binaries. It works now.

Similar Threads

  1. OpenGL Shading Problem
    By winEr in forum OpenGL: GLSL
    Replies: 7
    Last Post: 02-23-2011, 06:40 AM
  2. Shading problem? (pyglet-problem?, my problem?)
    By H2OBrain in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 12-03-2009, 08:31 AM
  3. Problem with GL_FLAT shading
    By cesarsalad in forum OpenGL: Basic Coding
    Replies: 26
    Last Post: 11-08-2004, 03:37 PM
  4. Shading problem
    By openqc in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 03-16-2004, 08:49 PM
  5. Shading problem
    By jbrehm in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 04-30-2003, 07:45 AM

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