PDA

View Full Version : problem by loading a shader, HELP not resolved



airseb
06-01-2005, 01:49 PM
Hi,
My program compile but at the execution it crashes : "the application have to close..."
I don't find the error, can you help me ?
this is my code :

class loadShader
{
private :
int stringslen[SLEN] ;
int nbString ;
const char *strings[SLEN] ;

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

loadShader::loadShader(char *fileName1, char *fileName2)
{
unsigned int vsh, fsh ; //vertex shader handler, vertex shader handler

vsh = glCreateShader(GL_VERTEX_SHADER);
fsh = glCreateShader(GL_FRAGMENT_SHADER);

loadStrings(fileName) ;
glShaderSource(vsh, nbString, strings, stringslen);
strings[0]='\0' ;

loadStrings(fileName2) ;
glShaderSource(fsh, nbString, strings, stringslen);

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)
{
FILE *f ;
f=fopen(fileName, "r") ;
nbString=0;
while(feof(f) !=0 )
{
stringslen[nbString]=fscanf(f, "%s", &strings[nbString]);
nbString++ ;
}
}

ZbuffeR
06-01-2005, 02:30 PM
use a debugger. What IDE/compiler are you using ?

airseb
06-01-2005, 02:32 PM
i use visual c++ 6

airseb
06-02-2005, 06:28 AM
it seems that it crash at this line :

vsh = glCreateShader(GL_VERTEX_SHADER);

where vsh is an unsigned int.
i don't understand why...

airseb
06-02-2005, 07:50 AM
this is my new 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)
{
fileLength=0 ;
content=NULL ;
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();
}

carl_lewis
06-02-2005, 07:55 AM
does the code update mean you solved the problem...?


i don't see any declaration of vsh in the new one

airseb
06-02-2005, 07:58 AM
Originally posted by carl_lewis:
does the code update mean you solved the problem...?


i don't see any declaration of vsh in the new onein fact it's the new code with some help, vsh is declared as a global variable

stanlylee
06-05-2005, 06:00 AM
check if your driver supported glCreateShader call (GL_Shading_Language_100)