c++ - Confused about behaviour of shaders in OpenGL - switching declarations creates errors and crashes -
i'm creating functions load shaders, create meshes, , like, started simple programme test functionalities adding, 1 one, , found problem bit:
const char* vertexshader = prm.loadshader ( "simple_vs.glsl" ).c_str (); const char* fragmentshader = prm.loadshader ( "simple_fs.glsl" ).c_str (); gluint vs = glcreateshader ( gl_vertex_shader ); glshadersource ( vs, 1, &vertexshader, null ); glcompileshader ( vs ); gluint fs = glcreateshader ( gl_fragment_shader ); glshadersource ( fs, 1, &fragmentshader, null ); glcompileshader ( fs );
if tried compile it, no errors, there black screen. if removed fragment shader, display triangle, meant to, without colors. if switched 2 declarations, in:
const char* fragmentshader = prm.loadshader ( "simple_fs.glsl" ).c_str (); const char* vertexshader = prm.loadshader ( "simple_vs.glsl" ).c_str ();
i error, , programme crash:
error code #3: shader info shader 1: warning: 0:1: '#version' : version number deprecated in ogl 3.0 forwards compatible context driver error: 0:1: '#extension' : 'gl_arb_separate_shader_objects' not supported
however, if set this:
const char* vertexshader = prm.loadshader ( "simple_vs.glsl" ).c_str (); gluint vs = glcreateshader ( gl_vertex_shader ); glshadersource ( vs, 1, &vertexshader, null ); glcompileshader ( vs ); const char* fragmentshader = prm.loadshader ( "simple_fs.glsl" ).c_str (); gluint fs = glcreateshader ( gl_fragment_shader ); glshadersource ( fs, 1, &fragmentshader, null ); glcompileshader ( fs );
it works fine. clueless why case, ran original code no issues in prior versions of program. checked prm.loadshader function, works fine, , returns expected value. none of changes have made programme deal shaders, confused bizzarely particular behaviour. can more experience explain why happening?
presumably prm.loadshader
returns std::string
value. calling c_str
gives internal character storage of std::string
, lives long std::string
does. end of each of loadshader
lines, std::string
returned destroyed because temporary object, , pointers you've stored no longer pointing @ valid character arrays.
you can around storing local re-create of returned strings.
std::string vertexshader = prm.loadshader ( "simple_vs.glsl" ); const char* cvertexshader = vertexshader.c_str(); std::string fragmentshader = prm.loadshader ( "simple_fs.glsl" ); const char* cfragmentshader = vertexshader.c_str(); gluint vs = glcreateshader ( gl_vertex_shader ); glshadersource ( vs, 1, &cvertexshader, null ); glcompileshader ( vs ); gluint fs = glcreateshader ( gl_fragment_shader ); glshadersource ( fs, 1, &cfragmentshader, null ); glcompileshader ( fs );
c++ opengl input shader glfw
No comments:
Post a Comment