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

Thread: problem by loading a shader, HELP not resolved

  1. #1
    Member Regular Contributor
    Join Date
    Mar 2002
    Location
    France
    Posts
    286

    problem by loading a shader, HELP not resolved

    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 :
    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++ ;
    	}
    }

  2. #2
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,575

    Re: problem by loading a shader, HELP not resolved

    use a debugger. What IDE/compiler are you using ?

  3. #3
    Member Regular Contributor
    Join Date
    Mar 2002
    Location
    France
    Posts
    286

    Re: problem by loading a shader, HELP not resolved

    i use visual c++ 6

  4. #4
    Member Regular Contributor
    Join Date
    Mar 2002
    Location
    France
    Posts
    286

    Re: problem by loading a shader, HELP not resolved

    it seems that it crash at this line :

    vsh = glCreateShader(GL_VERTEX_SHADER);

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

  5. #5
    Member Regular Contributor
    Join Date
    Mar 2002
    Location
    France
    Posts
    286

    Re: problem by loading a shader, HELP not resolved

    this is my new code :
    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();
    }

  6. #6
    Intern Newbie
    Join Date
    Feb 2005
    Location
    burton-on-trent [england]
    Posts
    34

    Re: problem by loading a shader, HELP not resolved

    does the code update mean you solved the problem...?


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

  7. #7
    Member Regular Contributor
    Join Date
    Mar 2002
    Location
    France
    Posts
    286

    Re: problem by loading a shader, HELP not resolved

    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 one
    in fact it's the new code with some help, vsh is declared as a global variable

  8. #8
    Intern Newbie
    Join Date
    Nov 2004
    Location
    beijing
    Posts
    49

    Re: problem by loading a shader, HELP not resolved

    check if your driver supported glCreateShader call (GL_Shading_Language_100)
    /****************\
    No games NO dreams
    For games ,for dreams
    .....
    every night ,
    I dreams a sex girl .
    but only dream....
    \****************/

Posting Permissions

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