Windows openg gl shading please help

I am using windows and trying to use programmable shaders. I am trying to use glext.h but when i am trying to compile i am getting. If anyone could tell me how to set up my program do shading.


1>------ Build started: Project: shader, Configuration: Debug Win32 ------
1>  main.cpp
1>c:\users\cytricks\documents\visual studio 2010\projects\shader\shader\main.cpp(139): error C3861: 'glCreateShader': identifier not found
1>c:\users\cytricks\documents\visual studio 2010\projects\shader\shader\main.cpp(140): error C3861: 'glShaderSource': identifier not found
1>c:\users\cytricks\documents\visual studio 2010\projects\shader\shader\main.cpp(142): error C3861: 'glCompileShader': identifier not found
1>c:\users\cytricks\documents\visual studio 2010\projects\shader\shader\main.cpp(143): error C3861: 'glGetShaderInfoLog': identifier not found
1>c:\users\cytricks\documents\visual studio 2010\projects\shader\shader\main.cpp(147): error C3861: 'glCreateShader': identifier not found
1>c:\users\cytricks\documents\visual studio 2010\projects\shader\shader\main.cpp(148): error C3861: 'glShaderSource': identifier not found
1>c:\users\cytricks\documents\visual studio 2010\projects\shader\shader\main.cpp(150): error C3861: 'glCompileShader': identifier not found
1>c:\users\cytricks\documents\visual studio 2010\projects\shader\shader\main.cpp(151): error C3861: 'glGetShaderInfoLog': identifier not found
1>c:\users\cytricks\documents\visual studio 2010\projects\shader\shader\main.cpp(154): error C3861: 'glCreateProgram': identifier not found
1>c:\users\cytricks\documents\visual studio 2010\projects\shader\shader\main.cpp(155): error C3861: 'glAttachShader': identifier not found
1>c:\users\cytricks\documents\visual studio 2010\projects\shader\shader\main.cpp(156): error C3861: 'glAttachShader': identifier not found
1>c:\users\cytricks\documents\visual studio 2010\projects\shader\shader\main.cpp(157): error C3861: 'glLinkProgram': identifier not found
1>c:\users\cytricks\documents\visual studio 2010\projects\shader\shader\main.cpp(158): error C3861: 'glGetProgramInfoLog': identifier not found
1>c:\users\cytricks\documents\visual studio 2010\projects\shader\shader\main.cpp(161): error C3861: 'glUseProgram': identifier not found
1>c:\users\cytricks\documents\visual studio 2010\projects\shader\shader\main.cpp(163): error C3861: 'glUniform1f': identifier not found
1>c:\users\cytricks\documents\visual studio 2010\projects\shader\shader\main.cpp(163): error C3861: 'glGetUniformLocation': identifier not found
1>c:\users\cytricks\documents\visual studio 2010\projects\shader\shader\main.cpp(164): error C3861: 'glUniform1f': identifier not found
1>c:\users\cytricks\documents\visual studio 2010\projects\shader\shader\main.cpp(164): error C3861: 'glGetUniformLocation': identifier not found
1>c:\users\cytricks\documents\visual studio 2010\projects\shader\shader\main.cpp(165): error C3861: 'glUniform1f': identifier not found
1>c:\users\cytricks\documents\visual studio 2010\projects\shader\shader\main.cpp(165): error C3861: 'glGetUniformLocation': identifier not found
1>c:\users\cytricks\documents\visual studio 2010\projects\shader\shader\main.cpp(166): error C3861: 'glUniform1f': identifier not found
1>c:\users\cytricks\documents\visual studio 2010\projects\shader\shader\main.cpp(166): error C3861: 'glGetUniformLocation': identifier not found
1>c:\users\cytricks\documents\visual studio 2010\projects\shader\shader\main.cpp(173): error C3861: 'glUniform1f': identifier not found
1>c:\users\cytricks\documents\visual studio 2010\projects\shader\shader\main.cpp(173): error C3861: 'glGetUniformLocation': identifier not found
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



#include <cmath>
#include <iostream>
#include <fstream>
#include <cstdlib>

using namespace std;

#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <Windows.h>
#include <GL/glut.h>
#include <GL/glext.h>
#endif




#define PI 3.14159265

GLfloat cam_height = 5.0, cam_angle = 0.0, time_step = 0.0;
GLuint prog;

