PDA

View Full Version : glCreateProgram - Access violation



DanielSaucen
02-29-2012, 07:39 PM
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:




// 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.

Alfonse Reinheart
02-29-2012, 09:27 PM
Did you initialize OpenGL and load the function pointers?

DanielSaucen
03-01-2012, 12:56 PM
SOLVED



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.