• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Hector San Roman Lanza

Error 1282 glUseProgram, very strange...

7 posts in this topic

Hi!
I have the next code, where I get an error and the program close:

main
[CODE]
[...]
glUseProgram(shader->ID);
ExitOnGLError("ERROR: Could use the shader");
[...]
[/CODE]

util.cpp

[CODE]void ExitOnGLError(const char* error_message)
{
const GLenum ErrorValue = glGetError();
cout<<ErrorValue<<endl; //output '1282'
if(ErrorValue != GL_NO_ERROR)
{
cout<<"hola "<<ErrorValue<<endl;
const char* APPEND_DETAIL_STRING = ": %s\n";
// strlen: retorna un numero de caracteres
const size_t APPEND_LENGTH = strlen(APPEND_DETAIL_STRING) + 1;
const size_t message_length = strlen(error_message);
char* display_message = (char*)malloc(message_length + APPEND_LENGTH);
memcpy(display_message, error_message, message_length);
memcpy(&display_message[message_length], APPEND_DETAIL_STRING, APPEND_LENGTH);
fprintf(stderr, display_message, gluErrorString(ErrorValue));
free(display_message);
exit(EXIT_FAILURE);
}
}[/CODE]

But if I use this code, I don´t get any error and the program works!

main

[CODE]
glUseProgram(shader->ID);
const GLenum ErrorValue = glGetError();
cout<<ErrorValue<<endl; // output '0'
ExitOnGLError("ERROR: Could use the shader"); // Any error here and the program continue..
[/CODE]

Does anyone know why this is happening?
0

Share this post


Link to post
Share on other sites
The reason the latter works is that glGetError() is called twice, and as the first one is called without resulting in an error, glGetError() returns 0 inside the ExitOnGLError() function.

IIRC, 1282 Means invalid value. - Are you sure that shader->ID was created from a glLinkProgram() successfully prior to that?
0

Share this post


Link to post
Share on other sites
[quote name='SuperVGA' timestamp='1350199944' post='4989993']
The reason the latter works is that glGetError() is called twice, and as the first one is called without resulting in an error, glGetError() returns 0 inside the ExitOnGLError() function.

IIRC, 1282 Means invalid value. - Are you sure that shader->ID was created from a glLinkProgram() successfully prior to that?
[/quote]

I think that the program was linked successfully.

