Big problem to load a shader(resolved)

Hi,
the program crashes on this line (by saying : the application has encountered a problem and have to close):

vsh = glCreateShader(GL_VERTEX_SHADER);

vsh is declared as a global variable
i have a radeon 9600 SE with 5.5 catalyst
this is my code :

  class loadShader
{
	private :
		long int fileLength ;
		char *content  ;

	public :
		loadShader(char *fileName1, char *fileName2) ;
		void loadStrings(char *fileName) ;
};

loadShader::loadShader(char *fileName1, char *fileName2)
{
	
	vsh = glCreateShader(GL_VERTEX_SHADER);
	fsh = glCreateShader(GL_FRAGMENT_SHADER);
	
	loadStrings(fileName1) ;
	const char *cContent = content ;
	glShaderSource(vsh, 1, &cContent, NULL);
	free((void*)content);


	loadStrings(fileName2) ;
	const char *cContent2 = content ;
	glShaderSource(fsh, 1, &cContent2, NULL);
	free((void*)content);

	glCompileShader(vsh);
	glCompileShader(fsh);

	unsigned short int ph = glCreateProgram();//program handler
	glAttachShader(ph, vsh);
	glAttachShader(ph, fsh);

	glLinkProgram(ph);
	glUseProgram(ph);
}

void loadShader::loadStrings(char *fileName)
{
	
	ifstream file ;
	file.open(fileName);
  
	file.seekg(0, ios::end);

	fileLength = file.tellg();
	content = (char *)malloc(sizeof(char) * (fileLength+1));
    
    file.seekg(0, ios::beg);
    file.read(content, fileLength);
	
	content[fileLength] = '\0' ;

    file.close();
}  

this is the main function :

 int main(int argc, char *argv[])
{
	myLoader= new loader3ds() ;
	
	glutInit (&argc, argv) ;
	glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH) ;
	glutInitWindowSize (640, 480) ;
	glutInitWindowPosition (250,250) ;
	glutCreateWindow (argv [0]) ;
	glEnable( GL_DEPTH_TEST );
	glClearColor(0, 0, 1, 0);

	myLoader->loadTextures() ;
	myLoader->lighting() ;

	glutReshapeFunc (reshape) ;
	glutKeyboardFunc (keyboard) ;
	glutDisplayFunc (display) ;
	
	loadShader *myShaderLoader = new loadShader("vertexShader.txt", "fragmentShader.txt");

	glutMainLoop () ;
	return 0 ;
} 

You didn’t setup the extensions.
Use a Extension Loading Library like GLEW http://glew.sourceforge.net/

i’m under visual c++ 6, i have ever put the lines :
#include <glew.h>
#pragma comment( lib, “glew32.lib”)

and added the .h, .lib and .dll in the include, lib and system32 directories
but it doen’t work :frowning:

have i forgotten to do something ? or is this a conflict about headers ? i have put these ones :
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <fstream.h>
#include <math.h>
#include <string.h>
#include <glew.h>
#include <glut.h>
//#include <gl.h>
#include <glext.h>
#include <SDL_image.h>

i forgot a call to glewInit();
it works now

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