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

Thread: glCreateProgram - Access violation

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2012
    Posts
    11

    glCreateProgram - Access violation

    Hello again all,

    I've made a shader class that will handle all my compiling and error handling, but to my horror, the easiest part decided to stop me from finishing.

    I decided to make a struct called ShaderProgram that would contain my two shaders so I can just enable and disable each program to get a desired effect, though I feel this is a good idea, the problem is the glCreateProgram() method, throwing me a memory access violation.
    Glew reports My OpenGL version as 4.2.

    GLuint Prog = glCreateProgram();
    Will, in any class or function, throw the memory violation error.

    // This may actually be ignored, if not, feel free to scorn me about any bad code.
    My code as follows:

    Code :
     
    // My include block (Way at the top) (all headers are working and linked)
    #pragma once
    #include <gl\glew.h>
    #include <glm\glm.hpp>
    #include <stdio.h>
    #include <FlakPath.h> // Simple file-path class
    #include <map>
     
    using namespace std;
     
     
    struct ShaderProgram
    {
    	GLuint mProgram;
    	SHADER mVertex,mFragment;
     
    	void Shader_DualDebug()
    	{
    		cout << "\n*Vertex*\n";
    		mVertex.Print_Textual_State();
    		cout << "\n*Fragment*\n";
    		mFragment.Print_Textual_State();
    	}
             // **************************************
             // Error Occurs Here, inside the method 
             // **************************************
    	ShaderProgram(){mProgram = glCreateProgram();}
     
    	void Activate(string Vertex,string Fragment,bool _Compile = false, bool _Use = false)
    	{
    		mVertex.Set_Data(GL_VERTEX_SHADER,Vertex);
    		mFragment.Set_Data(GL_FRAGMENT_SHADER,Fragment);
     
    		if (_Compile)
    		{
    			mVertex.Compile();
    			mFragment.Compile();
    		}
     
    		if (_Use)
    		{
    			mVertex.Attach(mProgram);
    			mFragment.Attach(mProgram);
    		}
     
    	}
     
            // Error Occurs Here also, on the CreateProgram line (again, a memory error)
    	ShaderProgram(string Vertex,string Fragment,bool _Compile = false, bool _Use = false)
    	{
     
    		mProgram = glCreateProgram();
    		Activate(Vertex,Fragment,_Compile,_Use);
    	}
    };

    Any help would be much appreciated.

  2. #2
    Senior Member OpenGL Lord
    Join Date
    May 2009
    Posts
    6,066

    Re: glCreateProgram - Access violation

    Did you initialize OpenGL and load the function pointers?

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2012
    Posts
    11

    Re: glCreateProgram - Access violation

    SOLVED

    Code :
    GLint GlewInitResult = glewInit();
    	if (GLEW_OK != GlewInitResult) 
    	{
    		printf("ERROR: %s\n",glewGetErrorString(GlewInitResult));
    		exit(EXIT_FAILURE);
    	}

    I realized that I had put my glCreateProgram() before the above block, which finished the GL instillation.
    Thanks, was a simple placement error, as many things are.

Posting Permissions

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