[CODE]
void CheckLink(GLuint id)
{
//CheckAndLog(id,GL_LINK_STATUS,"conexion");
GLint compiled = 0;
GLint length = 0;
glGetProgramiv(id, GL_LINK_STATUS, &compiled);
if(compiled == 0)
{
std::cerr<<"ERROR: linking fail"<<std::endl;
glGetProgramiv(id, GL_INFO_LOG_LENGTH, &length);
if(length > 1) {
std::string log(length, '\0');
glGetProgramInfoLog(id, length, &length, &log[0]);
std::cerr<<log<<std::endl;
exit(1);
}
}else
{
std::cout<<"linkage was successfully"<<std::endl;
}
[/CODE]

This code don´t give me any error
0

Share this post


Link to post
Share on other sites
Show more code, preferably a minimum complete program. There is likely more to this problem that what you have shown. For example, if you're only checking the error state after glUseProgram, then the error could be at any point before that because error bits are never reset by functions other that glGetError so the error can come from earlier functions within your program.
1

Share this post


Link to post
Share on other sites
engine.cpp


[CODE]
void Engine::CreateMesh(void)
{
mesh = content.Load<Mesh>("Models/cube2.obj");

shader = content.Load<Shader>("Shaders/simpleshader.glsl");

ModelMatrixUniformLocation = shader->GetUniformLocation("ModelMatrix");
ViewMatrixUniformLocation = shader->GetUniformLocation("ViewMatrix");
ProjectionMatrixUniformLocation = shader->GetUniformLocation("ProjectionMatrix");
ExitOnGLError("ERROR: Could not get the uniform locations");

Texture* texture0 = content.Load<Texture>("Textures/cube.bmp");
Tex0Loc = shader->GetUniformLocation("texture0");
ExitOnGLError("Error: Could not load texture");
}

void Engine::DrawMesh(void)
{

glUseProgram(shader->ID);
ExitOnGLError("ERROR: Could not use the shader"); // Error 1282

glUniformMatrix4fv(ModelMatrixUniformLocation, 1, GL_FALSE, value_ptr(ModelMatrix));
ExitOnGLError("ERROR: Could not set the model matrix");

ViewMatrix = lookAt(
vec3(0.0, 2.0, 4.0), //eye
vec3(0.0 ,0.0 , 0.0), //direction
vec3(0.0, 1.0, 0.0) //up
);
glUniformMatrix4fv(ViewMatrixUniformLocation, 1, GL_FALSE, value_ptr(ViewMatrix));
ExitOnGLError("ERROR: Could not set the view matrix");

ProjectionMatrix = perspective(45.0f, (float) CurrentWidth / CurrentHeight , 0.1f, 100.0f);
glUniformMatrix4fv(ProjectionMatrixUniformLocation, 1, GL_FALSE, value_ptr(ProjectionMatrix));
ExitOnGLError("ERROR: Could not set the projection matrix");
glUniform1i(Tex0Loc, 0);
mesh->Draw();
glUseProgram(0);
}
[/CODE]

Shader.cpp

[CODE]
void Shader::Load(const char* filename)
{
ifstream in(filename, ios::binary);
if(!in)
{
cerr << "Could not open the file" << filename << endl; // Lanzamos un mensaje de error
exit(1); // exit(1) usado para abortar el programa
}
//Leemos los datos
std::string glsl_source((std::istreambuf_iterator<char>(in)),
std::istreambuf_iterator<char>());
// Terminamos de leer el documento
in.close();
//miramos si hay algo
if(glsl_source.length() == 0)
{
cerr<<"ERROR: Any data in the file"<<endl;
exit(1);
}
std::string fs_shader = "#version 330\n #define COMPILING_FS\n" + glsl_source;
std::string vs_shader = "#version 330\n #define COMPILING_VS\n" + glsl_source;
// Creamos el programa
ID = glCreateProgram();
fragmentShaderID = CreateShader(fs_shader,GL_FRAGMENT_SHADER);
vertexShaderID = CreateShader(vs_shader,GL_VERTEX_SHADER);
Initialize();
}

GLuint Shader::CreateShader(std::string shader, GLenum type_shader)
{
GLuint shader_id = 0;
const char* glsl_cstr;
shader_id = glCreateShader(type_shader);
glShaderSource(shader_id, 1, &(glsl_cstr=shader.c_str()),NULL);
glCompileShader(shader_id);
ExitOnGLError("Could not compile the shader");
CheckCompile(shader_id);
return shader_id;
}

void Shader::Initialize(void)
{
glAttachShader(ID, fragmentShaderID);
ExitOnGLError("No se puede vincular el Fragment Shader");
glAttachShader(ID, vertexShaderID);
ExitOnGLError("No se puede vincular el Vertex Shader");
glLinkProgram(ID);
ExitOnGLError("No se puede conectar al programa");
CheckLink(ID);
}

GLint Shader::GetUniformLocation(const char* param)
{
return glGetUniformLocation(ID, param);
}

void CheckCompile(GLuint id)
{
GLint compiled = 0;
GLint length = 0;
glGetShaderiv(id, GL_COMPILE_STATUS, &compiled);
if(compiled == 0)
{
std::cerr<<"ERROR: The shader´s compilation fail"<<std::endl;
glGetShaderiv(id, GL_INFO_LOG_LENGTH, &length);
if(length > 1) {
std::string log(length, '\0');
glGetShaderInfoLog(id, length, &length, &log[0]);
std::cerr<<log<<std::endl;
exit(1);
}
}else
{
std::cout<<"The shader´s compilation was successfully"<<std::endl;
}
}

void CheckLink(GLuint id)
{
//CheckAndLog(id,GL_LINK_STATUS,"conexion");
GLint compiled = 0;
GLint length = 0;
glGetProgramiv(id, GL_LINK_STATUS, &compiled);
if(compiled == 0)
{
std::cerr<<"ERROR: The linking fail"<<std::endl;
glGetProgramiv(id, GL_INFO_LOG_LENGTH, &length);
if(length > 1) {
std::string log(length, '\0');
glGetProgramInfoLog(id, length, &length, &log[0]);
std::cerr<<log<<std::endl;
exit(1);
}
}else
{
std::cout<<"The linking was successfully"<<std::endl;
}
}
[/CODE] Edited by ShotoReaper
0

Share this post


Link to post
Share on other sites
In Engine::CreateMesh you're creating the shader and returning it by value. This means the shader object has to be copied from the function [i]content.Load<Shader>()[/i] to the object [i]shader[/i]. If you have not written a proper constructors, an assignment operator and a destructor to treat the object as a value, you cannot use the shader object as if it was a value either but that is what you're currently doing.

Look up the Rule of Three; here's a [url="http://www.drdobbs.com/c-made-easier-the-rule-of-three/184401400"]clicky[/url] for an example.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0