SHARE
TWEET

segfault

a guest Dec 9th, 2019 109 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Singleton: OpenGL
  2. class OpenGL
  3. {
  4. public:
  5.     static OpenGL& get_instance();
  6.     OpenGL(OpenGL const&)= delete;
  7.     void operator=(OpenGL const&) = delete;
  8.  
  9.     void init(void);
  10.  
  11.     //methods
  12.     enum class ProjectionMode {PROJECTION_MODE_UNSET, PROJECTION_MODE_2D};
  13.     // GLenum get_gl_primitive(PrimitiveType type);
  14.     // GLenum get_gl_buffer(BufferType type);
  15.     // void draw_indexed_command(DrawCommandIndexed cmd);
  16.     // void draw_draw_command(DrawCommand cmd);
  17.     void set_projection_mode(ProjectionMode mode);
  18.     //void update_projection_data(float new_window_width, float new_window_height);
  19.     std::string load_shader_from_file(const std::string& shader_path);
  20.     void update_projection(float new_window_width, float new_window_height);
  21.     void update_uniform_projection();
  22.     void set_color(float r, float g, float b);
  23.     void set_viewport_size(float width, float height);
  24.  
  25.     //draw functions
  26.     void draw_rectangle(float x, float y, float width, float height);
  27.     //TODO: implement
  28.     void draw_circle();
  29.     OpenGL();
  30. private:
  31.     static OpenGL* instance;
  32.  
  33.     //OpenGL state
  34.     struct glstate state;
  35.     // when user doesn't provide any projection mode
  36.     // this default one will be used
  37.     GLsizei window_width, window_height = 0;
  38.     ProjectionMode current_projection_mode = ProjectionMode::PROJECTION_MODE_UNSET;
  39.     glm::mat4x4 projection_matrix;
  40.     ~OpenGL(){};
  41. };
  42.  
  43.  
  44.  
  45.  
  46. OpenGL::OpenGL()
  47. {
  48.     //keep getting segfault here
  49.     state.program = glCreateProgram();
  50.     state.projection = glm::ortho(0.0f, 800.0f, 600.0f, 0.0f, -1.0f, 1.0f);
  51.     state.r = 1.0;
  52.     state.g = 1.0;
  53.     state.b = 1.0;
  54.     state.draw_calls_batched = 0;
  55. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top