char* readShaderSource(const char* shaderFile)
{
	ifstream fp(shaderFile);
	char* buf;
	long size;
	if (!fp.is_open()) {cerr << "KAPUT!
"; exit(1);}
	fp.seekg (0, ios::end);
	size = fp.tellg();
	fp.seekg (0, ios::beg);
	cout << "size " << size << endl;
	buf = new char[size+1];
	
	fp.read(buf, size);
	buf[size] = '\0'; //null termination
	fp.close();
	
	return buf;
}



void display(void)
{
	
	/* Displays all three modes, side by side */
	
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    gluLookAt(5*cos(cam_angle*PI/180), cam_height, 5*sin(cam_angle*PI/180), 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
	
	
    glutSolidTeapot(1.0);
	
    glutSwapBuffers();
}


void myReshape(int w, int h)
{
    glViewport(0, 0, w, h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    if (w <= h)
        glOrtho(-4.0, 4.0, -4.0 * (GLfloat) h / (GLfloat) w,
				4.0 * (GLfloat) h / (GLfloat) w, -10.0, 10.0);
    else
        glOrtho(-4.0 * (GLfloat) w / (GLfloat) h,
				4.0 * (GLfloat) w / (GLfloat) h, -4.0, 4.0, -10.0, 10.0);
    glMatrixMode(GL_MODELVIEW);
    display();
}

void mykeyboard(unsigned char key, int x, int y) {
	
	if (key == 'w' || key == 'W') {
		cam_height += 1;
	}
	if (key == 's' || key == 'S') {
		cam_height -= 1;
	}
	if (key == 'a' || key == 'A') {
		cam_angle += 5.0;
		if (cam_angle > 360.0) cam_angle -= 360.0;
	}
	if (key == 'd' || key == 'D') {
		cam_angle -= 5.0;
		if (cam_angle < -360.0) cam_angle += 360.0;
	}
	
	glutPostRedisplay();
}


void myinit()
{
    GLfloat mat_specular[]={1.0, 1.0, 1.0, 1.0};
    GLfloat mat_diffuse[]={1.0, 0.0, 1.0, 1.0};
    GLfloat mat_ambient[]={1.0, 1.0, 1.0, 1.0};
    GLfloat mat_shininess={100.0};
    GLfloat light_ambient[]={0.0, 0.0, 0.0, 1.0};
    GLfloat light_diffuse[]={1.0, 1.0, 1.0, 1.0};
    GLfloat light_specular[]={1.0, 1.0, 1.0, 1.0};
    GLfloat light_position[]={1.0, 2.0, 3.0, 1.0};
	
	
	/* set up ambient, diffuse, and specular components for light 0 */
	
    glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
    glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);
	
	/* define material properties for front face of all polygons */
	
    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
    glMaterialf(GL_FRONT, GL_SHININESS, mat_shininess);
	
    glShadeModel(GL_SMOOTH); /*enable smooth shading */
    glEnable(GL_LIGHTING); /* enable lighting */
    glEnable(GL_LIGHT0);  /* enable light 0 */
    glEnable(GL_DEPTH_TEST); /* enable z buffer */
	
    glClearColor (1.0, 1.0, 1.0, 1.0);
    glColor3f (0.0, 0.0, 0.0);
	
	
    GLchar log[500];
    int length;
    GLuint idV, idF;
	
    const GLchar * vSource = readShaderSource("phongV.vert");
    const GLchar * fSource = readShaderSource("simple.frag");
	
    idV = glCreateShader(GL_VERTEX_SHADER);
    glShaderSource(idV, 1, &vSource, NULL);
	
    glCompileShader(idV);
    glGetShaderInfoLog(idV, 500, &length, log);
    cout << "Status: " << log << endl;
	
	
    idF = glCreateShader(GL_FRAGMENT_SHADER);
    glShaderSource(idF, 1, &fSource, NULL);
	
    glCompileShader(idF);
    glGetShaderInfoLog(idF, 500, &length, log);
    cout << "Status: " << log << endl;
	
	prog = glCreateProgram();
	glAttachShader(prog, idV);
	glAttachShader(prog, idF);
	glLinkProgram(prog);
	glGetProgramInfoLog(prog, 500, &length, log);
    cout << "Status: " << log << endl;
	
	glUseProgram(prog);
	
	glUniform1f(glGetUniformLocation(prog, "time"), 0.0);
	glUniform1f(glGetUniformLocation(prog, "xs"), 1.0);
	glUniform1f(glGetUniformLocation(prog, "zs"), 1.5);
	glUniform1f(glGetUniformLocation(prog, "h"), 0.1);
	
	
}

void myidle() {
	time_step += 0.02;
	glUniform1f(glGetUniformLocation(prog, "time"), time_step);
	glutPostRedisplay();
}

int main(int argc, char **argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    glutInitWindowSize(500, 500);
    glutCreateWindow("shaders");
    myinit();
    glutReshapeFunc(myReshape);
    glutDisplayFunc(display);
    glutKeyboardFunc(mykeyboard);
    glutIdleFunc(myidle);
    glutMainLoop();
    return 0;
}


Add

#define GL_GLEXT_PROTOTYPES

before u include <GL/glext.h> header

This wont work on Windows.

OP, add this library http://glew.sourceforge.net/ to your program.
Alternatively you can manually obtain function pointers to functions you need using wglGetProcAddress.

how do you set them up. I places the headers in the right places, and the lib files as well but i am still having problems.

Is there a tutorial on how to use shaders on windows?

Just call glewInit() after creating your window and it should work.

This issue has nothing to do with shaders, its just general problem on Windows with OpenGL functions introduced after GL 1.1

To do manually what glew does for you, you need to:
<code>
PFNGLATTACHSHADERPROC glAttachShader;
//other function pointers declarations

void load_shader_functions() {
glAttachShader = (PFNGLATTACHSHADERPROC) wglGetProcAddress(“glAttachShader”);
//loading of other functions
}
</code>
and then call ‘load_shader_functions’ after you have a context (glut makes one for you together with a window).

Here you go
http://www.opengl.org/wiki/Getting_started

and
http://www.opengl.org/wiki/Getting_started#OpenGL_2.0.2B_and_extensions

I am getting linking errors now though

1>------ Build started: Project: shader, Configuration: Debug Win32 ------
1> main.cpp
1>main.obj : error LNK2001: unresolved external symbol __imp____glewUniform1f
1>main.obj : error LNK2001: unresolved external symbol __imp____glewGetUniformLocation
1>main.obj : error LNK2001: unresolved external symbol __imp____glewUseProgram
1>main.obj : error LNK2001: unresolved external symbol __imp____glewGetProgramInfoLog
1>main.obj : error LNK2001: unresolved external symbol __imp____glewLinkProgram
1>main.obj : error LNK2001: unresolved external symbol __imp____glewAttachShader
1>main.obj : error LNK2001: unresolved external symbol __imp____glewCreateProgram
1>main.obj : error LNK2001: unresolved external symbol __imp____glewGetShaderInfoLog
1>main.obj : error LNK2001: unresolved external symbol __imp____glewCompileShader
1>main.obj : error LNK2001: unresolved external symbol __imp____glewShaderSource
1>main.obj : error LNK2001: unresolved external symbol __imp____glewCreateShader
1>main.obj : error LNK2019: unresolved external symbol __imp__glewInit referenced in function _main
1>C:\Users\Cytricks\Documents\Visual Studio 2010\Projects\shader\Debug\shader.exe : fatal error LNK1120: 12 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

can i deleted stuff i dont need. I just want to get this to work.


#include <cmath>
#include <iostream>
#include <fstream>
#include <cstdlib>

using namespace std;

#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <Windows.h>
#include <GL/glew.h>
#include <GL/glut.h>
#include <GL/glext.h>
#include <GL/wglext.h>

#endif




#define PI 3.14159265

GLfloat cam_height = 5.0, cam_angle = 0.0, time_step = 0.0;
GLuint prog;

char* readShaderSource(const char* shaderFile)
{
	ifstream fp(shaderFile);
	char* buf;
	long size;
	if (!fp.is_open()) {cerr << "KAPUT!
"; exit(1);}
	fp.seekg (0, ios::end);
	size = fp.tellg();
	fp.seekg (0, ios::beg);
	cout << "size " << size << endl;
	buf = new char[size+1];
	
	fp.read(buf, size);
	buf[size] = '\0'; //null termination
	fp.close();
	
	return buf;
}



void display(void)
{
	
	/* Displays all three modes, side by side */
	
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    gluLookAt(5*cos(cam_angle*PI/180), cam_height, 5*sin(cam_angle*PI/180), 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
	
	
    glutSolidTeapot(1.0);
	
    glutSwapBuffers();
}


void myReshape(int w, int h)
{
    glViewport(0, 0, w, h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    if (w <= h)
        glOrtho(-4.0, 4.0, -4.0 * (GLfloat) h / (GLfloat) w,
				4.0 * (GLfloat) h / (GLfloat) w, -10.0, 10.0);
    else
        glOrtho(-4.0 * (GLfloat) w / (GLfloat) h,
				4.0 * (GLfloat) w / (GLfloat) h, -4.0, 4.0, -10.0, 10.0);
    glMatrixMode(GL_MODELVIEW);
    display();
}

void myinit()
{
   
    GLfloat light_ambient[]={0.0, 0.0, 0.0, 1.0};
    GLfloat light_diffuse[]={1.0, 1.0, 1.0, 1.0};
    GLfloat light_specular[]={1.0, 1.0, 1.0, 1.0};
    GLfloat light_position[]={1.0, 2.0, 3.0, 1.0};
	
	
	/* set up ambient, diffuse, and specular components for light 0 */
	
    glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
    glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);
	
	
	
    glShadeModel(GL_SMOOTH); /*enable smooth shading */
    glEnable(GL_LIGHTING); /* enable lighting */
    glEnable(GL_LIGHT0);  /* enable light 0 */
    glEnable(GL_DEPTH_TEST); /* enable z buffer */
	
    glClearColor (1.0, 1.0, 1.0, 1.0);
    glColor3f (0.0, 0.0, 0.0);
	
	
    GLchar log[500];
    int length;
    GLuint idV, idF;
	
    const GLchar * vSource = readShaderSource("phongV.vert");
    const GLchar * fSource = readShaderSource("simple.frag");
	
    idV = glCreateShader(GL_VERTEX_SHADER);
    glShaderSource(idV, 1, &vSource, NULL);
	
    glCompileShader(idV);
    glGetShaderInfoLog(idV, 500, &length, log);
    cout << "Status: " << log << endl;
	
	
    idF = glCreateShader(GL_FRAGMENT_SHADER);
    glShaderSource(idF, 1, &fSource, NULL);
	
    glCompileShader(idF);
    glGetShaderInfoLog(idF, 500, &length, log);
    cout << "Status: " << log << endl;
	
	prog = glCreateProgram();
	glAttachShader(prog, idV);
	glAttachShader(prog, idF);
	glLinkProgram(prog);
	glGetProgramInfoLog(prog, 500, &length, log);
    cout << "Status: " << log << endl;
	
	glUseProgram(prog);
	
	glUniform1f(glGetUniformLocation(prog, "time"), 0.0);
	glUniform1f(glGetUniformLocation(prog, "xs"), 1.0);
	glUniform1f(glGetUniformLocation(prog, "zs"), 1.5);
	glUniform1f(glGetUniformLocation(prog, "h"), 0.1);
	
	
}


int main(int argc, char **argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    glutInitWindowSize(500, 500);
	
	GLenum err=glewInit();

	
    glutCreateWindow("shaders");

    myinit();
    glutReshapeFunc(myReshape);
    glutDisplayFunc(display);
   
    glutMainLoop();
    return 0;
}


I am getting linking errors now though

Did you actually link to the GLEW static library?

thx but i am getting an exception…

idV = glCreateShader(GL_VERTEX_SHADER);

it doesn’t like this for some reason

Did you initialize GLEW, like the documentation says to do?

what is the exception?

One thing I just saw u should call glewInit after the glutCreateWindow call.

I was able to load the funtions with

glCreateProgram = (PFNGLCREATEPROGRAMPROC) wglGetProcAddress("glCreateProgram");
glAttachShader  = (PFNGLATTACHSHADERPROC)  wglGetProcAddress("glAttachShader");
glLinkProgram   = (PFNGLLINKPROGRAMPROC)   wglGetProcAddress("glLinkProgram");
glUseProgram    = (PFNGLUSEPROGRAMPROC)    wglGetProcAddress("glUseProgram");
glCreateShader	= (PFNGLCREATESHADERPROC)  wglGetProcAddress("glCreateShader");
glShaderSource  = (PFNGLSHADERSOURCEPROC)  wglGetProcAddress("glShaderSource");
glCompileShader = (PFNGLCOMPILESHADERPROC) wglGetProcAddress("glCompileShader");

but it doesnt work with
glUniform1f = (PFNGLUNIFORM1FPROC) wglGetProcAddress(“glUniform1f”);

can anyone tell what what to do for this one?

thx mobeen…had it in right before :stuck_out_tongue:

it works now!!

thanks

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.