├── SDL2-GUI ├── testGUI.json ├── GUIForm.cpp ├── atlas.png ├── button.bmp ├── button.png ├── closet.bmp ├── error.bmp ├── render.bmp ├── Prototype.ttf ├── buttonTest.jpg ├── testButton.bmp ├── testTexture.bmp ├── Dense-Regular.otf ├── DroidSerif-Regular.ttf ├── content │ ├── ButtonSDFTemplate.png │ ├── Fonts │ │ ├── VeraMoBI_test.png │ │ ├── VeraMoBI.ttf_sdf.png │ │ └── testBitmapFont.png_sdf.png │ ├── RadioButtonSDFTemplate.png │ ├── ButtonSDFTemplate.png_sdf.png │ ├── RadioButtonSDFTemplate.png_sdf.png │ └── HTMLElementTemplates.xml ├── tri.frag ├── UniformVarLoading.h ├── StringUtils.h ├── text.vert ├── GUITextInput.cpp ├── GL_Stencil.h ├── panel.vert ├── GUIEvent.h ├── Element.cpp ├── text.frag ├── tri.vert ├── panel.frag ├── json │ ├── json.h │ ├── autolink.h │ ├── forwards.h │ ├── assertions.h │ ├── features.h │ ├── config.h │ ├── writer.h │ └── reader.h ├── StringUtils.cpp ├── Mesh.h ├── TextureLoading.h ├── SimpleMesh.h ├── GUIRadioButton.cpp ├── CubeMap.h ├── GUIImage.h ├── GUIBoxBound.cpp ├── VertAttribLoading.h ├── GUIListItem.h ├── VertexAttrib.h ├── Texture.h ├── GUIUnorderedList.h ├── VertexAttrib.cpp ├── GUIForm.h ├── CubeMap.cpp ├── Texture.cpp ├── GUIBound.h ├── Mesh.cpp ├── GLSLMaterial.h ├── GUIBoxBound.h ├── MaterialFactory.h ├── GUITextBox.h ├── xmlGUITest.xml ├── GUITextInput.h ├── GUITextBox.cpp ├── GUILayout.h ├── GLSLShader.h ├── GLSLMaterial.cpp ├── GUILayout.cpp ├── GUIButton.cpp ├── GUIRadioButton.h ├── FrameBuffer.h ├── GUIView.cpp ├── GUIManager.cpp ├── GUIManager.h ├── GUIButton.h ├── GL_Camera.h ├── FrameBuffer.cpp ├── mainSDLtest.cpp ├── UtilityFuncs.h ├── TextureLoading.cpp ├── GUIFactory.h ├── tut1.h ├── GUIFont.h ├── UniformVar.h ├── VertAttribLoading.cpp ├── MaterialFactory.cpp ├── GUIView.h ├── Element.h ├── GLSLShader.cpp ├── SDL2-GUI.vcxproj ├── SDL2-GUI.vcxproj.filters ├── GUIFactory.cpp ├── jansson.h └── GUIFont.cpp ├── SDLGUI_Demo.jpg ├── .gitattributes ├── README.md ├── SDL2-GUI.sln └── .gitignore /SDL2-GUI/testGUI.json: -------------------------------------------------------------------------------- 1 | Ascii text -------------------------------------------------------------------------------- /SDL2-GUI/GUIForm.cpp: -------------------------------------------------------------------------------- 1 | #include"GUIForm.h" 2 | 3 | namespace SDLGUI { 4 | 5 | } -------------------------------------------------------------------------------- /SDLGUI_Demo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pieisgood/SDL2-GUI/HEAD/SDLGUI_Demo.jpg -------------------------------------------------------------------------------- /SDL2-GUI/atlas.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pieisgood/SDL2-GUI/HEAD/SDL2-GUI/atlas.png -------------------------------------------------------------------------------- /SDL2-GUI/button.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pieisgood/SDL2-GUI/HEAD/SDL2-GUI/button.bmp -------------------------------------------------------------------------------- /SDL2-GUI/button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pieisgood/SDL2-GUI/HEAD/SDL2-GUI/button.png -------------------------------------------------------------------------------- /SDL2-GUI/closet.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pieisgood/SDL2-GUI/HEAD/SDL2-GUI/closet.bmp -------------------------------------------------------------------------------- /SDL2-GUI/error.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pieisgood/SDL2-GUI/HEAD/SDL2-GUI/error.bmp -------------------------------------------------------------------------------- /SDL2-GUI/render.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pieisgood/SDL2-GUI/HEAD/SDL2-GUI/render.bmp -------------------------------------------------------------------------------- /SDL2-GUI/Prototype.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pieisgood/SDL2-GUI/HEAD/SDL2-GUI/Prototype.ttf -------------------------------------------------------------------------------- /SDL2-GUI/buttonTest.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pieisgood/SDL2-GUI/HEAD/SDL2-GUI/buttonTest.jpg -------------------------------------------------------------------------------- /SDL2-GUI/testButton.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pieisgood/SDL2-GUI/HEAD/SDL2-GUI/testButton.bmp -------------------------------------------------------------------------------- /SDL2-GUI/testTexture.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pieisgood/SDL2-GUI/HEAD/SDL2-GUI/testTexture.bmp -------------------------------------------------------------------------------- /SDL2-GUI/Dense-Regular.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pieisgood/SDL2-GUI/HEAD/SDL2-GUI/Dense-Regular.otf -------------------------------------------------------------------------------- /SDL2-GUI/DroidSerif-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pieisgood/SDL2-GUI/HEAD/SDL2-GUI/DroidSerif-Regular.ttf -------------------------------------------------------------------------------- /SDL2-GUI/content/ButtonSDFTemplate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pieisgood/SDL2-GUI/HEAD/SDL2-GUI/content/ButtonSDFTemplate.png -------------------------------------------------------------------------------- /SDL2-GUI/tri.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | in vec4 theColor; 3 | out vec4 outputColor; 4 | void main(){ 5 | outputColor = theColor; 6 | } -------------------------------------------------------------------------------- /SDL2-GUI/content/Fonts/VeraMoBI_test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pieisgood/SDL2-GUI/HEAD/SDL2-GUI/content/Fonts/VeraMoBI_test.png -------------------------------------------------------------------------------- /SDL2-GUI/content/Fonts/VeraMoBI.ttf_sdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pieisgood/SDL2-GUI/HEAD/SDL2-GUI/content/Fonts/VeraMoBI.ttf_sdf.png -------------------------------------------------------------------------------- /SDL2-GUI/content/RadioButtonSDFTemplate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pieisgood/SDL2-GUI/HEAD/SDL2-GUI/content/RadioButtonSDFTemplate.png -------------------------------------------------------------------------------- /SDL2-GUI/content/ButtonSDFTemplate.png_sdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pieisgood/SDL2-GUI/HEAD/SDL2-GUI/content/ButtonSDFTemplate.png_sdf.png -------------------------------------------------------------------------------- /SDL2-GUI/content/Fonts/testBitmapFont.png_sdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pieisgood/SDL2-GUI/HEAD/SDL2-GUI/content/Fonts/testBitmapFont.png_sdf.png -------------------------------------------------------------------------------- /SDL2-GUI/content/RadioButtonSDFTemplate.png_sdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pieisgood/SDL2-GUI/HEAD/SDL2-GUI/content/RadioButtonSDFTemplate.png_sdf.png -------------------------------------------------------------------------------- /SDL2-GUI/content/HTMLElementTemplates.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /SDL2-GUI/UniformVarLoading.h: -------------------------------------------------------------------------------- 1 | #ifndef UNIFORM_VARIABLE_LOADING 2 | #define UNIFORM_VARIABLE_LOADING 3 | #include 4 | 5 | void LoadUniformVariable(); //overload this function many times 6 | //for vec3, vec4, ... ect. 7 | #endif -------------------------------------------------------------------------------- /SDL2-GUI/StringUtils.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | std::vector &split(const std::string &s, char delim, std::vector &elems); 6 | 7 | std::vector split(const std::string &s, char delim); -------------------------------------------------------------------------------- /SDL2-GUI/text.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | layout (location=0) in vec2 vert_pos; 4 | layout (location=1) in vec2 vert_texcoord; 5 | uniform vec2 text_pos; 6 | out vec2 st; 7 | 8 | void main() { 9 | st = vert_texcoord; 10 | gl_Position = vec4(vert_pos + text_pos, -1.0, 1.0); 11 | } -------------------------------------------------------------------------------- /SDL2-GUI/GUITextInput.cpp: -------------------------------------------------------------------------------- 1 | #include"GUITextInput.h" 2 | 3 | namespace SDLGUI { 4 | 5 | void GUITextInput::draw() { 6 | //m_view->renderText( m_text, m_pos.x, m_pos.y, 10 ); 7 | m_view->renderPanel( m_textureId, m_pos, m_scale ); 8 | } 9 | 10 | void GUITextInput::onKeyPress( SDL_Event* ev ) { 11 | //ev->key. 12 | } 13 | 14 | } -------------------------------------------------------------------------------- /SDL2-GUI/GL_Stencil.h: -------------------------------------------------------------------------------- 1 | #ifndef UI_STENCIL 2 | #define UI_STENCIL 3 | 4 | #include 5 | 6 | class GL_Stencil { 7 | private: 8 | 9 | public: 10 | GL_Stencil(); 11 | ~GL_Stencil(); 12 | 13 | void bindStencil(); 14 | void stencilRect(); 15 | void stencilCircle(); 16 | void stencilShape( GLuint vBuffer ); 17 | 18 | }; 19 | 20 | #endif -------------------------------------------------------------------------------- /SDL2-GUI/panel.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | layout (location=0) in vec2 vertex_position; 4 | uniform vec2 pos; 5 | uniform vec2 scale; 6 | uniform int check; 7 | out vec2 texture_coords; 8 | 9 | void main() { 10 | texture_coords = (vertex_position + 1.0) * 0.5; 11 | gl_Position = vec4((vertex_position * scale) + pos, -1.0, 1.0); 12 | } 13 | 14 | -------------------------------------------------------------------------------- /SDL2-GUI/GUIEvent.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef GUIEVENT 4 | #define GUIEVENT 5 | 6 | namespace SDLGUI { 7 | 8 | enum GUIEventType { 9 | GUI_NONE, 10 | GUI_BUTTON, 11 | GUI_LAYOUT 12 | }; 13 | 14 | typedef struct ButtonEvent { 15 | const char* id; 16 | int x; 17 | int y; 18 | } ButtonEvent; 19 | 20 | typedef struct GUIEvent{ 21 | GUIEventType type; 22 | ButtonEvent button; 23 | } GUIEvent; 24 | 25 | } 26 | 27 | #endif -------------------------------------------------------------------------------- /SDL2-GUI/Element.cpp: -------------------------------------------------------------------------------- 1 | #include"Element.h" 2 | 3 | namespace SDLGUI { 4 | 5 | Element::~Element(){ 6 | 7 | } 8 | 9 | void Element::addChild( std::shared_ptr child ){ 10 | m_children.push_back(child); 11 | } 12 | 13 | void Element::addBound( std::shared_ptr bound ){ 14 | m_boundary = bound; 15 | } 16 | 17 | void Element::addParent( std::shared_ptr parent ){ 18 | m_parent = parent; 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /SDL2-GUI/text.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec2 st; 4 | 5 | uniform sampler2D tex; 6 | uniform vec4 text_color; 7 | out vec4 frag_color; 8 | 9 | const float smoothing = 1.0/16.0; 10 | 11 | void main() { 12 | float distance = texture2D(tex, st).a; 13 | float alpha = smoothstep(0.5 - smoothing, 0.5 + smoothing, distance); 14 | frag_color = vec4(text_color.rgb, alpha*text_color.a); 15 | 16 | //frag_color.a *= smoothstep(1.0, 0.99, distance); 17 | } 18 | -------------------------------------------------------------------------------- /SDL2-GUI/tri.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | layout(location = 0) in vec3 position; 3 | layout(location = 1) in vec3 norm; 4 | smooth out vec4 theColor; 5 | uniform vec2 offset; 6 | uniform mat4 perspectiveMatrix; 7 | uniform mat4 viewMatrix; 8 | uniform mat4 transMatrix; 9 | 10 | void main(){ 11 | vec4 cameraPos = vec4(position, 1.0); 12 | //vec4 cameraPos = position; 13 | gl_Position = perspectiveMatrix * viewMatrix * cameraPos; 14 | theColor = vec4(norm, 1.0); 15 | } -------------------------------------------------------------------------------- /SDL2-GUI/panel.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | in vec2 texture_coords; 3 | uniform sampler2D panel_texture; 4 | uniform int sub; 5 | out vec4 fragColor; 6 | 7 | 8 | void main(){ 9 | vec4 texel = texture2D(panel_texture, texture_coords); 10 | if(texel.a == 0.0){ 11 | discard; 12 | } 13 | if(sub == 1){ 14 | texel = texel + texture_coords.y*(vec4(1.0,1.0,1.0,1.0)); 15 | } 16 | if(sub == 2){ 17 | texel = texel - (1-texture_coords.y)*(vec4(1.0,1.0,1.0,0.0)); 18 | } 19 | 20 | fragColor = texel; 21 | } -------------------------------------------------------------------------------- /SDL2-GUI/json/json.h: -------------------------------------------------------------------------------- 1 | // Copyright 2007-2010 Baptiste Lepilleur 2 | // Distributed under MIT license, or public domain if desired and 3 | // recognized in your jurisdiction. 4 | // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 5 | 6 | #ifndef JSON_JSON_H_INCLUDED 7 | # define JSON_JSON_H_INCLUDED 8 | 9 | # include "autolink.h" 10 | # include "value.h" 11 | # include "reader.h" 12 | # include "writer.h" 13 | # include "features.h" 14 | 15 | #endif // JSON_JSON_H_INCLUDED 16 | -------------------------------------------------------------------------------- /SDL2-GUI/StringUtils.cpp: -------------------------------------------------------------------------------- 1 | #include"StringUtils.h" 2 | 3 | std::vector &split(const std::string &s, char delim, std::vector &elems) { 4 | std::stringstream ss(s); 5 | std::string item; 6 | while (std::getline(ss, item, delim)) { 7 | elems.push_back(item); 8 | } 9 | return elems; 10 | } 11 | 12 | 13 | std::vector split(const std::string &s, char delim) { 14 | std::vector elems; 15 | split(s, delim, elems); 16 | return elems; 17 | } -------------------------------------------------------------------------------- /SDL2-GUI/Mesh.h: -------------------------------------------------------------------------------- 1 | #ifndef GLSL_MESH 2 | #define GLSL_MESH 3 | 4 | #include 5 | #include"GLSLMaterial.h" 6 | 7 | class Mesh { 8 | private: 9 | int m_size; 10 | GLuint m_vao; 11 | std::shared_ptr< GLSLMaterial > m_material; 12 | 13 | public: 14 | Mesh( void ); 15 | ~Mesh( void ); 16 | 17 | void draw( glm::mat4 model , glm::mat4 view , glm::mat4 projection ); 18 | 19 | void setSize( int size ); 20 | void setVAO( GLuint vao ); 21 | void setMaterial( std::shared_ptr< GLSLMaterial > material ); 22 | 23 | 24 | }; 25 | 26 | #endif -------------------------------------------------------------------------------- /SDL2-GUI/TextureLoading.h: -------------------------------------------------------------------------------- 1 | #ifndef TEXTURE_LOADING 2 | #define TEXTURE_LOADING 3 | 4 | #include 5 | 6 | 7 | void loadCubeMap(const char* front, 8 | const char* back, 9 | const char* top, 10 | const char* bottom, 11 | const char* left, 12 | const char* right, 13 | GLuint* tex_cube ); 14 | 15 | bool loadCubeMapSides( GLuint texture, GLenum side_target, const char* file_name ); 16 | GLuint loadTexture( const char* file_name ); 17 | unsigned char* loadImage( const char* file_name , int* x, int* y ); 18 | 19 | #endif -------------------------------------------------------------------------------- /SDL2-GUI/SimpleMesh.h: -------------------------------------------------------------------------------- 1 | #ifndef SIMPLE_MESH 2 | #define SIMPLE_MESH 3 | #include 4 | //VERY Unfinished, and unlikely to be included in SDL2_GUI 5 | /* 6 | class SimpleMesh { 7 | private: 8 | float* m_vertex_array; 9 | float* m_normal_array; 10 | float* m_tex_coord_array; 11 | short* m_index_array; //an array that indexes each triangle in our geometry 12 | GLuint m_vao; //our vertex array object for binding to the render buffer 13 | float m_numVertices; //the number of vertices in our mesh 14 | 15 | public: 16 | 17 | 18 | 19 | 20 | }; 21 | */ 22 | 23 | #endif -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | SDL2-GUI 2 | ======== 3 | 4 | an SDL2 Opengl 3.x GUI system based on HTML and CSS 5 | 6 | I will start working towards finishing this project in the near future. 7 | It seems a good number of people like this and I'd like to deliver a final product. 8 | I've been learning a lot about C++ programming and design. I'll be sticking with a simple interface 9 | and getting everything running again soon. 10 | 11 | Here is an image of rendering a single xml file written with HTML tags 12 | 13 | ![Demo Image of GUI](https://github.com/pieisgood/SDL2-GUI/blob/master/SDLGUI_Demo.jpg) 14 | -------------------------------------------------------------------------------- /SDL2-GUI/GUIRadioButton.cpp: -------------------------------------------------------------------------------- 1 | #include"GUIRadioButton.h" 2 | 3 | namespace SDLGUI { 4 | 5 | GUIRadioButton::GUIRadioButton(): m_state(false) {} 6 | 7 | GUIRadioButton::~GUIRadioButton(){} 8 | 9 | void GUIRadioButton::draw() { 10 | 11 | } 12 | 13 | void GUIRadioButton::onMouseButton( SDL_Event* ev, std::shared_ptr clicked ) { 14 | if( this->isOver( ev->button.x, ev->button.y ) ){ 15 | m_state = !m_state; 16 | } 17 | 18 | } 19 | 20 | void GUIRadioButton::onClick(){} 21 | 22 | bool GUIRadioButton::isOver(int x, int y ) { return false; } 23 | 24 | void GUIRadioButton::onMouseMotion( SDL_Event* ev ) {} 25 | 26 | } -------------------------------------------------------------------------------- /SDL2-GUI/CubeMap.h: -------------------------------------------------------------------------------- 1 | #ifndef CUBE_MAP_TEXTURE 2 | #define CUBE_MAP_TEXTURE 3 | #include"Texture.h" 4 | 5 | class CubeMap : public Texture { 6 | private: 7 | 8 | public: 9 | 10 | CubeMap( void ); 11 | CubeMap( const char* name , GLuint textureId, GLenum textureNumber ); 12 | virtual ~CubeMap( void ); 13 | 14 | virtual void setTexture( GLuint textureId ); 15 | virtual void setTexture( GLuint textureId, GLenum textureNumber ); 16 | virtual void setTexture( const char* name , GLuint textureId ); 17 | virtual void setTexture( const char* name , GLuint textureId, GLenum textureNumber ); 18 | 19 | virtual void bindTexture( void ); 20 | }; 21 | 22 | #endif -------------------------------------------------------------------------------- /SDL2-GUI/GUIImage.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \class GUIForm 3 | * 4 | * \ingroup SDL2-GUI 5 | * 6 | * \brief An Element that implements an image 7 | * 8 | * This class should be used to render an image 9 | * 10 | * \note Should be used like the HTML Form tag 11 | * 12 | * \author Lee Jacobs 13 | * 14 | * \version 1.0 15 | * 16 | * \date 2014/06/10 17 | * 18 | * Contact: leemichaeljacobs@gmail.com 19 | * 20 | * Created on: 2014/05/28 21 | * 22 | * $Id: doxygen-howto.html,v 1.5 2005/04/14 14:16:20 bv Exp $ 23 | * 24 | */ 25 | 26 | #ifndef GUI_IMAGE 27 | #define GUI_IMAGE 28 | 29 | #include"Element.h" 30 | 31 | namespace SDLGUI { 32 | 33 | class GUIImage : public Element { 34 | private: 35 | 36 | public: 37 | 38 | }; 39 | 40 | } 41 | 42 | #endif -------------------------------------------------------------------------------- /SDL2-GUI/GUIBoxBound.cpp: -------------------------------------------------------------------------------- 1 | #include"GUIBoxBound.h" 2 | 3 | namespace SDLGUI { 4 | 5 | GUIBoxBound::GUIBoxBound() { 6 | m_width = 0; 7 | m_height = 0; 8 | m_pos.x = 0; 9 | m_pos.y = 0; 10 | } 11 | 12 | GUIBoxBound::~GUIBoxBound() { 13 | 14 | } 15 | 16 | bool GUIBoxBound::isHit( float mouse_x, float mouse_y ) { 17 | if( mouse_x <= (m_pos.x + m_width) && mouse_x >= (m_pos.x) && 18 | mouse_y <= (m_pos.y + m_height) && mouse_y >= (m_pos.y)){ 19 | return true; 20 | } 21 | return false; 22 | } 23 | 24 | void GUIBoxBound::assignWidth( float width ) { 25 | m_width = width; 26 | } 27 | 28 | void GUIBoxBound::assignHeight( float height ) { 29 | m_height = height; 30 | } 31 | 32 | void GUIBoxBound::assignPos( glm::vec2 pos ) { 33 | m_pos = pos; 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /SDL2-GUI/VertAttribLoading.h: -------------------------------------------------------------------------------- 1 | #ifndef VERTEX_ATTRIBUTE_LOADING 2 | #define VERTEX_ATTRIBUTE_LOADING 3 | 4 | #include // C importer 5 | #include // collects data 6 | #include // various extra operations 7 | #include 8 | 9 | void LoadVertexNormalAttribute( const aiScene* scene , GLuint* vBuffer ); 10 | void LoadVertexColorAttribute( const aiScene* scene , GLuint* vBuffer ); 11 | void LoadVertexTexCoordAttribute( const aiScene* scene , GLuint* vBuffer ); 12 | void LoadVertexTangentAttribute( const aiScene* scene , GLuint* vBuffer ); 13 | void LoadVertexBiTangentAttribute( const aiScene* scene , GLuint* vBuffer ); 14 | void LoadVertexPositionAttribute( const aiScene* scene , GLuint* vBuffer ); 15 | 16 | 17 | #endif -------------------------------------------------------------------------------- /SDL2-GUI/json/autolink.h: -------------------------------------------------------------------------------- 1 | // Copyright 2007-2010 Baptiste Lepilleur 2 | // Distributed under MIT license, or public domain if desired and 3 | // recognized in your jurisdiction. 4 | // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 5 | 6 | #ifndef JSON_AUTOLINK_H_INCLUDED 7 | # define JSON_AUTOLINK_H_INCLUDED 8 | 9 | # include "config.h" 10 | 11 | # ifdef JSON_IN_CPPTL 12 | # include 13 | # endif 14 | 15 | # if !defined(JSON_NO_AUTOLINK) && !defined(JSON_DLL_BUILD) && !defined(JSON_IN_CPPTL) 16 | # define CPPTL_AUTOLINK_NAME "json" 17 | # undef CPPTL_AUTOLINK_DLL 18 | # ifdef JSON_DLL 19 | # define CPPTL_AUTOLINK_DLL 20 | # endif 21 | # include "autolink.h" 22 | # endif 23 | 24 | #endif // JSON_AUTOLINK_H_INCLUDED 25 | -------------------------------------------------------------------------------- /SDL2-GUI/GUIListItem.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \class GUIForm 3 | * 4 | * \ingroup SDL2-GUI 5 | * 6 | * \brief An Element that implements a list item 7 | * 8 | * This class should be used to implement a list item 9 | * should be an iterator and text 10 | * 11 | * \note Should be used like the HTML Form tag 12 | * 13 | * \author Lee Jacobs 14 | * 15 | * \version 1.0 16 | * 17 | * \date 2014/06/10 18 | * 19 | * Contact: leemichaeljacobs@gmail.com 20 | * 21 | * Created on: 2014/05/28 22 | * 23 | * $Id: doxygen-howto.html,v 1.5 2005/04/14 14:16:20 bv Exp $ 24 | * 25 | */ 26 | 27 | #ifndef GUI_LIST_ITEM 28 | #define GUI_LIST_ITEM 29 | 30 | #include"Element.h" 31 | 32 | namespace SDLGUI { 33 | 34 | class GUIListItem : public Element { 35 | 36 | private: 37 | 38 | public: 39 | 40 | }; 41 | 42 | } 43 | 44 | #endif -------------------------------------------------------------------------------- /SDL2-GUI/VertexAttrib.h: -------------------------------------------------------------------------------- 1 | #ifndef GLSL_VERTEX_ATTRIBUTE 2 | #define GLSL_VERTEX_ATTRIBUTE 3 | 4 | #include 5 | 6 | class VertexAttrib { 7 | private: 8 | const char* m_name; 9 | GLuint m_vbo; //the buffer object holding our data, use this to delete the data later 10 | GLuint m_AttributeNum; //the layout number of the attribute 11 | 12 | public: 13 | VertexAttrib( void ); 14 | VertexAttrib( char* name ); 15 | VertexAttrib( char* name, GLuint num ); 16 | virtual ~VertexAttrib( void ); 17 | 18 | //some virtual functions for working with VertexAttributes here. 19 | 20 | void bindAttrib( void ); 21 | 22 | GLuint getLocation( void ); 23 | const char* getName( void ); 24 | 25 | void setName( const char* name ); 26 | void setVBO( GLuint vbo ); 27 | void setAttributeNum( GLuint num ); 28 | 29 | }; 30 | 31 | 32 | #endif -------------------------------------------------------------------------------- /SDL2-GUI/Texture.h: -------------------------------------------------------------------------------- 1 | #ifndef GLSL_TEXTURE_SAMPLER 2 | #define GLSL_TEXTURE_SAMPLER 3 | 4 | #include 5 | #include 6 | 7 | class Texture { 8 | protected: 9 | GLuint m_texId; //our texture id 10 | const char* m_name; //our sampler name in the shader 11 | GLenum m_texNum; //the number id for our texture, GL_TEXTURE0 , GL_TEXTURE1 .. ect 12 | 13 | public: 14 | Texture( void ); 15 | Texture( const char* name , GLuint textureId, GLenum textureNumber ); 16 | virtual ~Texture( void ); 17 | 18 | virtual void setTexture( GLuint textureId ); 19 | virtual void setTexture( GLuint textureId, GLenum textureNumber ); 20 | virtual void setTexture( const char* name , GLuint textureId ); 21 | virtual void setTexture( const char* name , GLuint textureId, GLenum textureNumber ); 22 | 23 | virtual void bindTexture( void ); 24 | }; 25 | 26 | #endif -------------------------------------------------------------------------------- /SDL2-GUI/GUIUnorderedList.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \class GUIForm 3 | * 4 | * \ingroup SDL2-GUI 5 | * 6 | * \brief An Element that handles list items 7 | * 8 | * This class should be used to handle list items 9 | * and to manage how to interact with the list given 10 | * css parameters 11 | * 12 | * \note Should be used like the HTML Form tag 13 | * 14 | * \author Lee Jacobs 15 | * 16 | * \version 1.0 17 | * 18 | * \date 2014/06/10 19 | * 20 | * Contact: leemichaeljacobs@gmail.com 21 | * 22 | * Created on: 2014/05/28 23 | * 24 | * $Id: doxygen-howto.html,v 1.5 2005/04/14 14:16:20 bv Exp $ 25 | * 26 | */ 27 | 28 | #ifndef GUI_UNORDERED_LIST 29 | #define GUI_UNORDERED_LIST 30 | 31 | #include"Element.h" 32 | 33 | namespace SDLGUI { 34 | 35 | class GUIUnorderedList : public Element { 36 | 37 | private: 38 | 39 | public: 40 | 41 | 42 | }; 43 | 44 | } 45 | 46 | #endif -------------------------------------------------------------------------------- /SDL2-GUI/VertexAttrib.cpp: -------------------------------------------------------------------------------- 1 | #include"VertexAttrib.h" 2 | 3 | VertexAttrib::VertexAttrib( void ) {} 4 | VertexAttrib::VertexAttrib( char* name ) : m_name( name ) {} 5 | VertexAttrib::VertexAttrib( char* name, GLuint num ) : 6 | m_name( name ) , m_AttributeNum( num ) {} 7 | 8 | VertexAttrib::~VertexAttrib( void ) {} 9 | 10 | void VertexAttrib::bindAttrib( void ) { 11 | 12 | //glEnableVertexAttribArray( m_AttributeNum ); 13 | 14 | } 15 | 16 | GLuint VertexAttrib::getLocation( void ) { 17 | 18 | return m_AttributeNum; 19 | 20 | } 21 | 22 | const char* VertexAttrib::getName( void ) { 23 | 24 | return m_name; 25 | 26 | } 27 | 28 | void VertexAttrib::setName( const char* name ) { 29 | 30 | m_name = name; 31 | 32 | } 33 | 34 | void VertexAttrib::setVBO( GLuint vbo ) { 35 | 36 | m_vbo = vbo; 37 | 38 | } 39 | 40 | void VertexAttrib::setAttributeNum( GLuint num ) { 41 | 42 | m_AttributeNum = num; 43 | 44 | } -------------------------------------------------------------------------------- /SDL2-GUI/GUIForm.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \class GUIForm 3 | * 4 | * \ingroup SDL2-GUI 5 | * 6 | * \brief An Element that handles user input requests 7 | * 8 | * This class should handle user input requests and send 9 | * data on these requests back to the program. This should 10 | * allow users to send requests and input, like user name and 11 | * passwords. 12 | * 13 | * \note Should be used like the HTML Form tag 14 | * 15 | * \author Lee Jacobs 16 | * 17 | * \version 1.0 18 | * 19 | * \date 2014/06/10 20 | * 21 | * Contact: leemichaeljacobs@gmail.com 22 | * 23 | * Created on: 2014/05/28 24 | * 25 | * $Id: doxygen-howto.html,v 1.5 2005/04/14 14:16:20 bv Exp $ 26 | * 27 | */ 28 | 29 | #ifndef GUIFORM 30 | #define GUIFORM 31 | #include"Element.h" 32 | 33 | namespace SDLGUI { 34 | 35 | class GUIForm : public Element { 36 | private: 37 | std::vector< std::shared_ptr > m_inputs; //the list of inputs we will recieve 38 | 39 | public: 40 | 41 | }; 42 | 43 | } 44 | 45 | #endif -------------------------------------------------------------------------------- /SDL2-GUI.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SDL2-GUI", "SDL2-GUI\SDL2-GUI.vcxproj", "{631977CB-C514-466F-B12C-9BDB15DCE4F7}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {631977CB-C514-466F-B12C-9BDB15DCE4F7}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {631977CB-C514-466F-B12C-9BDB15DCE4F7}.Debug|Win32.Build.0 = Debug|Win32 14 | {631977CB-C514-466F-B12C-9BDB15DCE4F7}.Release|Win32.ActiveCfg = Release|Win32 15 | {631977CB-C514-466F-B12C-9BDB15DCE4F7}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | GlobalSection(Performance) = preSolution 21 | HasPerformanceSessions = true 22 | EndGlobalSection 23 | EndGlobal 24 | -------------------------------------------------------------------------------- /SDL2-GUI/CubeMap.cpp: -------------------------------------------------------------------------------- 1 | #include"CubeMap.h" 2 | 3 | 4 | CubeMap::CubeMap( void ) { 5 | Texture::Texture(); 6 | } 7 | 8 | CubeMap::CubeMap( const char* name , GLuint textureId, GLenum textureNumber ) 9 | { 10 | Texture::Texture( name , textureId , textureNumber ); 11 | } 12 | 13 | CubeMap::~CubeMap( void ) { 14 | 15 | } 16 | 17 | void CubeMap::setTexture( GLuint textureId ) { 18 | 19 | m_texId = textureId; 20 | 21 | } 22 | 23 | void CubeMap::setTexture( GLuint textureId, GLenum textureNumber ) { 24 | 25 | m_texId = textureId; 26 | m_texNum = textureNumber; 27 | 28 | } 29 | 30 | void CubeMap::setTexture( const char* name , GLuint textureId ) { 31 | 32 | m_name = name; 33 | m_texId = textureId; 34 | 35 | } 36 | 37 | void CubeMap::setTexture( const char* name , GLuint textureId, GLenum textureNumber ) { 38 | 39 | m_name = name; 40 | m_texId = textureId; 41 | m_texNum = textureNumber; 42 | 43 | } 44 | 45 | void CubeMap::bindTexture( void ) { 46 | 47 | glActiveTexture( m_texNum ); 48 | glBindTexture( GL_TEXTURE_CUBE_MAP , m_texId ); 49 | 50 | } -------------------------------------------------------------------------------- /SDL2-GUI/Texture.cpp: -------------------------------------------------------------------------------- 1 | #include"Texture.h" 2 | 3 | Texture::Texture( void ) {} 4 | Texture::Texture( const char* name, GLuint textureId , GLenum textureNumber = GL_TEXTURE0 ) : 5 | m_name( name ) , m_texId( textureId ) , m_texNum( textureNumber ) 6 | {} 7 | 8 | Texture::~Texture( void ) { 9 | 10 | //delete( m_name ); 11 | 12 | } 13 | 14 | void Texture::setTexture( GLuint textureId ) { 15 | 16 | m_texId = textureId; 17 | 18 | } 19 | 20 | void Texture::setTexture( GLuint textureId, GLenum textureNumber ) { 21 | 22 | m_texId = textureId; 23 | m_texNum = textureNumber; 24 | 25 | } 26 | 27 | void Texture::setTexture( const char* name , GLuint textureId ) { 28 | 29 | m_name = name; 30 | m_texId = textureId; 31 | 32 | } 33 | 34 | void Texture::setTexture( const char* name , GLuint textureId, GLenum textureNumber ) { 35 | 36 | m_name = name; 37 | m_texId = textureId; 38 | m_texNum = textureNumber; 39 | 40 | } 41 | 42 | void Texture::bindTexture( void ) { 43 | 44 | glActiveTexture( m_texNum ); 45 | glBindTexture( GL_TEXTURE_2D , m_texId ); 46 | 47 | } -------------------------------------------------------------------------------- /SDL2-GUI/json/forwards.h: -------------------------------------------------------------------------------- 1 | // Copyright 2007-2010 Baptiste Lepilleur 2 | // Distributed under MIT license, or public domain if desired and 3 | // recognized in your jurisdiction. 4 | // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 5 | 6 | #ifndef JSON_FORWARDS_H_INCLUDED 7 | # define JSON_FORWARDS_H_INCLUDED 8 | 9 | #if !defined(JSON_IS_AMALGAMATION) 10 | # include "config.h" 11 | #endif // if !defined(JSON_IS_AMALGAMATION) 12 | 13 | namespace Json { 14 | 15 | // writer.h 16 | class FastWriter; 17 | class StyledWriter; 18 | 19 | // reader.h 20 | class Reader; 21 | 22 | // features.h 23 | class Features; 24 | 25 | // value.h 26 | typedef unsigned int ArrayIndex; 27 | class StaticString; 28 | class Path; 29 | class PathArgument; 30 | class Value; 31 | class ValueIteratorBase; 32 | class ValueIterator; 33 | class ValueConstIterator; 34 | #ifdef JSON_VALUE_USE_INTERNAL_MAP 35 | class ValueMapAllocator; 36 | class ValueInternalLink; 37 | class ValueInternalArray; 38 | class ValueInternalMap; 39 | #endif // #ifdef JSON_VALUE_USE_INTERNAL_MAP 40 | 41 | } // namespace Json 42 | 43 | 44 | #endif // JSON_FORWARDS_H_INCLUDED 45 | -------------------------------------------------------------------------------- /SDL2-GUI/GUIBound.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \class GUIBound 3 | * 4 | * \ingroup SDL2-GUI 5 | * 6 | * \brief Base class for boudning geometry 7 | * 8 | * This class is the base class for all bounding objects. 9 | * Each derived class should represent a single geometric bound. 10 | * Each derived class should only expose the isHit() member function. 11 | * 12 | * 13 | * \note All bounding objects must derive from this class 14 | * 15 | * \author Lee Jacobs 16 | * 17 | * \version 1.0 18 | * 19 | * \date 2014/06/10 20 | * 21 | * Contact: leemichaeljacobs@gmail.com 22 | * 23 | * Created on: 2014/05/28 24 | * 25 | * $Id: doxygen-howto.html,v 1.5 2005/04/14 14:16:20 bv Exp $ 26 | * 27 | */ 28 | 29 | #ifndef GUIBOUND 30 | #define GUIBOUND 31 | #include 32 | 33 | namespace SDLGUI { 34 | 35 | class GUIBound { 36 | 37 | public: 38 | 39 | /*! 40 | * \brief 41 | * 42 | * \param 43 | * 44 | * \return 45 | */ 46 | GUIBound(){}; 47 | 48 | /*! 49 | * \brief 50 | * 51 | * \param 52 | * 53 | * \return 54 | */ 55 | virtual ~GUIBound(){}; 56 | 57 | 58 | /*! 59 | * \brief 60 | * 61 | * \param 62 | * 63 | * \return 64 | */ 65 | virtual bool isHit( float mouse_x, float mouse_y ) = 0; 66 | 67 | }; 68 | 69 | } 70 | 71 | #endif -------------------------------------------------------------------------------- /SDL2-GUI/Mesh.cpp: -------------------------------------------------------------------------------- 1 | #include"Mesh.h" 2 | 3 | Mesh::Mesh( void ) : m_size( 0 ) , m_vao( 0 ) {} 4 | Mesh::~Mesh( void ) {} 5 | 6 | void Mesh::draw( glm::mat4 model , glm::mat4 view , glm::mat4 projection ) { 7 | static bool testAttributes = true; 8 | glBindVertexArray( m_vao ); 9 | m_material->use(); 10 | glEnableVertexAttribArray( 0 ); 11 | glEnableVertexAttribArray( 1 ); 12 | glEnableVertexAttribArray( 2 ); 13 | m_material->getProgram()->setUniform( "transMatrix" , model ); 14 | m_material->getProgram()->setUniform( "viewMatrix" , view ); 15 | m_material->getProgram()->setUniform( "perspectiveMatrix" , projection ); 16 | 17 | glDrawArrays( GL_TRIANGLES , 0 , m_size ); 18 | 19 | GLenum glErr; 20 | 21 | if( testAttributes ) { 22 | testAttributes = false; 23 | m_material->getProgram()->printActiveAttribs(); 24 | m_material->getProgram()->printActiveUniforms(); 25 | } 26 | 27 | glErr = glGetError(); 28 | if (glErr != GL_NO_ERROR) 29 | { 30 | printf("glError %i\n", glErr); 31 | } 32 | glUseProgram( 0 ); 33 | 34 | } 35 | 36 | void Mesh::setSize( int size ) { 37 | m_size = size; 38 | } 39 | 40 | void Mesh::setVAO( GLuint vao ) { 41 | m_vao = vao; 42 | } 43 | 44 | void Mesh::setMaterial( std::shared_ptr< GLSLMaterial > material ) { 45 | m_material = material; 46 | } -------------------------------------------------------------------------------- /SDL2-GUI/GLSLMaterial.h: -------------------------------------------------------------------------------- 1 | #ifndef GLSL_MATERIAL 2 | #define GLSL_MATERIAL 3 | 4 | #include"GLSLShader.h" 5 | #include"UniformVar.h" 6 | #include"Texture.h" 7 | #include"VertexAttrib.h" 8 | #include 9 | #include 10 | 11 | class GLSLMaterial { 12 | 13 | private: 14 | 15 | std::vector< std::shared_ptr< Uniform > > m_uniforms; //uniform list 16 | std::vector< std::shared_ptr< Texture > > m_textures; //texture list 17 | std::vector< std::shared_ptr< VertexAttrib > > m_vertAttribs; //Attribute list 18 | std::shared_ptr< GLSLProgram > m_program; //program 19 | 20 | 21 | //attribute and uniform lists go here, need to look up how to work with both! 22 | //should also consider the task of rendering a material on top of a mesh/model! 23 | //A mesh/model should hold reference to the vertex attributes 24 | //a shader should hold reference to the uniforms and changing data! 25 | 26 | 27 | public: 28 | GLSLMaterial( void ); 29 | ~GLSLMaterial( void ); 30 | 31 | void use( void ); 32 | 33 | void addUniform( std::shared_ptr< Uniform > uniform ); 34 | void addTexture( std::shared_ptr< Texture > texture ); 35 | void addVertexAttribute( std::shared_ptr< VertexAttrib > vertAttrib ); 36 | void setProgram( std::shared_ptr< GLSLProgram > program ); 37 | 38 | GLSLProgram* getProgram( void ); 39 | 40 | }; 41 | 42 | #endif -------------------------------------------------------------------------------- /SDL2-GUI/GUIBoxBound.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \class GUIBoxBound 3 | * 4 | * \ingroup SDL2-GUI 5 | * 6 | * \brief A Bounding box object 7 | * 8 | * This class implements a bounding box. 9 | * 10 | * 11 | * \note Simple bounding box 12 | * 13 | * \author Lee Jacobs 14 | * 15 | * \version 1.0 16 | * 17 | * \date 2014/06/10 18 | * 19 | * Contact: leemichaeljacobs@gmail.com 20 | * 21 | * Created on: 2014/05/28 22 | * 23 | * $Id: doxygen-howto.html,v 1.5 2005/04/14 14:16:20 bv Exp $ 24 | * 25 | */ 26 | 27 | #ifndef GUIBOXBOUND 28 | #define GUIBOXBOUND 29 | #include "GUIBound.h" 30 | 31 | namespace SDLGUI { 32 | 33 | class GUIBoxBound : public GUIBound { 34 | private: 35 | float m_width; 36 | float m_height; 37 | glm::vec2 m_pos; //top left hand point 38 | 39 | public: 40 | GUIBoxBound(); 41 | virtual ~GUIBoxBound(); 42 | 43 | /*! 44 | * \brief 45 | * 46 | * \param 47 | * 48 | * \return 49 | */ 50 | virtual bool isHit(float mouse_x, float mouse_y); 51 | 52 | /*! 53 | * \brief 54 | * 55 | * \param 56 | * 57 | * \return 58 | */ 59 | void assignWidth(float width); 60 | 61 | /*! 62 | * \brief 63 | * 64 | * \param 65 | * 66 | * \return 67 | */ 68 | void assignHeight(float height); 69 | 70 | /*! 71 | * \brief 72 | * 73 | * \param 74 | * 75 | * \return 76 | */ 77 | void assignPos(glm::vec2 pos); 78 | }; 79 | 80 | } 81 | 82 | #endif -------------------------------------------------------------------------------- /SDL2-GUI/json/assertions.h: -------------------------------------------------------------------------------- 1 | // Copyright 2007-2010 Baptiste Lepilleur 2 | // Distributed under MIT license, or public domain if desired and 3 | // recognized in your jurisdiction. 4 | // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 5 | 6 | #ifndef CPPTL_JSON_ASSERTIONS_H_INCLUDED 7 | # define CPPTL_JSON_ASSERTIONS_H_INCLUDED 8 | 9 | #include 10 | 11 | #if !defined(JSON_IS_AMALGAMATION) 12 | # include 13 | #endif // if !defined(JSON_IS_AMALGAMATION) 14 | 15 | #if JSON_USE_EXCEPTION 16 | #define JSON_ASSERT( condition ) assert( condition ); // @todo <= change this into an exception throw 17 | #define JSON_FAIL_MESSAGE( message ) throw std::runtime_error( message ); 18 | #else // JSON_USE_EXCEPTION 19 | #define JSON_ASSERT( condition ) assert( condition ); 20 | 21 | // The call to assert() will show the failure message in debug builds. In 22 | // release bugs we write to invalid memory in order to crash hard, so that a 23 | // debugger or crash reporter gets the chance to take over. We still call exit() 24 | // afterward in order to tell the compiler that this macro doesn't return. 25 | #define JSON_FAIL_MESSAGE( message ) { assert(false && message); strcpy(reinterpret_cast(666), message); exit(123); } 26 | 27 | #endif 28 | 29 | #define JSON_ASSERT_MESSAGE( condition, message ) if (!( condition )) { JSON_FAIL_MESSAGE( message ) } 30 | 31 | #endif // CPPTL_JSON_ASSERTIONS_H_INCLUDED 32 | -------------------------------------------------------------------------------- /SDL2-GUI/MaterialFactory.h: -------------------------------------------------------------------------------- 1 | #ifndef MATERIAL_FACTORY 2 | #define MATERIAL_FACTORY 3 | 4 | #include"UniformVar.h" 5 | #include"GLSLMaterial.h" 6 | #include"GLSLShader.h" 7 | #include"VertexAttrib.h" 8 | #include"Texture.h" 9 | #include"tinyxml2.h" 10 | #include"Mesh.h" 11 | //#include // C importer 12 | //#include // collects data 13 | //#include // various extra operations 14 | #include 15 | #include"TextureLoading.h" 16 | #include"VertAttribLoading.h" 17 | #include"CubeMap.h" 18 | 19 | class MaterialFactory { 20 | private: 21 | GLenum m_textureLocation; 22 | tinyxml2::XMLDocument* m_doc; 23 | std::shared_ptr< GLSLMaterial > m_material; 24 | 25 | std::shared_ptr< VertexAttrib > createVertexAttribute( tinyxml2::XMLElement* node , const aiScene* scene ); 26 | std::shared_ptr< Uniform > createUniform( tinyxml2::XMLElement* node ); 27 | std::shared_ptr< Texture > createTexture( tinyxml2::XMLElement* node ); 28 | std::shared_ptr< GLSLProgram > createProgram( tinyxml2::XMLElement* node , std::shared_ptr< GLSLMaterial > material ); 29 | std::shared_ptr< Texture > createCubeMap( tinyxml2::XMLElement* node ); 30 | 31 | public: 32 | 33 | MaterialFactory( void ); 34 | ~MaterialFactory( void ); 35 | 36 | std::shared_ptr< Mesh > createMesh( const char* meshXml ); 37 | std::shared_ptr< GLSLMaterial > createMaterial( tinyxml2::XMLElement* node, const aiScene* scene ); 38 | }; 39 | 40 | #endif -------------------------------------------------------------------------------- /SDL2-GUI/GUITextBox.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \class GUITextBox 3 | * 4 | * \ingroup SDL2-GUI 5 | * 6 | * \brief A text box for word wrapping 7 | * 8 | * Allows for word wrapping and aligned text input. 9 | * 10 | * 11 | * 12 | * 13 | * \note Should be used for all static text 14 | * 15 | * \author Lee Jacobs 16 | * 17 | * \version 1.0 18 | * 19 | * \date 2014/06/10 20 | * 21 | * Contact: leemichaeljacobs@gmail.com 22 | * 23 | * Created on: 2014/05/28 24 | * 25 | * $Id: doxygen-howto.html,v 1.5 2005/04/14 14:16:20 bv Exp $ 26 | * 27 | */ 28 | 29 | #ifndef GUITEXTBOX 30 | #define GUITEXTBOX 31 | #include "Element.h" 32 | 33 | namespace SDLGUI { 34 | 35 | class GUITextBox : public Element { 36 | private: 37 | friend class GUIFactory; 38 | glm::vec2 m_textPos; 39 | 40 | protected: 41 | 42 | void assignWidth(float width){ 43 | m_width = width; 44 | } 45 | 46 | void assignHeight(float height){ 47 | m_height = height; 48 | } 49 | 50 | void assignPosition(glm::vec2 pos){ 51 | m_pos = pos; 52 | } 53 | 54 | void assignScale( glm::vec2 scale ){ 55 | m_scale = scale; 56 | } 57 | 58 | 59 | public: 60 | 61 | GUITextBox(); 62 | virtual ~GUITextBox(); 63 | 64 | virtual void draw(); 65 | virtual void onClick(); 66 | virtual bool isOver(int x, int y); 67 | virtual void onMouseMotion(SDL_Event* ev); 68 | virtual void onMouseButton(SDL_Event* ev, std::shared_ptr clicked); 69 | virtual void onMouseScroll(SDL_Event* ev); 70 | }; 71 | 72 | } 73 | 74 | #endif -------------------------------------------------------------------------------- /SDL2-GUI/xmlGUITest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 9 | 11 | 13 | 15 | Here is some text. I am going to write a 16 | whole bunch of goddamn text to prove that this works really well and that I can use this to write tons of multine text 17 | that no matter what I do I have a ton of text that is available to me and that I can print what ever I want to the screen 18 | and that it will be rendered properly without any bullshit. I need more text to render so that I can prove the performance of this text is going to be appropriate for the type of rendering that I want to support. kjdhfksldjhfkalsjdkasl dskfhslkafj dkfjshlfkjahsdfkjhdfkjhsdkfjhakjdh dskfjhskfh skdjfhskljfh skdfhskfh skldjhfskljfh skldjfhskdjfh skdjfhskfhslkjd fsdkjhf sdfkhsfdlkshfklshdfkshdfks dfksdhfksd fkshdfjsdhfkshfdks fhsdf sd fshd fhskfhskdf sf sd fksdhfkshfs fs fkskd fks dfshdfkjsdhf 19 | -------------------------------------------------------------------------------- /SDL2-GUI/GUITextInput.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \class GUITextInput 3 | * 4 | * \ingroup SDL2-GUI 5 | * 6 | * \brief Dynamic text input 7 | * 8 | * Recieves user text input and builds a string. 9 | * Also renders the string to the screen. 10 | * 11 | * 12 | * 13 | * \note Should be used for user text input 14 | * 15 | * \author Lee Jacobs 16 | * 17 | * \version 1.0 18 | * 19 | * \date 2014/06/10 20 | * 21 | * Contact: leemichaeljacobs@gmail.com 22 | * 23 | * Created on: 2014/05/28 24 | * 25 | * $Id: doxygen-howto.html,v 1.5 2005/04/14 14:16:20 bv Exp $ 26 | * 27 | */ 28 | 29 | #ifndef GUITEXTINPUT 30 | #define GUITEXTINPUT 31 | #include 32 | #include"Element.h" 33 | 34 | namespace SDLGUI { 35 | 36 | class GUITextInput : public Element { 37 | 38 | private: 39 | GLuint m_subRoutine; //the shader subroutine we will use for the button 40 | GLuint m_textureId; //the texture we will use for this button 41 | 42 | public: 43 | 44 | virtual void draw(); 45 | virtual void onClick(); 46 | virtual bool isOver( int x, int y ); 47 | virtual void onMouseMotion( SDL_Event* ev ); 48 | virtual void onMouseButton( SDL_Event* ev, std::shared_ptr clicked ); 49 | virtual void onKeyPress( SDL_Event* ev ); 50 | virtual void addChild( std::shared_ptr child ){}; 51 | virtual void addBound( std::shared_ptr bound ); 52 | virtual void addParent( std::shared_ptr parent ); 53 | virtual void assignLayer( unsigned int layer ); 54 | virtual void assignProgram( std::shared_ptr program ); 55 | 56 | 57 | }; 58 | 59 | } 60 | 61 | #endif -------------------------------------------------------------------------------- /SDL2-GUI/GUITextBox.cpp: -------------------------------------------------------------------------------- 1 | #include"GUITextBox.h" 2 | 3 | namespace SDLGUI { 4 | 5 | GUITextBox::GUITextBox(){ 6 | m_pos.x = 0; 7 | m_pos.y = 0; 8 | m_width = 0; 9 | m_height = 0; 10 | } 11 | 12 | GUITextBox::~GUITextBox(){ 13 | 14 | } 15 | 16 | void GUITextBox::draw(){ 17 | 18 | m_view->renderText( m_textVAO , m_pos.x, m_textPos.y, 32 , m_text.size() ); 19 | 20 | std::vector>::iterator itr; 21 | itr = m_children.begin(); 22 | 23 | for(; itr != m_children.end(); itr++){ 24 | itr[0]->draw(); 25 | } 26 | } 27 | 28 | bool GUITextBox::isOver(int x, int y){ 29 | if( y > (m_screenPos.y) && y < (m_screenPos.y + m_height) && 30 | x > (m_screenPos.x) && x < (m_screenPos.x + m_width) ){ 31 | return true; 32 | } 33 | return false; 34 | } 35 | 36 | void GUITextBox::onClick(){ 37 | std::vector>::iterator itr; 38 | itr = m_children.begin(); 39 | 40 | for(; itr != m_children.end(); itr++){ 41 | itr[0]->onClick(); 42 | } 43 | } 44 | 45 | void GUITextBox::onMouseMotion(SDL_Event* ev){ 46 | std::vector>::iterator itr; 47 | itr = m_children.begin(); 48 | 49 | for(; itr != m_children.end(); itr++){ 50 | itr[0]->onMouseMotion(ev); 51 | } 52 | } 53 | 54 | void GUITextBox::onMouseButton(SDL_Event* ev, std::shared_ptr clicked){ 55 | std::vector>::iterator itr; 56 | itr = m_children.begin(); 57 | 58 | for(; itr != m_children.end(); itr++){ 59 | itr[0]->onMouseButton(ev, clicked); 60 | } 61 | } 62 | 63 | void GUITextBox::onMouseScroll(SDL_Event* ev) { 64 | m_textPos.y += ev->wheel.y; 65 | }; 66 | 67 | } -------------------------------------------------------------------------------- /SDL2-GUI/GUILayout.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \class GUILayout 3 | * 4 | * \ingroup SDL2-GUI 5 | * 6 | * \brief Should work like an HTML div tag 7 | * 8 | * This class should provide the ability to 9 | * have relative placement of elements within 10 | * certain boundaries. Like a sub window. 11 | * 12 | * 13 | * \note Needs to better defined 14 | * 15 | * \author Lee Jacobs 16 | * 17 | * \version 1.0 18 | * 19 | * \date 2014/06/10 20 | * 21 | * Contact: leemichaeljacobs@gmail.com 22 | * 23 | * Created on: 2014/05/28 24 | * 25 | * $Id: doxygen-howto.html,v 1.5 2005/04/14 14:16:20 bv Exp $ 26 | * 27 | */ 28 | 29 | #ifndef GUILAYOUT 30 | #define GUILAYOUT 31 | #include "Element.h" 32 | 33 | 34 | namespace SDLGUI { 35 | 36 | class GUILayout : public Element { 37 | private: 38 | friend class GUIFactory; 39 | std::shared_ptr m_view; 40 | 41 | protected: 42 | 43 | void assignWidth(float width){ 44 | m_width = width; 45 | } 46 | 47 | void assignHeight(float height){ 48 | m_height = height; 49 | } 50 | 51 | void assignPosition(glm::vec2 pos){ 52 | m_pos = pos; 53 | } 54 | 55 | void assignScale( glm::vec2 scale ){ 56 | m_scale = scale; 57 | } 58 | 59 | void assignView( std::shared_ptr view ){ 60 | m_view = view; 61 | } 62 | 63 | public: 64 | 65 | GUILayout(); 66 | virtual ~GUILayout(); 67 | 68 | virtual void draw(); 69 | virtual void onClick(); 70 | virtual bool isOver(int x, int y); 71 | virtual void onMouseMotion(SDL_Event* ev); 72 | virtual void onMouseButton(SDL_Event* ev, std::shared_ptr clicked); 73 | virtual void onMouseScroll( SDL_Event* ev ); 74 | }; 75 | 76 | } 77 | 78 | #endif -------------------------------------------------------------------------------- /SDL2-GUI/json/features.h: -------------------------------------------------------------------------------- 1 | // Copyright 2007-2010 Baptiste Lepilleur 2 | // Distributed under MIT license, or public domain if desired and 3 | // recognized in your jurisdiction. 4 | // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 5 | 6 | #ifndef CPPTL_JSON_FEATURES_H_INCLUDED 7 | # define CPPTL_JSON_FEATURES_H_INCLUDED 8 | 9 | #if !defined(JSON_IS_AMALGAMATION) 10 | # include "forwards.h" 11 | #endif // if !defined(JSON_IS_AMALGAMATION) 12 | 13 | namespace Json { 14 | 15 | /** \brief Configuration passed to reader and writer. 16 | * This configuration object can be used to force the Reader or Writer 17 | * to behave in a standard conforming way. 18 | */ 19 | class JSON_API Features 20 | { 21 | public: 22 | /** \brief A configuration that allows all features and assumes all strings are UTF-8. 23 | * - C & C++ comments are allowed 24 | * - Root object can be any JSON value 25 | * - Assumes Value strings are encoded in UTF-8 26 | */ 27 | static Features all(); 28 | 29 | /** \brief A configuration that is strictly compatible with the JSON specification. 30 | * - Comments are forbidden. 31 | * - Root object must be either an array or an object value. 32 | * - Assumes Value strings are encoded in UTF-8 33 | */ 34 | static Features strictMode(); 35 | 36 | /** \brief Initialize the configuration like JsonConfig::allFeatures; 37 | */ 38 | Features(); 39 | 40 | /// \c true if comments are allowed. Default: \c true. 41 | bool allowComments_; 42 | 43 | /// \c true if root must be either an array or an object value. Default: \c false. 44 | bool strictRoot_; 45 | }; 46 | 47 | } // namespace Json 48 | 49 | #endif // CPPTL_JSON_FEATURES_H_INCLUDED 50 | -------------------------------------------------------------------------------- /SDL2-GUI/GLSLShader.h: -------------------------------------------------------------------------------- 1 | #ifndef GLSLSHADER 2 | #define GLSLSHADER 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace GLSLShader { 9 | enum GLSLShaderType{ 10 | VERTEX, FRAGMENT, GEOMETRY, TESS_CONTROL, 11 | TESS_EVALUATION 12 | }; 13 | }; 14 | 15 | class GLSLProgram { 16 | 17 | private: 18 | 19 | int m_handle; 20 | bool m_linked; 21 | std::string m_logString; 22 | 23 | int getUniformLocation( const char* name ); 24 | bool fileExists( const std::string & fileName ); 25 | 26 | public: 27 | 28 | GLSLProgram(); 29 | virtual ~GLSLProgram(); 30 | 31 | bool compileShaderFromFile( const char* fileName, GLSLShader::GLSLShaderType type ); 32 | bool compileShaderFromString( const std::string & source, GLSLShader::GLSLShaderType type ); 33 | bool link(); 34 | void use(); 35 | std::string log(); 36 | int getHandle(); 37 | bool isLinked(); 38 | void bindAttribLocation( GLuint location, const char* name ); 39 | void bindFragDataLocation( GLuint location, const char* name ); 40 | void setUniform( const char *name, const glm::vec3 & v ); 41 | void setUniform( const char *name, const glm::vec4 & v ); 42 | void setUniform( const char *name, const glm::mat4 & m ); 43 | void setUniform( const char *name, const glm::mat3 & m ); 44 | void setUniform( const char *name, const glm::vec2 & v ); 45 | void setUniform( const char *name, float val ); 46 | void setUniform( const char *name, int val ); 47 | void setUniform( const char *name, bool val ); 48 | void setUniform( const char *name, float x, float y ); 49 | void setUniform( const char *name, float x, float y, float z ); 50 | void setUniform( const char *name, float x, float y, float z, float w ); 51 | 52 | void printActiveUniforms(); 53 | void printActiveAttribs(); 54 | }; 55 | 56 | 57 | 58 | #endif -------------------------------------------------------------------------------- /SDL2-GUI/GLSLMaterial.cpp: -------------------------------------------------------------------------------- 1 | #include"GLSLMaterial.h" 2 | 3 | GLSLMaterial::GLSLMaterial( void ) { } 4 | GLSLMaterial::~GLSLMaterial( void ) { } 5 | 6 | 7 | void GLSLMaterial::addUniform( std::shared_ptr< Uniform > uniform ) { 8 | m_uniforms.push_back( uniform ); 9 | } 10 | 11 | void GLSLMaterial::addTexture( std::shared_ptr< Texture > texture ) { 12 | m_textures.push_back( texture ); 13 | } 14 | 15 | void GLSLMaterial::addVertexAttribute( std::shared_ptr< VertexAttrib > vertAttrib ) { 16 | m_vertAttribs.push_back( vertAttrib ); 17 | } 18 | 19 | void GLSLMaterial::setProgram( std::shared_ptr< GLSLProgram > program ) { 20 | m_program = program; 21 | } 22 | 23 | void GLSLMaterial::use( void ) { 24 | 25 | m_program->use(); 26 | 27 | GLenum glErr; 28 | 29 | glErr = glGetError(); 30 | if (glErr != GL_NO_ERROR) 31 | { 32 | printf("glError %i\n", glErr); 33 | } 34 | 35 | auto uniformIt = m_uniforms.begin(); 36 | for( ; uniformIt != m_uniforms.end(); uniformIt++ ) { 37 | (*uniformIt)->loadUniform( m_program->getHandle() ); 38 | glErr = glGetError(); 39 | if (glErr != GL_NO_ERROR) 40 | { 41 | printf("glError %i\n", glErr); 42 | } 43 | } 44 | 45 | auto vertAttribIt = m_vertAttribs.begin(); 46 | for( ; vertAttribIt != m_vertAttribs.end() ; vertAttribIt++ ) { 47 | (*vertAttribIt)->bindAttrib(); 48 | glErr = glGetError(); 49 | if (glErr != GL_NO_ERROR) 50 | { 51 | printf("glError %i\n", glErr); 52 | } 53 | } 54 | 55 | auto textureIt = m_textures.begin(); 56 | for( ; textureIt != m_textures.end() ; textureIt++ ) { 57 | (*textureIt)->bindTexture(); 58 | glErr = glGetError(); 59 | if (glErr != GL_NO_ERROR) 60 | { 61 | printf("glError %i\n", glErr); 62 | } 63 | } 64 | 65 | } 66 | 67 | GLSLProgram* GLSLMaterial::getProgram( void ) { 68 | return m_program.get(); 69 | } -------------------------------------------------------------------------------- /SDL2-GUI/GUILayout.cpp: -------------------------------------------------------------------------------- 1 | #include"GUILayout.h" 2 | #include 3 | 4 | namespace SDLGUI { 5 | 6 | GUILayout::GUILayout() 7 | : Element(){ 8 | 9 | } 10 | 11 | GUILayout::~GUILayout(){ 12 | 13 | } 14 | 15 | void GUILayout::draw(){ 16 | //optional layout render goes here 17 | //m_view->renderError(m_pos, m_scale); 18 | 19 | std::vector>::iterator itr; 20 | itr = m_children.begin(); 21 | 22 | for(; itr != m_children.end(); itr++){ 23 | itr[0]->draw(); 24 | } 25 | } 26 | 27 | bool GUILayout::isOver(int x, int y){ 28 | if( y > (m_screenPos.y) && y < (m_screenPos.y + m_height) && 29 | x > (m_screenPos.x) && x < (m_screenPos.x + m_width) ){ 30 | return true; 31 | } 32 | return false; 33 | } 34 | 35 | void GUILayout::onClick(){ 36 | std::vector>::iterator itr; 37 | itr = m_children.begin(); 38 | 39 | for(; itr != m_children.end(); itr++){ 40 | itr[0]->onClick(); 41 | } 42 | } 43 | 44 | void GUILayout::onMouseMotion(SDL_Event* ev){ 45 | if( !( this->isOver( ev->motion.x, ev->motion.y ) ) ) { 46 | return; 47 | } 48 | 49 | std::vector>::iterator itr; 50 | itr = m_children.begin(); 51 | 52 | for(; itr != m_children.end(); itr++){ 53 | itr[0]->onMouseMotion(ev); 54 | } 55 | } 56 | 57 | void GUILayout::onMouseButton(SDL_Event* ev, std::shared_ptr clicked){ 58 | if( !(this->isOver(ev->button.x, ev->button.y)) ){ 59 | return; 60 | } 61 | 62 | std::vector>::iterator itr; 63 | itr = m_children.begin(); 64 | 65 | for(; itr != m_children.end(); itr++){ 66 | itr[0]->onMouseButton(ev, clicked); 67 | } 68 | } 69 | 70 | void GUILayout::onMouseScroll( SDL_Event* ev ) { 71 | 72 | m_pos.y += ev->wheel.y; 73 | m_screenPos.y -= ev->wheel.y*240; 74 | 75 | std::vector>::iterator itr; 76 | itr = m_children.begin(); 77 | 78 | for(; itr != m_children.end(); itr++){ 79 | itr[0]->onMouseScroll(ev); 80 | } 81 | } 82 | 83 | } -------------------------------------------------------------------------------- /SDL2-GUI/GUIButton.cpp: -------------------------------------------------------------------------------- 1 | #include"GUIButton.h" 2 | #include 3 | 4 | namespace SDLGUI { 5 | 6 | GUI2DButton::GUI2DButton(){ 7 | m_id = ""; 8 | } 9 | 10 | GUI2DButton::~GUI2DButton(){ 11 | 12 | } 13 | 14 | bool GUI2DButton::isOver(int x, int y){ 15 | if( y > (m_screenPos.y) && y < (m_screenPos.y + m_height) && 16 | x > (m_screenPos.x) && x < (m_screenPos.x + m_width) ){ 17 | return true; 18 | } 19 | return false; 20 | } 21 | 22 | void GUI2DButton::draw(){ 23 | m_view->renderPanel(m_textureId, m_pos, m_scale, m_subRoutine); 24 | } 25 | 26 | void GUI2DButton::onClick(){ 27 | 28 | } 29 | 30 | void GUI2DButton::onMouseMotion(SDL_Event* ev){ 31 | 32 | //Highlight if mouse is over button 33 | if( this->isOver(ev->motion.x , ev->motion.y) ){ 34 | m_subRoutine = 1; 35 | } 36 | else{ 37 | m_subRoutine = 0; 38 | return; 39 | } 40 | 41 | //iterate over children 42 | std::vector>::iterator itr; 43 | itr = m_children.begin(); 44 | 45 | for(; itr != m_children.end(); itr++){ 46 | itr[0]->onMouseMotion(ev); 47 | } 48 | } 49 | 50 | void GUI2DButton::onMouseButton(SDL_Event* ev, std::shared_ptr clicked){ 51 | 52 | bool over = this->isOver(ev->button.x , ev->button.y) ; 53 | 54 | if( ev->type == SDL_MOUSEBUTTONDOWN){ 55 | if( over ){ 56 | m_subRoutine = 2; 57 | clicked->type = GUIEventType::GUI_BUTTON; 58 | clicked->button.id = m_id; 59 | clicked->button.x = m_pos.x; 60 | clicked->button.y = m_pos.y; 61 | this->onClick(); 62 | } 63 | } 64 | else if(over){ 65 | m_subRoutine = 1; 66 | } 67 | else{ 68 | m_subRoutine = 0; 69 | return; 70 | } 71 | 72 | //iterate over children 73 | std::vector>::iterator itr; 74 | itr = m_children.begin(); 75 | 76 | for(; itr != m_children.end(); itr++){ 77 | itr[0]->onMouseButton(ev, clicked); 78 | } 79 | 80 | } 81 | 82 | void GUI2DButton::onMouseScroll(SDL_Event* ev) { 83 | m_pos.y += ev->wheel.y; 84 | m_screenPos.y -= ev->wheel.y*240; 85 | } 86 | 87 | } -------------------------------------------------------------------------------- /SDL2-GUI/GUIRadioButton.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \class GUIRadioButton 3 | * 4 | * \ingroup SDL2-GUI 5 | * 6 | * \brief A derived radio button class 7 | * 8 | * This class is used to create and handle radio buttons 9 | * 10 | * \note Should be built by a factory 11 | * 12 | * \author Lee Jacobs 13 | * 14 | * \version 1.0 15 | * 16 | * \date 2014/06/10 17 | * 18 | * Contact: leemichaeljacobs@gmail.com 19 | * 20 | * Created on: 2014/05/28 21 | * 22 | * $Id: doxygen-howto.html,v 1.5 2005/04/14 14:16:20 bv Exp $ 23 | * 24 | */ 25 | 26 | #ifndef GUI_RADIO_BUTTON 27 | #define GUI_RADIO_BUTTON 28 | #include"Element.h" 29 | 30 | namespace SDLGUI { 31 | 32 | class GUIRadioButton : public Element { 33 | private: 34 | bool m_state; /* clicked ); 76 | 77 | }; 78 | 79 | } 80 | 81 | #endif -------------------------------------------------------------------------------- /SDL2-GUI/FrameBuffer.h: -------------------------------------------------------------------------------- 1 | #ifndef FRAME_BUFFER_UTILITY 2 | #define FRAME_BUFFER_UTILITY 3 | 4 | #include"GLSLShader.h" 5 | #include 6 | 7 | struct FrameBufferSurface { 8 | 9 | float verts[12]; 10 | 11 | float texture_coords[12]; 12 | 13 | FrameBufferSurface() { 14 | verts[0] = -1.0; 15 | verts[1] = 1.0; 16 | verts[2] = -1.0; 17 | verts[3] = -1.0; 18 | verts[4] = 1.0; 19 | verts[5] = -1.0; 20 | verts[6] = 1.0; 21 | verts[7] = -1.0; 22 | verts[8] = 1.0; 23 | verts[9] = 1.0; 24 | verts[10] = -1.0; 25 | verts[11] = 1.0; 26 | 27 | texture_coords[0] = 0.0; 28 | texture_coords[1] = 1.0; 29 | texture_coords[2] = 0.0; 30 | texture_coords[3] = 0.0; 31 | texture_coords[4] = 1.0; 32 | texture_coords[5] = 0.0; 33 | texture_coords[6] = 1.0; 34 | texture_coords[7] = 0.0; 35 | texture_coords[8] = 1.0; 36 | texture_coords[9] = 1.0; 37 | texture_coords[10] = 0.0; 38 | texture_coords[11] = 1.0; 39 | }; 40 | 41 | }; 42 | 43 | class FrameBuffer { 44 | private: 45 | //data members needed for using a framebuffer 46 | std::shared_ptr< GLSLProgram > m_program; 47 | FrameBufferSurface m_windowSurface; 48 | GLuint m_FBO; 49 | GLuint m_renderBuffer; 50 | GLuint m_fbTexture; 51 | GLuint m_windowVBO; 52 | GLuint m_windowVTBO; 53 | GLuint m_windowVAO; 54 | 55 | 56 | public: 57 | FrameBuffer( int windowWidth = 800 , int windowHeight = 600 ); 58 | ~FrameBuffer( void ); 59 | //this class should allow us to easily create framebuffers and "use" them when rendering 60 | //this will allow for easier frame buffer management and switching 61 | 62 | void use( void ); //use this framebuffer for rendering 63 | 64 | void renderToMainBuffer( void ); //renders this framebuffer to the main frame buffer :) 65 | 66 | void setProgram( std::shared_ptr< GLSLProgram > program ) { 67 | m_program = program; 68 | }//at some point we need to change this to a material 69 | 70 | GLuint getBufferTexture( void ) { 71 | return m_fbTexture; 72 | } 73 | 74 | void setWindow( int windowWidth, int windowHeight ); 75 | 76 | }; 77 | 78 | #endif -------------------------------------------------------------------------------- /SDL2-GUI/GUIView.cpp: -------------------------------------------------------------------------------- 1 | #include"GUIView.h" 2 | 3 | namespace SDLGUI { 4 | 5 | GUIView::GUIView( std::shared_ptr program){ 6 | //accept compiled GLSL program 7 | m_program = program; 8 | glGenVertexArrays(1, &m_vao); 9 | glBindVertexArray(m_vao); 10 | 11 | m_program->use(); 12 | 13 | //generate VBO to hold surface data 14 | glGenBuffers(1, &m_vbo); 15 | glBindBuffer(GL_ARRAY_BUFFER, m_vbo); 16 | glBufferData(GL_ARRAY_BUFFER, sizeof(m_surface.verts), m_surface.verts, GL_STATIC_DRAW); 17 | 18 | //bind vertex position attribute to GLSL program 19 | glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, NULL); 20 | m_program->bindAttribLocation(0, "vertex_position"); 21 | glEnableVertexAttribArray(0); 22 | 23 | } 24 | 25 | GUIView::~GUIView(){ 26 | 27 | } 28 | 29 | void GUIView::renderPanel( GLuint texture, glm::vec2 position, glm::vec2 scale ){ 30 | glBindTexture(GL_TEXTURE_2D, texture); 31 | m_program->setUniform("pos", position); 32 | m_program->setUniform("scale", scale); 33 | m_program->setUniform("sub", 0); 34 | glDrawArrays(GL_TRIANGLES, 0, 6); 35 | } 36 | 37 | void GUIView::renderPanel( GLuint texture, glm::vec2 position, glm::vec2 scale, int subroutine ){ 38 | glBindTexture(GL_TEXTURE_2D, texture); 39 | m_program->setUniform("pos", position); 40 | m_program->setUniform("scale", scale); 41 | m_program->setUniform("sub" , subroutine); 42 | glDrawArrays(GL_TRIANGLES, 0, 6); 43 | } 44 | 45 | void GUIView::renderText( GLuint textVAO, float pos_x, float pos_y, int size, int numChars ) { 46 | m_font->renderText( textVAO, pos_x, pos_y, size, numChars ); 47 | } 48 | 49 | void GUIView::renderError( glm::vec2 position, glm::vec2 scale ){ 50 | glBindTexture(GL_TEXTURE_2D, m_errorTexture); 51 | m_program->setUniform("pos", position); 52 | m_program->setUniform("scale", scale); 53 | m_program->setUniform("sub", 0); 54 | glDrawArrays(GL_TRIANGLES, 0, 6); 55 | } 56 | 57 | void GUIView::prepareRenderer(){ 58 | m_program->use(); 59 | glBindVertexArray(m_vao); 60 | glEnableVertexAttribArray(0); 61 | } 62 | 63 | void GUIView::cleanRenderer(){ 64 | glUseProgram(0); 65 | } 66 | 67 | } -------------------------------------------------------------------------------- /SDL2-GUI/GUIManager.cpp: -------------------------------------------------------------------------------- 1 | #include"GUIManager.h" 2 | #include 3 | 4 | namespace SDLGUI { 5 | 6 | GUIManager::GUIManager(){ 7 | m_GUIFrameBuffer = std::shared_ptr( new FrameBuffer() ); 8 | m_event = std::shared_ptr(new GUIEvent()); 9 | m_event->type = GUI_NONE; 10 | } 11 | 12 | GUIManager::GUIManager(std::shared_ptr window){ 13 | assignWindow(window); 14 | } 15 | 16 | void GUIManager::pollGUIEvent(std::shared_ptr in_event){ 17 | //possible problems with this code 18 | *in_event = *m_event; 19 | m_event = std::shared_ptr (new GUIEvent()); 20 | m_event->type = GUI_NONE; 21 | } 22 | 23 | void GUIManager::updateMs(float ms){ 24 | std::string text = std::string("FPS: "); 25 | text.append(std::to_string((int)ms)); 26 | m_fps->updateText(text, 0); 27 | } 28 | 29 | void GUIManager::drawFPS(){ 30 | m_fps->draw(); 31 | } 32 | 33 | void GUIManager::draw(){ 34 | 35 | m_GUIFrameBuffer->use(); 36 | 37 | glClearColor(1.0f, 1.0f,1.0f, 0.0f); 38 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 39 | 40 | glEnable(GL_BLEND); 41 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 42 | 43 | m_view->prepareRenderer(); 44 | m_window->draw(); 45 | 46 | m_GUIFrameBuffer->renderToMainBuffer(); 47 | 48 | } 49 | 50 | void GUIManager::onEvent(SDL_Event* event){ 51 | //handle SDL events and send to children 52 | if(event->type == SDL_MOUSEMOTION){ 53 | m_window->onMouseMotion(event); 54 | } 55 | else if(event->type == SDL_MOUSEBUTTONDOWN || event->type == SDL_MOUSEBUTTONUP){ 56 | m_window->onMouseButton(event, m_event); 57 | } 58 | else if(event->type == SDL_MOUSEWHEEL){ 59 | m_window->onMouseScroll(event); 60 | std::cout << event->wheel.y << '\n'; 61 | } 62 | } 63 | 64 | void GUIManager::assignProgram(std::shared_ptr program){ 65 | m_panelProgram = program; 66 | m_GUIFrameBuffer->setProgram( m_panelProgram ); 67 | } 68 | 69 | void GUIManager::assignWindow(std::shared_ptr window){ 70 | m_window = window; 71 | m_GUIFrameBuffer->setWindow( window->getWidth(), window->getHeight() ); 72 | } 73 | 74 | GUIManager::~GUIManager(){ 75 | 76 | } 77 | 78 | } -------------------------------------------------------------------------------- /SDL2-GUI/GUIManager.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \class GUIManager 3 | * 4 | * \ingroup SDL2-GUI 5 | * 6 | * \brief Manages all Elements and a seperate framebuffer 7 | * 8 | * This class manages the rendering, events and processing 9 | * of elements in the element tree. It also manages a seperate 10 | * framebuffer so that SDL2-GUI rendering does not interfere 11 | * with user rendering. 12 | * 13 | * \note Needs to be created using a GUIFactory 14 | * 15 | * \author Lee Jacobs 16 | * 17 | * \version 1.0 18 | * 19 | * \date 2014/06/10 20 | * 21 | * Contact: leemichaeljacobs@gmail.com 22 | * 23 | * Created on: 2014/05/28 24 | * 25 | * $Id: doxygen-howto.html,v 1.5 2005/04/14 14:16:20 bv Exp $ 26 | * 27 | */ 28 | 29 | #ifndef SDLGUIMANAGER 30 | #define SDLGUIMANAGER 31 | #include "GUIEvent.h" 32 | #include "Element.h" 33 | #include "GUILayout.h" 34 | #include "GUIButton.h" 35 | #include "GUITextBox.h" 36 | #include "FrameBuffer.h" 37 | #include 38 | #include 39 | 40 | namespace SDLGUI { 41 | 42 | class GUIManager { 43 | 44 | private: 45 | 46 | std::shared_ptr m_window; 47 | std::map< std::string , std::shared_ptr> m_idMap; 48 | std::shared_ptr m_GUIFrameBuffer; 49 | std::shared_ptr m_panelProgram; 50 | std::shared_ptr m_fps; //a box to render fps with 51 | std::shared_ptr m_view; 52 | std::shared_ptr m_event; 53 | std::shared_ptr m_focus; //element we are currently focused on 54 | 55 | public: 56 | 57 | GUIManager( std::shared_ptr window ); 58 | 59 | GUIManager(); 60 | 61 | virtual ~GUIManager(); 62 | 63 | void draw(); 64 | void onEvent( SDL_Event* event ); 65 | void pollGUIEvent( std::shared_ptr in_event ); 66 | 67 | void assignWindow( std::shared_ptr window ); 68 | void assignProgram( std::shared_ptr program ); 69 | void drawFPS(); 70 | void updateMs( float ms ); //we update the ms that have passed since each frame 71 | 72 | Element* getElement( const char* id ); 73 | 74 | void assignView( std::shared_ptr view ){ 75 | m_view = view; 76 | } 77 | 78 | void assignFPS( std::shared_ptr fpsBox ){ 79 | m_fps = fpsBox; 80 | } 81 | 82 | std::shared_ptr getWindow(); 83 | 84 | 85 | }; 86 | 87 | } 88 | 89 | #endif -------------------------------------------------------------------------------- /SDL2-GUI/GUIButton.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \class GUI2DButton 3 | * 4 | * \ingroup SDL2-GUI 5 | * 6 | * \brief A derived button class 7 | * 8 | * This class implements an HTML Button Element. 9 | * A texture can be provided to override the default button design. 10 | * Buttons can have any size or position in their parent Element. 11 | * 12 | * 13 | * \note Allows for clickable buttons 14 | * 15 | * \author Lee Jacobs 16 | * 17 | * \version 1.0 18 | * 19 | * \date 2014/06/10 20 | * 21 | * Contact: leemichaeljacobs@gmail.com 22 | * 23 | * Created on: 2014/05/28 24 | * 25 | * $Id: doxygen-howto.html,v 1.5 2005/04/14 14:16:20 bv Exp $ 26 | * 27 | */ 28 | 29 | #ifndef SDLGUIBUTTON 30 | #define SDLGUIBUTTON 31 | #include "Element.h" 32 | #include 33 | 34 | namespace SDLGUI { 35 | 36 | class GUI2DButton : public Element { 37 | private: 38 | friend class GUIFactory; 39 | 40 | const char* m_id; /*!< The id string that represents this button */ 41 | GLuint m_subRoutine; /*!< The shader subroutine used for highlighting the button */ 42 | GLuint m_textureId; /*!< The texture that we use to render the button */ 43 | 44 | 45 | protected: 46 | 47 | void assignWidth(float width){ 48 | m_width = width; 49 | } 50 | 51 | void assignHeight(float height){ 52 | m_height = height; 53 | } 54 | 55 | void assignPosition(glm::vec2 pos){ 56 | m_pos = pos; 57 | } 58 | 59 | void assignId(const char* id){ 60 | m_id = id; 61 | } 62 | 63 | void assignTexture(GLuint textureId){ 64 | m_textureId = textureId; 65 | } 66 | 67 | void assignScale( glm::vec2 scale) { 68 | m_scale = scale; 69 | } 70 | 71 | public: 72 | 73 | /*! 74 | * \brief 75 | * 76 | * \param 77 | * 78 | * \return 79 | */ 80 | GUI2DButton(); 81 | 82 | /*! 83 | * \brief 84 | * 85 | * \param 86 | * 87 | * \return 88 | */ 89 | virtual ~GUI2DButton(); 90 | 91 | /*! 92 | * \brief 93 | * 94 | * \param 95 | * 96 | * \return 97 | */ 98 | virtual void draw(); 99 | 100 | /*! 101 | * \brief 102 | * 103 | * \param 104 | * 105 | * \return 106 | */ 107 | virtual void onClick(); 108 | 109 | /*! 110 | * \brief 111 | * 112 | * \param 113 | * 114 | * \return 115 | */ 116 | virtual bool isOver(int x, int y); 117 | 118 | /*! 119 | * \brief 120 | * 121 | * \param 122 | * 123 | * \return 124 | */ 125 | virtual void onMouseMotion(SDL_Event* ev); 126 | 127 | /*! 128 | * \brief 129 | * 130 | * \param 131 | * 132 | * \return 133 | */ 134 | virtual void onMouseButton(SDL_Event* ev, std::shared_ptr clicked); 135 | 136 | /*! 137 | * \brief 138 | * 139 | * \param 140 | * 141 | * \return 142 | */ 143 | virtual void onMouseScroll(SDL_Event* ev); 144 | 145 | }; 146 | 147 | } 148 | 149 | #endif -------------------------------------------------------------------------------- /SDL2-GUI/GL_Camera.h: -------------------------------------------------------------------------------- 1 | #ifndef OPENGL_CAMERA 2 | #define OPENGL_CAMERA 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | class GL_Camera { 9 | private: 10 | glm::vec3 m_pos; //Camera position in R^3 11 | glm::vec3 m_dir; //Direction the camera is looking 12 | glm::vec3 m_up; //Cameras up direction 13 | glm::vec3 m_right; //Cameras right direction 14 | float m_pitch; //Current pitch in radians 15 | float m_yaw; //Current yaw in radians 16 | float m_speed; //Speed in the xz plane 17 | float m_yaw_speed; //Rotation speed 18 | glm::mat4 m_view; //View Matrix 19 | 20 | public: 21 | 22 | GL_Camera(): m_pos(glm::vec3(0.0,0.0,2.0)), m_dir(glm::vec3(0.0,0.0,1.0)), 23 | m_up(glm::vec3(0.0,1.0,0.0)), m_yaw(0) { 24 | m_right = glm::cross(m_dir, m_up); 25 | } 26 | 27 | GL_Camera(glm::vec3 pos, glm::vec3 dir, glm::vec3 up, float speed, float yaw); 28 | 29 | ~GL_Camera(); 30 | 31 | glm::mat4 lookAt(glm::vec3 target_pos); 32 | void updatePosition(glm::vec3 delta); 33 | void withDir(float delta); 34 | glm::mat4 getViewMatrix(); 35 | void mouseRotation(float deltaX, float deltaY); 36 | void forwardMotion(float deltaTime); 37 | void backwardMotion(float deltaTime); 38 | void rightMotion(float deltaTime); 39 | void leftMotion(float deltaTime); 40 | 41 | }; 42 | 43 | GL_Camera::~GL_Camera(){ 44 | 45 | } 46 | 47 | GL_Camera::GL_Camera(glm::vec3 pos, glm::vec3 dir, glm::vec3 up, float speed, float yaw){ 48 | m_pos = pos; 49 | m_dir = dir; 50 | m_up = up; 51 | m_speed = speed; 52 | m_yaw_speed = yaw; 53 | m_yaw = 0; 54 | } 55 | 56 | void GL_Camera::mouseRotation(float deltaX, float deltaY){ 57 | m_yaw += deltaX/2000.0; 58 | m_pitch += deltaY/2000.0; 59 | m_dir = glm::vec3(cos(m_pitch)*sin(m_yaw), sin(m_pitch), cos(m_pitch)*cos(m_yaw)); 60 | m_right = glm::vec3(sin(m_yaw - 3.14f/2.0f), 0, cos(m_yaw - 3.14f/2.0f)); 61 | m_up = glm::cross(m_right, m_dir); 62 | } 63 | 64 | void GL_Camera::forwardMotion(float deltaTime){ 65 | m_pos = m_pos + deltaTime*m_dir; 66 | } 67 | 68 | void GL_Camera::backwardMotion(float deltaTime){ 69 | m_pos = m_pos - deltaTime*m_dir; 70 | } 71 | 72 | void GL_Camera::rightMotion(float deltaTime){ 73 | m_pos = m_pos + deltaTime*m_right; 74 | } 75 | 76 | void GL_Camera::leftMotion(float deltaTime){ 77 | m_pos = m_pos - deltaTime*m_right; 78 | } 79 | 80 | glm::mat4 GL_Camera::lookAt(glm::vec3 target_pos){ 81 | glm::mat4 temp(0.0); 82 | return temp; 83 | } 84 | 85 | void GL_Camera::updatePosition(glm::vec3 delta){ 86 | m_pos = m_pos + delta; 87 | } 88 | 89 | void GL_Camera::withDir(float delta){ 90 | m_pos = m_pos + delta*m_dir; 91 | } 92 | 93 | glm::mat4 GL_Camera::getViewMatrix(){ 94 | glm::mat4 cam_view = glm::lookAt(m_pos, m_pos+m_dir, m_up); 95 | return cam_view; 96 | } 97 | 98 | 99 | 100 | #endif 101 | -------------------------------------------------------------------------------- /SDL2-GUI/FrameBuffer.cpp: -------------------------------------------------------------------------------- 1 | #include"FrameBuffer.h" 2 | 3 | FrameBuffer::FrameBuffer( int windowWidth , int windowHeight ) { 4 | 5 | this->setWindow( windowWidth , windowHeight ); 6 | 7 | } 8 | 9 | FrameBuffer::~FrameBuffer( void ) { 10 | 11 | } 12 | 13 | void FrameBuffer::use( void ) { 14 | 15 | glBindFramebuffer(GL_FRAMEBUFFER, m_FBO); 16 | 17 | } 18 | 19 | void FrameBuffer::renderToMainBuffer( void ) { 20 | 21 | glBindFramebuffer(GL_FRAMEBUFFER, 0); 22 | glClearColor( 0.0f , 0.0f , 0.0f , 0.0f); 23 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 24 | 25 | glBindVertexArray(m_windowVAO); 26 | 27 | int bufferLoc = glGetUniformLocation( m_program->getHandle() , "panel_texture" ); 28 | 29 | m_program->use(); 30 | m_program->setUniform("pos", glm::vec2(0, 0)); 31 | m_program->setUniform("scale", glm::vec2(1.0, 1.0)); 32 | m_program->setUniform("sub", 0); 33 | glActiveTexture(GL_TEXTURE0); 34 | glUniform1i( bufferLoc , 0 ); 35 | glBindTexture(GL_TEXTURE_2D, m_fbTexture); 36 | glEnableVertexAttribArray(0); 37 | glDrawArrays(GL_TRIANGLES, 0, 6); 38 | glUseProgram(0); 39 | 40 | } 41 | 42 | void FrameBuffer::setWindow( int windowWidth, int windowHeight ) { 43 | 44 | glGenVertexArrays(1, &m_windowVAO); 45 | glBindVertexArray(m_windowVAO); 46 | 47 | glGenFramebuffers(1, &m_FBO); 48 | glGenTextures(1, &m_fbTexture); 49 | //glActiveTexture (GL_TEXTURE0); 50 | glBindTexture(GL_TEXTURE_2D, m_fbTexture); 51 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 52 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 53 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 54 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 55 | glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); 56 | 57 | glTexImage2D( 58 | GL_TEXTURE_2D, 59 | 0, 60 | GL_RGBA, 61 | windowWidth, 62 | windowHeight, 63 | 0, 64 | GL_RGBA, 65 | GL_UNSIGNED_BYTE, 66 | NULL 67 | ); 68 | 69 | glBindFramebuffer(GL_FRAMEBUFFER, m_FBO); 70 | glFramebufferTexture2D( 71 | GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_fbTexture, 0 72 | ); 73 | 74 | glGenRenderbuffers (1, &m_renderBuffer); 75 | glBindRenderbuffer (GL_RENDERBUFFER, m_renderBuffer); 76 | glRenderbufferStorage ( 77 | GL_RENDERBUFFER, 78 | GL_DEPTH_COMPONENT, 79 | windowWidth, 80 | windowHeight 81 | ); 82 | 83 | glFramebufferRenderbuffer ( 84 | GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_renderBuffer 85 | ); 86 | 87 | GLenum drawBuff[] = { GL_COLOR_ATTACHMENT0 }; 88 | glDrawBuffers(1, drawBuff); 89 | 90 | glGenBuffers(1, &m_windowVBO); 91 | glBindBuffer(GL_ARRAY_BUFFER, m_windowVBO); 92 | glBufferData(GL_ARRAY_BUFFER, 2*6*sizeof(float), &m_windowSurface.verts, GL_STATIC_DRAW); 93 | glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0); 94 | glBindBuffer(GL_ARRAY_BUFFER, 0); 95 | glBindFramebuffer(GL_FRAMEBUFFER, 0); 96 | } 97 | 98 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | 32 | ################# 33 | ## Visual Studio 34 | ################# 35 | 36 | ## Ignore Visual Studio temporary files, build results, and 37 | ## files generated by popular Visual Studio add-ons. 38 | 39 | # User-specific files 40 | *.suo 41 | *.user 42 | *.sln.docstates 43 | 44 | # Build results 45 | 46 | [Dd]ebug/ 47 | [Rr]elease/ 48 | x64/ 49 | build/ 50 | [Bb]in/ 51 | [Oo]bj/ 52 | 53 | # MSTest test Results 54 | [Tt]est[Rr]esult*/ 55 | [Bb]uild[Ll]og.* 56 | 57 | *_i.c 58 | *_p.c 59 | *.ilk 60 | *.meta 61 | *.obj 62 | *.pch 63 | *.pdb 64 | *.pgc 65 | *.pgd 66 | *.rsp 67 | *.sbr 68 | *.tlb 69 | *.tli 70 | *.tlh 71 | *.tmp 72 | *.tmp_proj 73 | *.log 74 | *.vspscc 75 | *.vssscc 76 | .builds 77 | *.pidb 78 | *.log 79 | *.scc 80 | 81 | # Visual C++ cache files 82 | ipch/ 83 | *.aps 84 | *.ncb 85 | *.opensdf 86 | *.sdf 87 | *.cachefile 88 | 89 | # Visual Studio profiler 90 | *.psess 91 | *.vsp 92 | *.vspx 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | 101 | # TeamCity is a build add-in 102 | _TeamCity* 103 | 104 | # DotCover is a Code Coverage Tool 105 | *.dotCover 106 | 107 | # NCrunch 108 | *.ncrunch* 109 | .*crunch*.local.xml 110 | 111 | # Installshield output folder 112 | [Ee]xpress/ 113 | 114 | # DocProject is a documentation generator add-in 115 | DocProject/buildhelp/ 116 | DocProject/Help/*.HxT 117 | DocProject/Help/*.HxC 118 | DocProject/Help/*.hhc 119 | DocProject/Help/*.hhk 120 | DocProject/Help/*.hhp 121 | DocProject/Help/Html2 122 | DocProject/Help/html 123 | 124 | # Click-Once directory 125 | publish/ 126 | 127 | # Publish Web Output 128 | *.Publish.xml 129 | *.pubxml 130 | 131 | # NuGet Packages Directory 132 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 133 | #packages/ 134 | 135 | # Windows Azure Build Output 136 | csx 137 | *.build.csdef 138 | 139 | # Windows Store app package directory 140 | AppPackages/ 141 | 142 | # Others 143 | sql/ 144 | *.Cache 145 | ClientBin/ 146 | [Ss]tyle[Cc]op.* 147 | ~$* 148 | *~ 149 | *.dbmdl 150 | *.[Pp]ublish.xml 151 | *.pfx 152 | *.publishsettings 153 | 154 | # RIA/Silverlight projects 155 | Generated_Code/ 156 | 157 | # Backup & report files from converting an old project file to a newer 158 | # Visual Studio version. Backup files are not needed, because we have git ;-) 159 | _UpgradeReport_Files/ 160 | Backup*/ 161 | UpgradeLog*.XML 162 | UpgradeLog*.htm 163 | 164 | # SQL Server files 165 | App_Data/*.mdf 166 | App_Data/*.ldf 167 | 168 | ############# 169 | ## Windows detritus 170 | ############# 171 | 172 | # Windows image file caches 173 | Thumbs.db 174 | ehthumbs.db 175 | 176 | # Folder config file 177 | Desktop.ini 178 | 179 | # Recycle Bin used on file shares 180 | $RECYCLE.BIN/ 181 | 182 | # Mac crap 183 | .DS_Store 184 | 185 | 186 | ############# 187 | ## Python 188 | ############# 189 | 190 | *.py[co] 191 | 192 | # Packages 193 | *.egg 194 | *.egg-info 195 | dist/ 196 | build/ 197 | eggs/ 198 | parts/ 199 | var/ 200 | sdist/ 201 | develop-eggs/ 202 | .installed.cfg 203 | 204 | # Installer logs 205 | pip-log.txt 206 | 207 | # Unit test / coverage reports 208 | .coverage 209 | .tox 210 | 211 | #Translations 212 | *.mo 213 | 214 | #Mr Developer 215 | .mr.developer.cfg 216 | -------------------------------------------------------------------------------- /SDL2-GUI/json/config.h: -------------------------------------------------------------------------------- 1 | // Copyright 2007-2010 Baptiste Lepilleur 2 | // Distributed under MIT license, or public domain if desired and 3 | // recognized in your jurisdiction. 4 | // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 5 | 6 | #ifndef JSON_CONFIG_H_INCLUDED 7 | # define JSON_CONFIG_H_INCLUDED 8 | 9 | /// If defined, indicates that json library is embedded in CppTL library. 10 | //# define JSON_IN_CPPTL 1 11 | 12 | /// If defined, indicates that json may leverage CppTL library 13 | //# define JSON_USE_CPPTL 1 14 | /// If defined, indicates that cpptl vector based map should be used instead of std::map 15 | /// as Value container. 16 | //# define JSON_USE_CPPTL_SMALLMAP 1 17 | /// If defined, indicates that Json specific container should be used 18 | /// (hash table & simple deque container with customizable allocator). 19 | /// THIS FEATURE IS STILL EXPERIMENTAL! There is know bugs: See #3177332 20 | //# define JSON_VALUE_USE_INTERNAL_MAP 1 21 | /// Force usage of standard new/malloc based allocator instead of memory pool based allocator. 22 | /// The memory pools allocator used optimization (initializing Value and ValueInternalLink 23 | /// as if it was a POD) that may cause some validation tool to report errors. 24 | /// Only has effects if JSON_VALUE_USE_INTERNAL_MAP is defined. 25 | //# define JSON_USE_SIMPLE_INTERNAL_ALLOCATOR 1 26 | 27 | // If non-zero, the library uses exceptions to report bad input instead of C 28 | // assertion macros. The default is to use exceptions. 29 | # ifndef JSON_USE_EXCEPTION 30 | # define JSON_USE_EXCEPTION 1 31 | # endif 32 | 33 | /// If defined, indicates that the source file is amalgated 34 | /// to prevent private header inclusion. 35 | /// Remarks: it is automatically defined in the generated amalgated header. 36 | // #define JSON_IS_AMALGAMATION 37 | 38 | 39 | # ifdef JSON_IN_CPPTL 40 | # include 41 | # ifndef JSON_USE_CPPTL 42 | # define JSON_USE_CPPTL 1 43 | # endif 44 | # endif 45 | 46 | # ifdef JSON_IN_CPPTL 47 | # define JSON_API CPPTL_API 48 | # elif defined(JSON_DLL_BUILD) 49 | # define JSON_API __declspec(dllexport) 50 | # elif defined(JSON_DLL) 51 | # define JSON_API __declspec(dllimport) 52 | # else 53 | # define JSON_API 54 | # endif 55 | 56 | // If JSON_NO_INT64 is defined, then Json only support C++ "int" type for integer 57 | // Storages, and 64 bits integer support is disabled. 58 | // #define JSON_NO_INT64 1 59 | 60 | #if defined(_MSC_VER) && _MSC_VER <= 1200 // MSVC 6 61 | // Microsoft Visual Studio 6 only support conversion from __int64 to double 62 | // (no conversion from unsigned __int64). 63 | #define JSON_USE_INT64_DOUBLE_CONVERSION 1 64 | #endif // if defined(_MSC_VER) && _MSC_VER < 1200 // MSVC 6 65 | 66 | #if defined(_MSC_VER) && _MSC_VER >= 1500 // MSVC 2008 67 | /// Indicates that the following function is deprecated. 68 | # define JSONCPP_DEPRECATED(message) __declspec(deprecated(message)) 69 | #endif 70 | 71 | #if !defined(JSONCPP_DEPRECATED) 72 | # define JSONCPP_DEPRECATED(message) 73 | #endif // if !defined(JSONCPP_DEPRECATED) 74 | 75 | namespace Json { 76 | typedef int Int; 77 | typedef unsigned int UInt; 78 | # if defined(JSON_NO_INT64) 79 | typedef int LargestInt; 80 | typedef unsigned int LargestUInt; 81 | # undef JSON_HAS_INT64 82 | # else // if defined(JSON_NO_INT64) 83 | // For Microsoft Visual use specific types as long long is not supported 84 | # if defined(_MSC_VER) // Microsoft Visual Studio 85 | typedef __int64 Int64; 86 | typedef unsigned __int64 UInt64; 87 | # else // if defined(_MSC_VER) // Other platforms, use long long 88 | typedef long long int Int64; 89 | typedef unsigned long long int UInt64; 90 | # endif // if defined(_MSC_VER) 91 | typedef Int64 LargestInt; 92 | typedef UInt64 LargestUInt; 93 | # define JSON_HAS_INT64 94 | # endif // if defined(JSON_NO_INT64) 95 | } // end namespace Json 96 | 97 | 98 | #endif // JSON_CONFIG_H_INCLUDED 99 | -------------------------------------------------------------------------------- /SDL2-GUI/mainSDLtest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "MaterialFactory.h" 3 | #include "GUIFactory.h" 4 | #include "GL_Camera.h" 5 | GL_Camera g_cam = GL_Camera(); 6 | #include "tut1.h" 7 | #include 8 | //#include 9 | 10 | SDL_Window* g_pWindow = 0; 11 | SDL_Renderer* g_pRenderer = 0; 12 | SDL_GLContext GL_Context = 0; 13 | void CreateOGLContext(); 14 | 15 | 16 | SDLGUI::GUIManager* testGUISystem(SDL_Window* window); 17 | 18 | int main(int argc, char **argv){ 19 | 20 | CreateOGLContext(); 21 | SDL_Event ourEvents; 22 | SDLGUI::GUIManager* localManager; 23 | bool running = true; 24 | 25 | if (SDL_Init(SDL_INIT_EVERYTHING) != 0){ 26 | 27 | std::cout << "SDL_Init Error: " << SDL_GetError() << std::endl; 28 | return 1; 29 | 30 | } 31 | 32 | g_pWindow = SDL_CreateWindow("SDL2.0 Opengl 3.3 Setup", SDL_WINDOWPOS_CENTERED, 33 | SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN); 34 | 35 | GL_Context = SDL_GL_CreateContext(g_pWindow); 36 | GLenum err = glewInit(); 37 | 38 | if(g_pWindow == 0){ 39 | 40 | std::cout << "SDL_CreateRenderer error: " << SDL_GetError() << std::endl; 41 | return 1; 42 | 43 | } 44 | 45 | 46 | SDLGUI::GUIFactory* testFactory = new SDLGUI::GUIFactory(g_pWindow); 47 | 48 | std::shared_ptr testManager = testFactory->newGUIManager("xmlGUITest.xml"); 49 | 50 | 51 | init(); 52 | 53 | int mouseX, mouseY; 54 | int mouseXRel, mouseYRel; 55 | const unsigned char* key = SDL_GetKeyboardState(NULL); 56 | unsigned int mouse = SDL_GetRelativeMouseState(&mouseXRel, &mouseYRel); 57 | SDL_GetMouseState(&mouseX, &mouseY); 58 | unsigned int curTime = SDL_GetTicks(); 59 | unsigned int nextTime = 0; 60 | unsigned int tDelta = 0; 61 | std::cout << key[SDLK_q]; 62 | std::cout << mouse; 63 | 64 | std::shared_ptr guiEvent(new SDLGUI::GUIEvent()); 65 | 66 | int frameCount = 0; 67 | int msSum = 0; 68 | 69 | while(running){ 70 | 71 | SDL_PumpEvents(); 72 | 73 | //glClear( GL_COLOR_BUFFER_BIT ); 74 | 75 | while(SDL_PollEvent(&ourEvents)){ 76 | 77 | testManager->onEvent(&ourEvents); 78 | 79 | } 80 | 81 | nextTime = SDL_GetTicks(); 82 | tDelta = nextTime - curTime; 83 | curTime = nextTime; 84 | 85 | 86 | if(msSum > 60){ 87 | 88 | float fps = (float)frameCount /((float)msSum/1000.0) ; 89 | 90 | testManager->updateMs(fps); 91 | msSum = 0; 92 | frameCount = 0; 93 | 94 | } 95 | 96 | testManager->pollGUIEvent(guiEvent); 97 | 98 | if(guiEvent->type == SDLGUI::GUIEventType::GUI_BUTTON){ 99 | 100 | printf("you clicked button: %s", guiEvent->button.id); 101 | 102 | } 103 | 104 | if(key[SDL_SCANCODE_A]){ 105 | g_cam.leftMotion(tDelta/100.0); 106 | } 107 | if(key[SDL_SCANCODE_W]){ 108 | g_cam.forwardMotion(tDelta/100.0); 109 | } 110 | if(key[SDL_SCANCODE_S]){ 111 | g_cam.backwardMotion(tDelta/100.0); 112 | } 113 | if(key[SDL_SCANCODE_D]){ 114 | g_cam.rightMotion(tDelta/100.0); 115 | } 116 | if(key[SDL_SCANCODE_Q]){ 117 | SDL_Quit(); 118 | running = false; 119 | } 120 | 121 | if(SDL_GetRelativeMouseState(&mouseXRel, &mouseYRel)&SDL_BUTTON(1) ){ 122 | g_cam.mouseRotation(mouseXRel*2, mouseYRel*2); 123 | } 124 | 125 | 126 | testManager->draw(); 127 | display(); 128 | 129 | 130 | 131 | 132 | SDL_GL_SwapWindow(g_pWindow); 133 | frameCount++; 134 | msSum += tDelta; 135 | SDL_Delay(5); 136 | 137 | } 138 | 139 | 140 | 141 | return 0; 142 | } 143 | 144 | 145 | void CreateOGLContext(){ 146 | SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); 147 | SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); 148 | SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); 149 | SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); 150 | SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); 151 | SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 16); 152 | } 153 | 154 | 155 | -------------------------------------------------------------------------------- /SDL2-GUI/UtilityFuncs.h: -------------------------------------------------------------------------------- 1 | #include // C importer 2 | #include // collects data 3 | #include // various extra operations 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | std::vector g_vp, g_vt, g_vn; 10 | int g_point_count = 0; 11 | GLuint tex; 12 | 13 | glm::mat4 PerspectiveMatrix( float fov, float aspect, float zFar, float zNear ) { 14 | glm::mat4 pMatrix(0.0); 15 | float range = tan(fov * 0.5) * zNear; 16 | 17 | pMatrix[0][0] = (2.0*zNear)/(range * aspect + range * aspect); 18 | pMatrix[1][1] = zNear / range; 19 | pMatrix[2][2] = (zFar + zNear) / (zNear - zFar); 20 | pMatrix[2][3] = (2 * zFar * zNear) / (zNear - zFar); 21 | pMatrix[3][2] = -1.0f; 22 | 23 | return pMatrix; 24 | } 25 | 26 | glm::mat4 IdentityMat4(){ 27 | glm::mat4 identity; 28 | 29 | identity[0][0] = 1.0; 30 | identity[1][1] = 1.0; 31 | identity[2][2] = 1.0; 32 | identity[3][3] = 1.0; 33 | 34 | return identity; 35 | } 36 | 37 | glm::mat4 Translate( glm::mat4 mat, glm::vec3 trans ) { 38 | mat[0][4] = trans[0]; 39 | mat[1][4] = trans[1]; 40 | mat[2][4] = trans[2]; 41 | return mat; 42 | } 43 | 44 | 45 | bool loadTexture(){ 46 | SDL_Surface* textureImage = SDL_LoadBMP("testTexture.bmp"); 47 | 48 | glGenTextures (1, &tex); 49 | glActiveTexture (GL_TEXTURE0); 50 | glBindTexture (GL_TEXTURE_2D, tex); 51 | glTexImage2D ( 52 | GL_TEXTURE_2D, 53 | 0, 54 | GL_RGB, 55 | textureImage->w, 56 | textureImage->h, 57 | 0, 58 | GL_BGR, 59 | GL_UNSIGNED_BYTE, 60 | textureImage->pixels 61 | ); 62 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 63 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 64 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 65 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 66 | return true; 67 | } 68 | 69 | bool loadMesh( const char* file_name ) { 70 | const aiScene* scene = aiImportFile (file_name, aiProcess_Triangulate); // TRIANGLES! 71 | 72 | if (!scene) { 73 | fprintf (stderr, "ERROR: reading mesh %s\n", file_name); 74 | return false; 75 | } 76 | 77 | printf (" %i animations\n", scene->mNumAnimations); 78 | printf (" %i cameras\n", scene->mNumCameras); 79 | printf (" %i lights\n", scene->mNumLights); 80 | printf (" %i materials\n", scene->mNumMaterials); 81 | printf (" %i meshes\n", scene->mNumMeshes); 82 | printf (" %i textures\n", scene->mNumTextures); 83 | 84 | for (unsigned int m_i = 0; m_i < scene->mNumMeshes; m_i++) { 85 | 86 | const aiMesh* mesh = scene->mMeshes[m_i]; 87 | printf (" %i vertices in mesh\n", mesh->mNumVertices); 88 | g_point_count = mesh->mNumVertices; 89 | 90 | for (unsigned int v_i = 0; v_i < mesh->mNumVertices; v_i++) { 91 | if (mesh->HasPositions ()) { 92 | const aiVector3D* vp = &(mesh->mVertices[v_i]); 93 | //printf (" vp %i (%f,%f,%f)\n", v_i, vp->x, vp->y, vp->z); 94 | g_vp.push_back (vp->x); 95 | g_vp.push_back (vp->y); 96 | g_vp.push_back (vp->z); 97 | } 98 | if (mesh->HasNormals ()) { 99 | const aiVector3D* vn = &(mesh->mNormals[v_i]); 100 | //printf (" vn %i (%f,%f,%f)\n", v_i, vn->x, vn->y, vn->z); 101 | g_vn.push_back (vn->x); 102 | g_vn.push_back (vn->y); 103 | g_vn.push_back (vn->z); 104 | } 105 | if (mesh->HasTextureCoords (0)) { 106 | const aiVector3D* vt = &(mesh->mTextureCoords[0][v_i]); 107 | //printf (" vt %i (%f,%f)\n", v_i, vt->x, vt->y); 108 | g_vt.push_back (vt->x); 109 | g_vt.push_back (vt->y); 110 | } 111 | if (mesh->HasTangentsAndBitangents ()) { 112 | // NB: could store/print tangents here 113 | } 114 | } 115 | } 116 | 117 | printf(" %i normals in mesh\n", g_vn.size()/3); 118 | 119 | aiReleaseImport(scene); 120 | return true; 121 | } 122 | 123 | void meshToBuffer() { 124 | unsigned int vbo = 0; 125 | unsigned int nbo = 0; 126 | glGenBuffers(1, &vbo); 127 | glBindBuffer (GL_ARRAY_BUFFER, vbo); 128 | glBufferData (GL_ARRAY_BUFFER, g_point_count * 3 * sizeof (float), &g_vp[0], 129 | GL_STATIC_DRAW); 130 | unsigned int vao = 0; 131 | glGenVertexArrays (1, &vao); 132 | glBindVertexArray (vao); 133 | glEnableVertexAttribArray (0); 134 | glBindBuffer (GL_ARRAY_BUFFER, vbo); 135 | glVertexAttribPointer (0, 3, GL_FLOAT, GL_FALSE, 0, (GLubyte*)NULL); 136 | } -------------------------------------------------------------------------------- /SDL2-GUI/TextureLoading.cpp: -------------------------------------------------------------------------------- 1 | #include"TextureLoading.h" 2 | //#define STB_IMAGE_IMPLEMENTATION 3 | #include"stb_image.h" 4 | #include 5 | #include 6 | 7 | 8 | void loadCubeMap(const char* front, 9 | const char* back, 10 | const char* top, 11 | const char* bottom, 12 | const char* left, 13 | const char* right, 14 | GLuint* tex_cube ) { 15 | // generate a cube-map texture to hold all the sides 16 | glActiveTexture (GL_TEXTURE0); 17 | glGenTextures (1, tex_cube); 18 | 19 | // load each image and copy into a side of the cube-map texture 20 | assert ( 21 | loadCubeMapSides (*tex_cube, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, front)); 22 | assert ( 23 | loadCubeMapSides (*tex_cube, GL_TEXTURE_CUBE_MAP_POSITIVE_Z, back)); 24 | assert ( 25 | loadCubeMapSides (*tex_cube, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, top)); 26 | assert ( 27 | loadCubeMapSides (*tex_cube, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, bottom)); 28 | assert ( 29 | loadCubeMapSides (*tex_cube, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, left)); 30 | assert ( 31 | loadCubeMapSides (*tex_cube, GL_TEXTURE_CUBE_MAP_POSITIVE_X, right)); 32 | // format cube map texture 33 | glTexParameteri (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 34 | glTexParameteri (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 35 | glTexParameteri (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); 36 | glTexParameteri (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 37 | glTexParameteri (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 38 | } 39 | 40 | bool loadCubeMapSides( GLuint texture, GLenum side_target, const char* file_name ) { 41 | 42 | glBindTexture (GL_TEXTURE_CUBE_MAP, texture); 43 | 44 | int x, y, n; 45 | int force_channels = 4; 46 | unsigned char* image_data = stbi_load ( 47 | file_name, &y , &x, &n, force_channels); 48 | 49 | if (!image_data) { 50 | fprintf (stderr, "ERROR: could not load %s\n", file_name); 51 | return false; 52 | } 53 | 54 | // non-power-of-2 dimensions check 55 | if ((x & (x - 1)) != 0 || (y & (y - 1)) != 0) { 56 | fprintf ( 57 | stderr, "WARNING: image %s is not power-of-2 dimensions\n", file_name 58 | ); 59 | } 60 | 61 | // copy image data into 'target' side of cube map 62 | glTexImage2D ( 63 | side_target, 64 | 0, 65 | GL_RGBA, 66 | x, 67 | y, 68 | 0, 69 | GL_RGBA, 70 | GL_UNSIGNED_BYTE, 71 | image_data 72 | ); 73 | 74 | free (image_data); 75 | 76 | return true; 77 | } 78 | 79 | GLuint loadTexture( const char* file_name ) { 80 | int x, y; 81 | unsigned char* image = loadImage(file_name, &x, &y); 82 | 83 | GLuint localTexture; 84 | 85 | glGenTextures (1, &localTexture); 86 | //glActiveTexture (GL_TEXTURE0); 87 | glBindTexture (GL_TEXTURE_2D, localTexture); 88 | glTexImage2D ( 89 | GL_TEXTURE_2D, 90 | 0, 91 | GL_RGBA, 92 | x, 93 | y, 94 | 0, 95 | GL_RGBA, 96 | GL_UNSIGNED_BYTE, 97 | image 98 | ); 99 | 100 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 101 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 102 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 103 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 104 | 105 | delete[](image); 106 | 107 | return localTexture; 108 | } 109 | 110 | unsigned char* loadImage( const char* file_name , int* x, int* y ) { 111 | int n; 112 | int force_channels = 4; 113 | unsigned char* image_data = stbi_load (file_name, x, y, &n, force_channels); 114 | 115 | if (!image_data) { 116 | fprintf (stderr, "ERROR: could not load %s\n", file_name); 117 | } 118 | 119 | // NPOT check 120 | if ((*x & (*x - 1)) != 0 || (*y & (*y - 1)) != 0) { 121 | fprintf ( 122 | stderr, "WARNING: texture %s is not power-of-2 dimensions\n", file_name 123 | ); 124 | } 125 | 126 | int width_in_bytes = *x * 4; 127 | unsigned char *top = NULL; 128 | unsigned char *bottom = NULL; 129 | unsigned char temp = 0; 130 | int half_height = (*y) / 2; 131 | 132 | for (int row = 0; row < half_height; row++) { 133 | top = image_data + row * width_in_bytes; 134 | bottom = image_data + (*y - row - 1) * width_in_bytes; 135 | for (int col = 0; col < width_in_bytes; col++) { 136 | temp = *top; 137 | *top = *bottom; 138 | *bottom = temp; 139 | top++; 140 | bottom++; 141 | } 142 | } 143 | 144 | return image_data; 145 | } 146 | -------------------------------------------------------------------------------- /SDL2-GUI/GUIFactory.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \class GUIFactory 3 | * 4 | * \ingroup SDL2-GUI 5 | * 6 | * \brief A class that builds GUIManagers from html documents 7 | * 8 | * This class, when handed an html file, will build GUIManager 9 | * objects as well as all Element objects that are children to 10 | * the GUIManager. This allows for a simple call to build new 11 | * GUIManagers and to allow for ease of use. 12 | * 13 | * \note Should be used to build baseline GUIManagers 14 | * 15 | * \author Lee Jacobs 16 | * 17 | * \version 1.0 18 | * 19 | * \date 2014/06/10 20 | * 21 | * Contact: leemichaeljacobs@gmail.com 22 | * 23 | * Created on: 2014/05/28 24 | * 25 | * $Id: doxygen-howto.html,v 1.5 2005/04/14 14:16:20 bv Exp $ 26 | * 27 | */ 28 | 29 | #ifndef SDLGUIFACTORY 30 | #define SDLGUIFACTORY 31 | #include 32 | #include 33 | #include 34 | #include "GUIManager.h" 35 | #include "tinyxml2.h" 36 | 37 | namespace SDLGUI { 38 | 39 | class GUIFactory { 40 | private: 41 | tinyxml2::XMLDocument* m_doc; //our XML document 42 | std::shared_ptr m_view; 43 | std::shared_ptr m_manager; 44 | int m_windowWidth; 45 | int m_windowHeight; 46 | 47 | /*! 48 | * \brief 49 | * 50 | * \param 51 | * 52 | * \return 53 | */ 54 | std::shared_ptr newElement( tinyxml2::XMLElement* type, std::shared_ptr parent ); 55 | 56 | /*! 57 | * \brief 58 | * 59 | * \param 60 | * 61 | * \return 62 | */ 63 | std::shared_ptr newButton(int x, int y, int width, int height, const char* id, std::shared_ptr parent, const char* texture, glm::vec2 scale); 64 | 65 | /*! 66 | * \brief 67 | * 68 | * \param 69 | * 70 | * \return 71 | */ 72 | std::shared_ptr newLayout(int x, int y, int width, int height, const char* id, std::shared_ptr parent, glm::vec2 scale); 73 | 74 | /*! 75 | * \brief 76 | * 77 | * \param 78 | * 79 | * \return 80 | */ 81 | std::shared_ptr newTextBox( int x, int y, int width, int height, const char* id, std::shared_ptr parent, glm::vec2 scale, std::string text, std::shared_ptr view); 82 | 83 | /*! 84 | * \brief 85 | * 86 | * \param 87 | * 88 | * \return 89 | */ 90 | std::shared_ptr handleButton(tinyxml2::XMLElement* buttonElement, std::shared_ptr parent); 91 | 92 | /*! 93 | * \brief 94 | * 95 | * \param 96 | * 97 | * \return 98 | */ 99 | std::shared_ptr handleLayout(tinyxml2::XMLElement* layoutElement, std::shared_ptr parent); 100 | 101 | /*! 102 | * \brief 103 | * 104 | * \param 105 | * 106 | * \return 107 | */ 108 | std::shared_ptr newGUIFont(const char* fontTexture , const char* fontData , std::shared_ptr fontProgram); 109 | 110 | /*! 111 | * \brief 112 | * 113 | * \param 114 | * 115 | * \return 116 | */ 117 | //unsigned char* loadImage(const char* file, int* x, int* y); 118 | 119 | /*! 120 | * \brief 121 | * 122 | * \param 123 | * 124 | * \return 125 | */ 126 | void iterateTree( tinyxml2::XMLElement* node, std::shared_ptr parent); 127 | 128 | /*! 129 | * \brief 130 | * 131 | * \param 132 | * 133 | * \return 134 | */ 135 | GLuint newTexture(const char* file); 136 | 137 | /*! 138 | * \brief 139 | * 140 | * \param 141 | * 142 | * \return 143 | */ 144 | std::shared_ptr newProgram( const char* vertShader, const char* fragShader); 145 | 146 | /*! 147 | * \brief 148 | * 149 | * \param 150 | * 151 | * \return 152 | */ 153 | glm::vec2 getPos( float x, float y ); 154 | 155 | /*! 156 | * \brief 157 | * 158 | * \param 159 | * 160 | * \return 161 | */ 162 | glm::vec4 createStencil( std::shared_ptr el, std::shared_ptr parent ); 163 | 164 | /*! 165 | * \brief 166 | * 167 | * \param 168 | * 169 | * \return 170 | */ 171 | void alignElementLeft( std::shared_ptr el, std::shared_ptr parent ); 172 | 173 | /*! 174 | * \brief 175 | * 176 | * \param 177 | * 178 | * \return 179 | */ 180 | void alignElementRight( std::shared_ptr el, std::shared_ptr parent ); 181 | 182 | /*! 183 | * \brief 184 | * 185 | * \param 186 | * 187 | * \return 188 | */ 189 | void alignElementMiddle( std::shared_ptr el, std::shared_ptr parent ); 190 | 191 | /*! 192 | * \brief 193 | * 194 | * \param 195 | * 196 | * \return 197 | */ 198 | void alignElementCenter( std::shared_ptr el, std::shared_ptr parent ); 199 | 200 | public: 201 | 202 | /*! 203 | * \brief 204 | * 205 | * \param 206 | * 207 | * \return 208 | */ 209 | GUIFactory(SDL_Window* window); 210 | 211 | /*! 212 | * \brief 213 | * 214 | * \param 215 | * 216 | * \return 217 | */ 218 | virtual ~GUIFactory(); 219 | 220 | /*! 221 | * \brief 222 | * 223 | * \param 224 | * 225 | * \return 226 | */ 227 | std::shared_ptr newGUIManager( const char* xmlFile ); 228 | 229 | 230 | }; 231 | 232 | 233 | } 234 | 235 | 236 | 237 | #endif -------------------------------------------------------------------------------- /SDL2-GUI/tut1.h: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2010-2012 by Jason L. McKesson 2 | //This file is licensed under the MIT License. 3 | 4 | #ifndef TUTORIAL 5 | #define TUTORIAL 6 | 7 | //#define GLEW_STATIC 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "UtilityFuncs.h" 14 | #include "GLSLShader.h" 15 | #include 16 | #include 17 | #include 18 | 19 | glm::mat4 lookAt(glm::vec4 camera_pos, glm::vec4 target_pos, glm::vec3 up_dir); //implement to produce a matrix that looks at a position 20 | 21 | GLuint theProgram; 22 | GLuint panelProgram; 23 | GLSLProgram *testProgram; 24 | GLSLProgram *mProgram; 25 | 26 | const char* strVertexShader = "tri.vert"; 27 | 28 | const char* strFragmentShader = "tri.frag"; 29 | 30 | void InitializeProgram() 31 | { 32 | 33 | mProgram = new GLSLProgram(); 34 | mProgram->compileShaderFromFile("tri.vert", GLSLShader::VERTEX); 35 | mProgram->compileShaderFromFile("tri.frag", GLSLShader::FRAGMENT); 36 | mProgram->link(); 37 | 38 | loadMesh("monkey.dae"); 39 | } 40 | 41 | const float vertexPositions[] = { 42 | 0.0f, 0.5f, -1.0f, 1.0f, 43 | 0.5f, -0.366f, -1.5f, 1.0f, 44 | -0.5f, -0.366f, -0.2f, 1.0f, 45 | 1.0f, 0.0f, 0.0f, 1.0f, 46 | 0.0f, 1.0f, 0.0f, 1.0f, 47 | 0.0f, 0.0f, 1.0f, 1.0f, 48 | }; 49 | float matrixTransform[] = { 50 | 1.0f, 0.0f, 0.0f, 0.0f, // first column 51 | 0.0f, 1.0f, 0.0f, 0.0f, // second column 52 | 0.0f, 0.0f, 1.0f, 0.0f, // third column 53 | 0.5f, 0.0f, 0.0f, 1.0f // fourth column 54 | }; 55 | float points[] = { 56 | -1.0, 1.0, 57 | -1.0, -1.0, 58 | 1.0, -1.0, 59 | 1.0, -1.0, 60 | 1.0, 1.0, 61 | -1.0, 1.0 62 | }; 63 | 64 | float tex_coords[] = { 65 | 0.0, 1.0, 66 | 0.0, 0.0, 67 | 1.0, 0.0, 68 | 1.0, 0.0, 69 | 1.0, 1.0, 70 | 0.0, 1.0 71 | }; 72 | 73 | GLuint positionBufferObject; 74 | GLuint vao; 75 | GLuint panelVao; 76 | GLuint offsetUniform; 77 | GLuint perspectiveMatrixUnif; 78 | GLuint vertBuffer; 79 | GLuint texcBuffer; 80 | GLuint transform; 81 | GLuint viewMatrix; 82 | GLuint normBuffer; 83 | GLuint panMatrix; 84 | GLuint texUni; 85 | GLuint subThing; 86 | GLuint otherThing; 87 | float theMatrix[16]; 88 | 89 | 90 | void InitializeVertexBuffer() 91 | { 92 | glGenBuffers(1, &positionBufferObject); 93 | glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject); 94 | glBufferData(GL_ARRAY_BUFFER, g_point_count * 3 * sizeof (float), &g_vp[0], GL_STATIC_DRAW); 95 | glGenBuffers(1, &normBuffer); 96 | glBindBuffer(GL_ARRAY_BUFFER, normBuffer); 97 | glBufferData(GL_ARRAY_BUFFER, g_point_count * 3 * sizeof (float), &g_vn[0], GL_STATIC_DRAW); 98 | glBindBuffer(GL_ARRAY_BUFFER, 0); 99 | } 100 | 101 | //Called after the window and OpenGL are initialized. Called exactly once, before the main loop. 102 | void init() 103 | { 104 | InitializeProgram(); 105 | loadTexture(); 106 | InitializeVertexBuffer(); 107 | 108 | glm::mat4 matrix = glm::scale(IdentityMat4(), glm::vec3(200.0/640.0, 200.0/480.0, 1.0)); 109 | 110 | glGenVertexArrays(1, &vao); 111 | glBindVertexArray(vao); 112 | 113 | glm::mat4x4 persMatrix = glm::perspective(60.0f, 640.0f/ 480.0f, 0.5f, 100.0f); 114 | glm::mat4 vMatrix = g_cam.getViewMatrix(); 115 | 116 | mProgram->use(); 117 | mProgram->bindAttribLocation(0, "position"); 118 | mProgram->bindAttribLocation(1, "norm"); 119 | mProgram->setUniform("viewMatrix", vMatrix); 120 | mProgram->setUniform("transMatrix", matrixTransform); 121 | mProgram->setUniform("perspectiveMatrix", persMatrix); 122 | glUseProgram(0); 123 | 124 | mProgram->printActiveAttribs(); 125 | mProgram->printActiveUniforms(); 126 | 127 | glEnable(GL_CULL_FACE); 128 | glCullFace(GL_BACK); 129 | glFrontFace(GL_CCW); 130 | glEnable(GL_DEPTH_TEST); 131 | glDepthMask(GL_TRUE); 132 | glDepthFunc(GL_LEQUAL); 133 | glDepthRange(0.0f, 1.0f); 134 | } 135 | 136 | //Called to update the display. 137 | //You should call glutSwapBuffers after all of your rendering to display what you rendered. 138 | //If you need continuous updates of the screen, call glutPostRedisplay() at the end of the function. 139 | void display() 140 | { 141 | glBindVertexArray(vao); 142 | 143 | mProgram->use(); 144 | glEnableVertexAttribArray(0); 145 | glEnableVertexAttribArray(1); 146 | mProgram->setUniform("viewMatrix", g_cam.getViewMatrix()); 147 | glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject); 148 | glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); 149 | glBindBuffer(GL_ARRAY_BUFFER, normBuffer); 150 | glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0); 151 | glDrawArrays(GL_TRIANGLES, 0, g_vp.size()); 152 | glUseProgram(0); 153 | 154 | } 155 | 156 | //Called whenever the window is resized. The new window size is given, in pixels. 157 | //This is an opportunity to call glViewport or glScissor to keep up with the change in size. 158 | void reshape (int w, int h) 159 | { 160 | float fFrustumScale = 1.0f; 161 | theMatrix[0] = fFrustumScale / (w / (float)h); 162 | theMatrix[5] = fFrustumScale; 163 | 164 | glUseProgram(theProgram); 165 | glUniformMatrix4fv(perspectiveMatrixUnif, 1, GL_FALSE, theMatrix); 166 | glUseProgram(0); 167 | 168 | glViewport(0, 0, (GLsizei) w, (GLsizei) h); 169 | } 170 | 171 | 172 | unsigned int defaults(unsigned int displayMode, int &width, int &height) {return displayMode;} 173 | #endif -------------------------------------------------------------------------------- /SDL2-GUI/GUIFont.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \class GUIFont 3 | * 4 | * \ingroup SDL2-GUI 5 | * 6 | * \brief Font Rendering and Management class 7 | * 8 | * This class is meant to help generate and render text. 9 | * Outside tools can be used to generate the distance field 10 | * and char descriptor files. These are provided under the 11 | * tools folder in SDL2-GUI. 12 | * 13 | * \note Text rendering made easy. 14 | * 15 | * \author Lee Jacobs 16 | * 17 | * \version 1.0 18 | * 19 | * \date 2014/06/10 20 | * 21 | * Contact: leemichaeljacobs@gmail.com 22 | * 23 | * Created on: 2014/05/28 24 | * 25 | * $Id: doxygen-howto.html,v 1.5 2005/04/14 14:16:20 bv Exp $ 26 | * 27 | */ 28 | 29 | #ifndef GUIFONT 30 | #define GUIFONT 31 | #include 32 | #include"GLSLShader.h" 33 | #include 34 | #include 35 | 36 | namespace SDLGUI { 37 | 38 | struct CharDescriptor 39 | { 40 | //clean 16 bytes 41 | unsigned short x, y; 42 | unsigned short Width, Height; 43 | float XOffset, YOffset; 44 | float XAdvance; 45 | unsigned short Page; 46 | 47 | CharDescriptor() : x( 0 ), y( 0 ), Width( 0 ), Height( 0 ), XOffset( 0 ), YOffset( 0 ), 48 | XAdvance( 0 ), Page( 0 ) 49 | { } 50 | }; 51 | 52 | struct Charset 53 | { 54 | unsigned short LineHeight; 55 | unsigned short Base; 56 | unsigned short Width, Height; 57 | unsigned short Pages; 58 | CharDescriptor Chars[256]; 59 | }; 60 | 61 | class GUIFont { 62 | 63 | private: 64 | Charset m_charSet; 65 | std::shared_ptr m_fontProgram; 66 | GLuint m_fontTexture; 67 | GLuint m_textVAO; //our vertex attributes for fonts/text 68 | const char* m_fontData; 69 | glm::vec3 m_color; 70 | float m_alpha; 71 | 72 | 73 | bool parseFont( std::istream& Stream ); 74 | GUIFont(){}; 75 | 76 | public: 77 | 78 | GUIFont( GLuint fontTexture , const char* fontData , std::shared_ptr fontProgram ); 79 | ~GUIFont(); 80 | 81 | 82 | void renderText( std::string text , float x , float y , int size ); //render text to screen 83 | 84 | /*! 85 | * \brief Used to render cached text in the form of a Vertex Array Object 86 | * 87 | * \param textVAO a GLuint that represents the vertex array object referencing the buffer objects on the gpu 88 | * \param x the x position to render the text at 89 | * \param y the y position to render the text at 90 | * \param size the size to render the text at 91 | * \param stringSize the length of the string, needed to properly call the glDrawArrays function 92 | * 93 | * \return void 94 | */ 95 | void renderText( GLuint textVAO , float x, float y, int size, int stringSize); 96 | 97 | /*! 98 | * \brief Used to update the color of the text to be rendered 99 | * 100 | * \param color A GLM Vec3 representing the color of the text 101 | * 102 | * \return void 103 | */ 104 | void assignColor( glm::vec3 color ); 105 | 106 | /*! 107 | * \brief Used to update the transparency of the text to be rendered 108 | * 109 | * \param alpha A float value from 0.0f to 1.0f representing the transparency of the text 110 | * 111 | * \return void 112 | */ 113 | void assignTransparency( float alpha ); 114 | 115 | /*! 116 | * \brief Used to cache text for future rendering 117 | * 118 | * \param text A string that represents the text to be used in the cache 119 | * \param vertVBO The vertex buffer object that will store our text verticies 120 | * \param texcoordVBO The vertex buffer object that will store our texture coordinates for our text verticies 121 | * \param textVAO The vertex array object we will call when rendering our text to the screen 122 | * 123 | * \return 124 | */ 125 | GLuint cacheText( std::string text, GLuint vertVBO, GLuint texcoordVBO, GLuint textVAO ); 126 | 127 | /*! 128 | * \brief Used to cache text in a bounded box and allows for simple word wrapping. 129 | * 130 | * \param text A string that represents the text to be used in the cache 131 | * \param vertVBO The vertex buffer object that will store our text verticies 132 | * \param texcoordVBO The vertex buffer object that will store our texture coordinates for our text verticies 133 | * \param textVAO The vertex array object we will call when rendering our text to the screen 134 | * \param width The width of the text box in pixels 135 | * 136 | * \return 137 | */ 138 | GLuint cacheTextWrap( std::string text, GLuint vertVBO, GLuint texcoordVBO, GLuint textVAO , int width ); 139 | 140 | /*! 141 | * \brief Used to update a small portion of cached text, for dynamic updating of text 142 | * 143 | * \param text A string that represents the text to be used in the cache 144 | * \param vertVBO The vertex buffer object that will store our text verticies 145 | * \param texcoordVBO The vertex buffer object that will store our texture coordinates for our text verticies 146 | * \param textVAO The vertex array object we will call when rendering our text to the screen 147 | * \param updateLocation the character location to start updating from 148 | * \param CurY the Y location in pixels to draw the new text 149 | * \param CurX the X location in pixels to draw the new text 150 | * 151 | * \return 152 | */ 153 | GLuint updateCacheText( std::string text,GLuint vertVBO, GLuint texcoordVBO, GLuint textVAO , int updateLocation, int CurY = 0, int CurX = 0 ); 154 | 155 | /*! 156 | * \brief Used to fill the Verts vector and Texcoords vector with the proper geometry information to store in a buffer object 157 | * 158 | * \param text A string that represents the text data to be stored in the vectors 159 | * \param Verts A reference to a vector of floats to be filled with 2D vertex data 160 | * \param Texcoords A reference to a vector of floats to be filled with texture coordinate data 161 | * \param CurY the Y location in pixels to draw the new text 162 | * \param CurX the X location in pixels to draw the new text 163 | * 164 | * \return void 165 | */ 166 | void textListFill( std::string text, std::vector &Verts, std::vector &Texcoords , int CurY = 0 , int CurX = 0 ); 167 | 168 | }; 169 | 170 | } 171 | 172 | #endif -------------------------------------------------------------------------------- /SDL2-GUI/UniformVar.h: -------------------------------------------------------------------------------- 1 | #ifndef GLSL_UNIFORM_VARIABLE 2 | #define GLSL_UNIFORM_VARIABLE 3 | 4 | #include 5 | #include 6 | 7 | class Uniform { 8 | private: 9 | 10 | public: 11 | Uniform( void ){} 12 | virtual ~Uniform( void ); 13 | 14 | virtual void loadUniform( GLuint program ) = 0; 15 | 16 | }; 17 | 18 | 19 | class UniformVec3 : public Uniform { 20 | 21 | private: 22 | glm::vec3 m_data; 23 | char* m_name; 24 | 25 | public: 26 | 27 | UniformVec3( void ) {}; 28 | UniformVec3( char* name ) : m_name( name ) {} 29 | UniformVec3( char* name , glm::vec3 data ) : m_name( name ) , m_data( data ) {} 30 | ~UniformVec3( void ) {}; 31 | 32 | 33 | void setData( glm::vec3 data ) { 34 | m_data = data; 35 | } 36 | 37 | glm::vec3 getData( void ) { 38 | return m_data; 39 | } 40 | 41 | void loadUniform( GLuint program ) { 42 | 43 | GLuint location = glGetUniformLocation( program, (const char*) m_name ); 44 | 45 | if( location >= 0 ){ 46 | glUniform3f( location, m_data.x, m_data.y , m_data.z ); 47 | } 48 | 49 | } 50 | 51 | }; 52 | 53 | class UniformVec4 : public Uniform { 54 | 55 | private: 56 | glm::vec4 m_data; 57 | unsigned char* m_name; 58 | public: 59 | UniformVec4( void ) {}; 60 | UniformVec4( unsigned char* name ) : m_name( name ) {} 61 | UniformVec4( unsigned char* name , glm::vec4 data ) : m_name( name ) , m_data( data ) {} 62 | ~UniformVec4( void ) {} 63 | 64 | 65 | void setData( glm::vec4 data ) { 66 | m_data = data; 67 | } 68 | 69 | glm::vec4 getData( void ) { 70 | return m_data; 71 | } 72 | 73 | void loadUniform( GLuint program ) { 74 | 75 | GLuint location = glGetUniformLocation( program, (const char*) m_name ); 76 | 77 | if( location >= 0 ){ 78 | glUniform4f( location, m_data.x, m_data.y , m_data.z , m_data.w ); 79 | } 80 | 81 | } 82 | 83 | 84 | }; 85 | 86 | class UniformVec2 : public Uniform { 87 | 88 | private: 89 | glm::vec2 m_data; 90 | unsigned char* m_name; 91 | 92 | public: 93 | UniformVec2( void ) {}; 94 | UniformVec2( unsigned char* name ) : m_name( name ) {} 95 | UniformVec2( unsigned char* name , glm::vec2 data ) : m_name( name ) , m_data( data ) {} 96 | ~UniformVec2( void ) {}; 97 | 98 | 99 | void setData( glm::vec2 data ) { 100 | m_data = data; 101 | } 102 | 103 | glm::vec2 getData( void ) { 104 | return m_data; 105 | } 106 | 107 | void loadUniform( GLuint program ) { 108 | 109 | GLuint location = glGetUniformLocation( program, (const char*) m_name ); 110 | 111 | if( location >= 0 ){ 112 | glUniform2f( location, m_data.x, m_data.y ); 113 | } 114 | } 115 | 116 | 117 | }; 118 | 119 | class UniformMat4 : public Uniform { 120 | 121 | private: 122 | glm::mat4 m_data; 123 | unsigned char* m_name; 124 | 125 | public: 126 | UniformMat4( void ) {}; 127 | UniformMat4( unsigned char* name ) : m_name( name ) {} 128 | UniformMat4( unsigned char* name , glm::mat4 data ) : m_name( name ) , m_data( data ) {} 129 | ~UniformMat4( void ) {}; 130 | 131 | 132 | void setData( glm::mat4 data ) { 133 | m_data = data; 134 | } 135 | 136 | glm::mat4 getData( void ) { 137 | return m_data; 138 | } 139 | 140 | void loadUniform( GLuint program ) { 141 | 142 | GLuint location = glGetUniformLocation( program, (const char*) m_name ); 143 | 144 | if( location >= 0 ){ 145 | glUniformMatrix4fv(location, 1, GL_FALSE, &m_data[0][0]); 146 | } 147 | } 148 | 149 | }; 150 | 151 | class UniformMat3 : public Uniform { 152 | 153 | private: 154 | glm::mat3 m_data; 155 | unsigned char* m_name; 156 | 157 | public: 158 | UniformMat3( void ) {}; 159 | UniformMat3( unsigned char* name ) : m_name( name ) {} 160 | UniformMat3( unsigned char* name , glm::mat3 data ) : m_name( name ) , m_data( data ) {} 161 | ~UniformMat3( void ) {}; 162 | 163 | 164 | void setData( glm::mat3 data ) { 165 | m_data = data; 166 | } 167 | 168 | glm::mat3 getData( void ) { 169 | return m_data; 170 | } 171 | 172 | void loadUniform( GLuint program ) { 173 | 174 | GLuint location = glGetUniformLocation( program, (const char*) m_name ); 175 | 176 | if( location >= 0 ){ 177 | glUniformMatrix3fv(location, 1, GL_FALSE, &m_data[0][0]); 178 | } 179 | } 180 | 181 | 182 | }; 183 | 184 | class UniformFloat : public Uniform { 185 | 186 | private: 187 | float m_data; 188 | unsigned char* m_name; 189 | 190 | public: 191 | UniformFloat( void ) {}; 192 | UniformFloat( unsigned char* name ) : m_name( name ) {} 193 | UniformFloat( unsigned char* name , float data ) : m_name( name ) , m_data( data ) {} 194 | ~UniformFloat( void ) {}; 195 | 196 | 197 | void setData( float data ) { 198 | m_data = data; 199 | } 200 | 201 | float getData( void ) { 202 | return m_data; 203 | } 204 | 205 | void loadUniform( GLuint program ) { 206 | 207 | GLuint location = glGetUniformLocation( program, (const char*) m_name ); 208 | 209 | if( location >= 0 ){ 210 | glUniform1f(location, m_data); 211 | } 212 | } 213 | 214 | }; 215 | 216 | class UniformInt : public Uniform { 217 | 218 | private: 219 | int m_data; 220 | unsigned char* m_name; 221 | 222 | public: 223 | UniformInt( void ) {}; 224 | UniformInt( unsigned char* name ) : m_name( name ) {} 225 | UniformInt( unsigned char* name , int data ) : m_name( name ) , m_data( data ) {} 226 | ~UniformInt( void ) {}; 227 | 228 | 229 | void setData( int data ) { 230 | m_data = data; 231 | } 232 | 233 | int getData( void ) { 234 | return m_data; 235 | } 236 | 237 | void loadUniform( GLuint program ) { 238 | 239 | GLuint location = glGetUniformLocation( program, (const char*) m_name ); 240 | 241 | if( location >= 0 ){ 242 | glUniform1i(location, m_data); 243 | } 244 | } 245 | 246 | }; 247 | 248 | class UniformBool : public Uniform { 249 | 250 | private: 251 | bool m_data; 252 | unsigned char* m_name; 253 | 254 | public: 255 | UniformBool( void ) {}; 256 | UniformBool( unsigned char* name ) : m_name( name ) {} 257 | UniformBool( unsigned char* name , bool data ) : m_name( name ) , m_data( data ) {} 258 | ~UniformBool( void ) {}; 259 | 260 | 261 | void setData( bool data ) { 262 | m_data = data; 263 | } 264 | 265 | bool getData( void ) { 266 | return m_data; 267 | } 268 | 269 | void loadUniform( GLuint program ) { 270 | 271 | GLuint location = glGetUniformLocation( program, (const char*) m_name ); 272 | 273 | if( location >= 0 ){ 274 | glUniform1i(location, m_data); 275 | } 276 | } 277 | 278 | }; 279 | 280 | #endif -------------------------------------------------------------------------------- /SDL2-GUI/VertAttribLoading.cpp: -------------------------------------------------------------------------------- 1 | #include "VertAttribLoading.h" 2 | #include // C importer 3 | #include // various extra operations 4 | #include 5 | 6 | void LoadVertexNormalAttribute( const aiScene* scene , GLuint* vBuffer ) { 7 | std::vector g_vn; 8 | 9 | int g_point_count = 0; 10 | 11 | for (unsigned int m_i = 0; m_i < scene->mNumMeshes; m_i++) { 12 | 13 | const aiMesh* mesh = scene->mMeshes[m_i]; 14 | printf (" %i vertices in mesh\n", mesh->mNumVertices); 15 | g_point_count = mesh->mNumVertices; 16 | 17 | for (unsigned int v_i = 0; v_i < mesh->mNumVertices; v_i++) { 18 | 19 | if ( mesh->HasNormals() ) { 20 | const aiVector3D* vn = &(mesh->mNormals[v_i]); 21 | //printf (" vn %i (%f,%f,%f)\n", v_i, vn->x, vn->y, vn->z); 22 | g_vn.push_back (vn->x); 23 | g_vn.push_back (vn->y); 24 | g_vn.push_back (vn->z); 25 | } 26 | 27 | } 28 | 29 | } 30 | 31 | 32 | 33 | glGenBuffers( 1, vBuffer ); 34 | glBindBuffer( GL_ARRAY_BUFFER, *vBuffer ); 35 | glBufferData( GL_ARRAY_BUFFER, g_point_count * 3 * sizeof (float), &g_vn[0], GL_STATIC_DRAW ); 36 | glVertexAttribPointer( 1, 3, GL_FLOAT, GL_FALSE, 0, 0 ); 37 | 38 | glBindBuffer( GL_ARRAY_BUFFER, 0 ); 39 | } 40 | 41 | void LoadVertexColorAttribute( const aiScene* scene , GLuint* vBuffer ) { 42 | std::vector g_vn; 43 | 44 | int g_point_count = 0; 45 | 46 | for (unsigned int m_i = 0; m_i < scene->mNumMeshes; m_i++) { 47 | 48 | const aiMesh* mesh = scene->mMeshes[m_i]; 49 | printf (" %i vertices in mesh\n", mesh->mNumVertices); 50 | g_point_count = mesh->mNumVertices; 51 | 52 | for (unsigned int v_i = 0; v_i < mesh->mNumVertices; v_i++) { 53 | 54 | if ( mesh->HasNormals() ) { 55 | const aiVector3D* vn = &(mesh->mNormals[v_i]); 56 | //printf (" vn %i (%f,%f,%f)\n", v_i, vn->x, vn->y, vn->z); 57 | g_vn.push_back (vn->x); 58 | g_vn.push_back (vn->y); 59 | g_vn.push_back (vn->z); 60 | } 61 | 62 | } 63 | 64 | } 65 | 66 | 67 | 68 | glGenBuffers( 1, vBuffer ); 69 | glBindBuffer( GL_ARRAY_BUFFER, *vBuffer ); 70 | glBufferData( GL_ARRAY_BUFFER, g_point_count * 3 * sizeof (float), &g_vn[0], GL_STATIC_DRAW ); 71 | glVertexAttribPointer( 5, 3, GL_FLOAT, GL_FALSE, 0, 0 ); 72 | 73 | glBindBuffer( GL_ARRAY_BUFFER, 0 ); 74 | } 75 | 76 | void LoadVertexTangentAttribute( const aiScene* scene , GLuint* vBuffer ) { 77 | std::vector g_vn; 78 | 79 | int g_point_count = 0; 80 | 81 | for (unsigned int m_i = 0; m_i < scene->mNumMeshes; m_i++) { 82 | 83 | const aiMesh* mesh = scene->mMeshes[m_i]; 84 | printf (" %i vertices in mesh\n", mesh->mNumVertices); 85 | g_point_count = mesh->mNumVertices; 86 | 87 | for (unsigned int v_i = 0; v_i < mesh->mNumVertices; v_i++) { 88 | 89 | if ( mesh->HasTangentsAndBitangents() ) { 90 | const aiVector3D* vn = &(mesh->mTangents[0]); 91 | //printf (" vn %i (%f,%f,%f)\n", v_i, vn->x, vn->y, vn->z); 92 | g_vn.push_back (vn->x); 93 | g_vn.push_back (vn->y); 94 | g_vn.push_back (vn->z); 95 | } 96 | 97 | } 98 | 99 | } 100 | 101 | 102 | 103 | glGenBuffers( 1, vBuffer ); 104 | glBindBuffer( GL_ARRAY_BUFFER, *vBuffer ); 105 | glBufferData( GL_ARRAY_BUFFER, g_point_count * 3 * sizeof (float), &g_vn[0], GL_STATIC_DRAW ); 106 | glVertexAttribPointer( 3, 3, GL_FLOAT, GL_FALSE, 0, 0 ); 107 | 108 | glBindBuffer( GL_ARRAY_BUFFER, 0 ); 109 | } 110 | 111 | void LoadVertexBiTangentAttribute( const aiScene* scene , GLuint* vBuffer ) { 112 | std::vector g_vn; 113 | 114 | int g_point_count = 0; 115 | 116 | for (unsigned int m_i = 0; m_i < scene->mNumMeshes; m_i++) { 117 | 118 | const aiMesh* mesh = scene->mMeshes[m_i]; 119 | printf (" %i vertices in mesh\n", mesh->mNumVertices); 120 | g_point_count = mesh->mNumVertices; 121 | 122 | for (unsigned int v_i = 0; v_i < mesh->mNumVertices; v_i++) { 123 | 124 | if ( mesh->HasTangentsAndBitangents() ) { 125 | const aiVector3D* vn = &(mesh->mBitangents[0]); 126 | //printf (" vn %i (%f,%f,%f)\n", v_i, vn->x, vn->y, vn->z); 127 | g_vn.push_back (vn->x); 128 | g_vn.push_back (vn->y); 129 | g_vn.push_back (vn->z); 130 | } 131 | 132 | } 133 | 134 | } 135 | 136 | 137 | glGenBuffers( 1, vBuffer ); 138 | glBindBuffer( GL_ARRAY_BUFFER, *vBuffer ); 139 | glBufferData( GL_ARRAY_BUFFER, g_point_count * 3 * sizeof (float), &g_vn[0], GL_STATIC_DRAW ); 140 | glVertexAttribPointer( 4, 3, GL_FLOAT, GL_FALSE, 0, 0 ); 141 | 142 | glBindBuffer( GL_ARRAY_BUFFER, 0 ); 143 | } 144 | 145 | void LoadVertexPositionAttribute( const aiScene* scene , GLuint* vBuffer ) { 146 | 147 | std::vector g_vp; 148 | 149 | int g_point_count = 0; 150 | 151 | for (unsigned int m_i = 0; m_i < scene->mNumMeshes; m_i++) { 152 | 153 | const aiMesh* mesh = scene->mMeshes[m_i]; 154 | printf (" %i vertices in mesh\n", mesh->mNumVertices); 155 | g_point_count = mesh->mNumVertices; 156 | 157 | for (unsigned int v_i = 0; v_i < mesh->mNumVertices; v_i++) { 158 | 159 | if ( mesh->HasPositions () ) { 160 | const aiVector3D* vp = &(mesh->mVertices[v_i]); 161 | //printf (" vp %i (%f,%f,%f)\n", v_i, vp->x, vp->y, vp->z); 162 | g_vp.push_back (vp->x); 163 | g_vp.push_back (vp->y); 164 | g_vp.push_back (vp->z); 165 | } 166 | 167 | } 168 | 169 | } 170 | 171 | 172 | glGenBuffers( 1, vBuffer ); 173 | glBindBuffer( GL_ARRAY_BUFFER, *vBuffer ); 174 | glBufferData( GL_ARRAY_BUFFER, g_point_count * 3 * sizeof (float), &g_vp[0], GL_STATIC_DRAW ); 175 | glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 0, 0 ); 176 | 177 | 178 | glBindBuffer( GL_ARRAY_BUFFER, 0 ); 179 | 180 | } 181 | 182 | void LoadVertexTexCoordAttribute( const aiScene* scene , GLuint* vBuffer ) { 183 | 184 | std::vector g_vt; 185 | 186 | int g_point_count = 0; 187 | 188 | 189 | for (unsigned int m_i = 0; m_i < scene->mNumMeshes; m_i++) { 190 | 191 | const aiMesh* mesh = scene->mMeshes[m_i]; 192 | printf (" %i vertices in mesh\n", mesh->mNumVertices); 193 | g_point_count = mesh->mNumVertices; 194 | 195 | for (unsigned int v_i = 0; v_i < mesh->mNumVertices; v_i++) { 196 | 197 | if (mesh->HasTextureCoords (0)) { 198 | const aiVector3D* vt = &(mesh->mTextureCoords[0][v_i]); 199 | //printf (" vt %i (%f,%f)\n", v_i, vt->x, vt->y); 200 | g_vt.push_back (vt->x); 201 | g_vt.push_back (vt->y); 202 | } 203 | 204 | } 205 | 206 | } 207 | 208 | 209 | glGenBuffers( 1, vBuffer ); 210 | glBindBuffer( GL_ARRAY_BUFFER, *vBuffer ); 211 | glBufferData( GL_ARRAY_BUFFER, g_point_count * 2 * sizeof (float), &g_vt[0], GL_STATIC_DRAW ); 212 | glVertexAttribPointer( 2, 2, GL_FLOAT, GL_FALSE, 0, 0 ); 213 | 214 | glBindBuffer( GL_ARRAY_BUFFER, 0 ); 215 | } -------------------------------------------------------------------------------- /SDL2-GUI/MaterialFactory.cpp: -------------------------------------------------------------------------------- 1 | #include"MaterialFactory.h" 2 | 3 | 4 | MaterialFactory::MaterialFactory( void ) { 5 | m_textureLocation = GL_TEXTURE0; 6 | } 7 | 8 | MaterialFactory::~MaterialFactory( void ) {} 9 | 10 | std::shared_ptr< Mesh > MaterialFactory::createMesh( const char* meshXml ) { 11 | 12 | std::shared_ptr< Mesh > mesh = std::shared_ptr< Mesh >( new Mesh() ); 13 | m_material = std::shared_ptr< GLSLMaterial >( new GLSLMaterial() ); 14 | 15 | m_doc = new tinyxml2::XMLDocument(); 16 | 17 | if( m_doc->LoadFile( meshXml ) ) { 18 | printf("loading xml file error"); 19 | return NULL; 20 | } 21 | 22 | tinyxml2::XMLNode* child = m_doc->FirstChild(); 23 | 24 | const char* meshFile = child->ToElement()->Attribute( "file" ); 25 | 26 | int g_point_count = 0; 27 | GLuint vao; 28 | 29 | const aiScene* scene = aiImportFile (meshFile, aiProcess_Triangulate); // TRIANGLES! 30 | 31 | if (!scene) { 32 | fprintf (stderr, "ERROR: reading mesh %s\n", meshFile); 33 | return false; 34 | } 35 | 36 | glGenVertexArrays( 1, &vao ); 37 | glBindVertexArray( vao ); 38 | 39 | mesh->setVAO( vao ); 40 | 41 | g_point_count = scene->mMeshes[0]->mNumVertices; 42 | 43 | mesh->setSize( g_point_count ); 44 | 45 | 46 | for( tinyxml2::XMLElement* loopNode =child->FirstChildElement(); loopNode != NULL; loopNode=loopNode->NextSiblingElement() ) { 47 | 48 | if( strcmp( loopNode->Name() , "Material" ) == 0 ) { 49 | 50 | mesh->setMaterial( createMaterial( loopNode, scene ) ); 51 | 52 | } 53 | 54 | } 55 | 56 | aiReleaseImport( scene ); 57 | 58 | glBindVertexArray( 0 ); 59 | 60 | m_textureLocation = GL_TEXTURE0; 61 | 62 | return mesh; 63 | 64 | } 65 | 66 | std::shared_ptr< GLSLMaterial > MaterialFactory::createMaterial( tinyxml2::XMLElement* node , const aiScene* scene ) { 67 | 68 | std::shared_ptr< GLSLMaterial > myMaterial = std::shared_ptr< GLSLMaterial > ( new GLSLMaterial() ); 69 | 70 | for( tinyxml2::XMLElement* loopNode = node->FirstChildElement(); loopNode != NULL; loopNode=loopNode->NextSiblingElement() ) { 71 | 72 | if( strcmp( loopNode->Name() , "vertex_attribute" ) == 0 ) { 73 | 74 | myMaterial->addVertexAttribute( createVertexAttribute( loopNode , scene ) ); 75 | 76 | } 77 | else if( strcmp( loopNode->Name() , "program" ) == 0 ) { 78 | 79 | myMaterial->setProgram( createProgram( loopNode , myMaterial ) ); 80 | 81 | } 82 | 83 | } 84 | 85 | return myMaterial; 86 | 87 | } 88 | 89 | std::shared_ptr< VertexAttrib > MaterialFactory::createVertexAttribute( tinyxml2::XMLElement* node , const aiScene* scene ) { 90 | 91 | std::shared_ptr< VertexAttrib > vertA = std::shared_ptr< VertexAttrib >( new VertexAttrib() ); 92 | 93 | m_material->addVertexAttribute( vertA ); 94 | 95 | GLuint vertBuffer; 96 | 97 | const char* type = node->Attribute( "type" ); 98 | 99 | if( strcmp( type , "position" ) == 0 ) { 100 | LoadVertexPositionAttribute( scene , &vertBuffer ); 101 | vertA->setVBO( vertBuffer ); 102 | vertA->setName( node->Attribute( "name" ) ); 103 | } 104 | 105 | if( strcmp( type , "normal" ) == 0 ) { 106 | LoadVertexNormalAttribute( scene , &vertBuffer ); 107 | vertA->setVBO( vertBuffer ); 108 | vertA->setName( node->Attribute( "name" ) ); 109 | } 110 | 111 | if( strcmp( type , "texture_coordinate" ) == 0 ) { 112 | LoadVertexTexCoordAttribute( scene , &vertBuffer ); 113 | vertA->setVBO( vertBuffer ); 114 | vertA->setName( node->Attribute( "name" ) ); 115 | } 116 | 117 | if( strcmp( type , "tangent" ) == 0 ) { 118 | LoadVertexTangentAttribute( scene , &vertBuffer ); 119 | vertA->setVBO( vertBuffer ); 120 | vertA->setName( node->Attribute( "name" ) ); 121 | } 122 | 123 | if( strcmp( type , "bitangent" ) == 0 ) { 124 | LoadVertexBiTangentAttribute( scene , &vertBuffer ); 125 | vertA->setVBO( vertBuffer ); 126 | vertA->setName( node->Attribute( "name" ) ); 127 | } 128 | 129 | return vertA; 130 | } 131 | 132 | std::shared_ptr< Uniform > MaterialFactory::createUniform( tinyxml2::XMLElement* node ) { 133 | return NULL; 134 | } 135 | 136 | std::shared_ptr< Texture > MaterialFactory::createTexture( tinyxml2::XMLElement* node ) { 137 | 138 | std::shared_ptr< Texture > myTexture = std::shared_ptr< Texture > ( new Texture() ); 139 | 140 | GLuint textureId = loadTexture( node->Attribute( "file" ) ); 141 | 142 | myTexture->setTexture( node->Attribute( "name" ) , textureId , m_textureLocation ); 143 | 144 | printf( " Loaded texture2D - \n "); 145 | printf( " name: %s \n" , node->Attribute( "name" ) ); 146 | printf( " file: %s \n" , node->Attribute( "file" ) ); 147 | printf( " textureId: %i \n" , textureId ); 148 | printf( " textureLocation: %i \n", m_textureLocation ); 149 | 150 | m_textureLocation++; 151 | 152 | return myTexture; 153 | 154 | } 155 | 156 | std::shared_ptr< Texture > MaterialFactory::createCubeMap( tinyxml2::XMLElement* node ) { 157 | 158 | std::shared_ptr< Texture > myTexture = std::shared_ptr< Texture > ( new CubeMap() ); 159 | 160 | GLuint textureId; 161 | 162 | loadCubeMap( node->Attribute( "front" ) , node->Attribute( "back" ) , node->Attribute( "top" ) , 163 | node->Attribute( "bottom" ) , node->Attribute( "left" ) , node->Attribute( "right" ) , &textureId ); 164 | 165 | myTexture->setTexture( node->Attribute( "name" ) , textureId , m_textureLocation ); 166 | 167 | printf( " Loaded cubeMap - \n "); 168 | printf( " name: %s \n" , node->Attribute( "name" ) ); 169 | printf( " textureId: %i \n" , textureId ); 170 | printf( " textureLocation: %i \n", m_textureLocation ); 171 | 172 | m_textureLocation++; 173 | 174 | return myTexture; 175 | 176 | } 177 | 178 | std::shared_ptr< GLSLProgram > MaterialFactory::createProgram( tinyxml2::XMLElement* node , std::shared_ptr< GLSLMaterial > material ) { 179 | 180 | std::shared_ptr< GLSLProgram > program = std::shared_ptr< GLSLProgram > ( new GLSLProgram() ); 181 | const char* vertexShaderFile; 182 | const char* fragmentShaderFile; 183 | 184 | for( tinyxml2::XMLElement* loopNode = node->FirstChildElement(); loopNode != NULL; loopNode=loopNode->NextSiblingElement() ) { 185 | 186 | if( strcmp( loopNode->Name() , "vertex_shader" ) == 0 ) { 187 | vertexShaderFile = loopNode->Attribute( "source" ); 188 | } 189 | else if ( strcmp( loopNode->Name() , "fragment_shader" ) == 0 ) { 190 | fragmentShaderFile = loopNode->Attribute( "source" ); 191 | } 192 | else if ( strcmp( loopNode->Name() , "texture2D" ) == 0 ) { 193 | material->addTexture( createTexture( loopNode ) ); 194 | } 195 | else if ( strcmp( loopNode->Name() , "cubeMap" ) == 0 ) { 196 | material->addTexture( this->createCubeMap( loopNode ) ); 197 | } 198 | 199 | } 200 | 201 | program->compileShaderFromFile( vertexShaderFile , GLSLShader::VERTEX ); 202 | program->compileShaderFromFile( fragmentShaderFile, GLSLShader::FRAGMENT ); 203 | 204 | program->link(); 205 | 206 | return program; 207 | 208 | } 209 | -------------------------------------------------------------------------------- /SDL2-GUI/GUIView.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \class GUIView 3 | * 4 | * \ingroup SDL2-GUI 5 | * 6 | * \brief Handles all rendering in SDL2-GUI 7 | * 8 | * This class holds shaders and rendering data so that 9 | * elements can make draw calls and only reference a 10 | * single object. 11 | * 12 | * 13 | * \note Should be used for all rendering. 14 | * 15 | * \author Lee Jacobs 16 | * 17 | * \version 1.0 18 | * 19 | * \date 2014/06/10 20 | * 21 | * Contact: leemichaeljacobs@gmail.com 22 | * 23 | * Created on: 2014/05/28 24 | * 25 | * $Id: doxygen-howto.html,v 1.5 2005/04/14 14:16:20 bv Exp $ 26 | * 27 | */ 28 | 29 | #ifndef GUIVIEW 30 | #define GUIVIEW 31 | 32 | #include "GLSLShader.h" 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include"GUIFont.h" 40 | 41 | namespace SDLGUI { 42 | 43 | //quad surface to render texture over 44 | struct ElementSurface { 45 | 46 | float verts[12]; 47 | 48 | float texture_coords[12]; 49 | 50 | ElementSurface() { 51 | verts[0] = -1.0; 52 | verts[1] = 1.0; 53 | verts[2] = -1.0; 54 | verts[3] = -1.0; 55 | verts[4] = 1.0; 56 | verts[5] = -1.0; 57 | verts[6] = 1.0; 58 | verts[7] = -1.0; 59 | verts[8] = 1.0; 60 | verts[9] = 1.0; 61 | verts[10] = -1.0; 62 | verts[11] = 1.0; 63 | 64 | texture_coords[0] = 0.0; 65 | texture_coords[1] = 1.0; 66 | texture_coords[2] = 0.0; 67 | texture_coords[3] = 0.0; 68 | texture_coords[4] = 1.0; 69 | texture_coords[5] = 0.0; 70 | texture_coords[6] = 1.0; 71 | texture_coords[7] = 0.0; 72 | texture_coords[8] = 1.0; 73 | texture_coords[9] = 1.0; 74 | texture_coords[10] = 0.0; 75 | texture_coords[11] = 1.0; 76 | }; 77 | 78 | }; 79 | 80 | class GUIView { 81 | 82 | private: 83 | GLuint m_vao; 84 | GLuint m_vbo; 85 | GLuint m_vbot; 86 | std::shared_ptr m_program; 87 | ElementSurface m_surface; //Surface we are rendering to 88 | GLuint m_errorTexture; //red texture for error checking 89 | std::shared_ptr m_font; 90 | 91 | public: 92 | 93 | GUIView( std::shared_ptr program ); 94 | virtual ~GUIView(); 95 | 96 | /*! 97 | * \brief renders a texture at the given position with the given scale 98 | * 99 | * \param texture A GLuint that is handle to a texture in GPU memory 100 | * \param position A GLM::Vec2 representing the upper left hand position of the panel 101 | * \param scale A GLM::Vec2 representing the width and height scale of the panel 102 | * 103 | * \return void 104 | */ 105 | void renderPanel( GLuint texture, glm::vec2 position, glm::vec2 scale ); 106 | 107 | /*! 108 | * \brief renders a texture at the given postion with the given scale and provides 109 | * the subroutine handle to be used by the panel shader. 110 | * 111 | * \param texture A GLuint that is handle to a texture in GPU memory 112 | * \param position A GLM::Vec2 representing the upper left hand position of the panel 113 | * \param scale A GLM::Vec2 representing the width and height scale of the panel 114 | * \param subroutine A handle to the subroutine for the panels shader 115 | * 116 | * \return void 117 | */ 118 | void renderPanel( GLuint texture, glm::vec2 position, glm::vec2 scale, int subroutine ); 119 | 120 | /*! 121 | * \brief renders the given Vertex array object using the text rendering shader 122 | * 123 | * \param textVAO A vertex array object that is a handle to text information on the GPU 124 | * \param pos_x The x position to render at 125 | * \param pos_y the y position to render at 126 | * \param size The size that our text should be when rendering 127 | * \param numChars The number of characters that our text string has 128 | * 129 | * \return void 130 | */ 131 | void renderText( GLuint textVAO, float pos_x, float pos_y, int size, int numChars ); 132 | 133 | /*! 134 | * \brief render a panel at the scale of the original panel, error rendering can be turned on through the GUIManager 135 | * 136 | * \param position A GLM::Vec2 that represents the position to render the error at 137 | * \param scale A GLM::Vec2 that represents the width and height to render the error with 138 | * 139 | * \return void 140 | */ 141 | void renderError( glm::vec2 position, glm::vec2 scale ); 142 | 143 | /*! 144 | * \brief sets up the view to render a panel using the panel shader and geometry 145 | * 146 | * \return void 147 | */ 148 | void prepareRenderer(); 149 | 150 | /*! 151 | * \brief returns the Opengl state to using the default shader 152 | * 153 | * \return void 154 | */ 155 | void cleanRenderer(); 156 | 157 | /*! 158 | * \brief Store text on the GPU to be rendered later 159 | * 160 | * \param text The string of text to be stored 161 | * \param vertVBO The VBO to hold the text vertex data 162 | * \param texcoordVBO The VBO to hold the text texturecoord data 163 | * \param textVAO The VAO to hold the handle to the vertex data on the GPU 164 | * 165 | * \return void 166 | */ 167 | void cacheText( std::string text , GLuint vertVBO, GLuint texcoordVBO, GLuint textVAO ){ 168 | m_font->cacheText(text, vertVBO, texcoordVBO, textVAO); 169 | } 170 | 171 | /*! 172 | * \brief Store text on the GPU to be rendered in a multiLine format 173 | * 174 | * \param text The string of text to be stored 175 | * \param vertVBO The VBO to hold the text vertex data 176 | * \param texcoordVBO The VBO to hold the text texturecoord data 177 | * \param textVAO The VAO to hold the handle to the vertex data on the GPU 178 | * \param width The width of the box to render the text in 179 | * 180 | * \return 181 | */ 182 | void cacheTextWrap( std::string text , GLuint vertVBO, GLuint texcoordVBO, GLuint textVAO , int width ) { 183 | m_font->cacheTextWrap( text, vertVBO, texcoordVBO, textVAO, width ); 184 | } 185 | 186 | /*! 187 | * \brief update current text with more text or remove text at the updateLocation onward 188 | * 189 | * \param text The string of text to be stored 190 | * \param vertVBO The VBO to hold the text vertex data 191 | * \param texcoordVBO The VBO to hold the text texturecoord data 192 | * \param textVAO The VAO to hold the handle to the vertex data on the GPU 193 | * \param updateLocation The text location to update the current text at 194 | * 195 | * \return void 196 | */ 197 | void updateCachedText( std::string text, GLuint vertVBO, GLuint texcoordVBO, GLuint textVAO, int updateLocation ){ 198 | m_font->updateCacheText(text, vertVBO, texcoordVBO, textVAO, updateLocation, 0 ); 199 | } 200 | 201 | /*! 202 | * \brief assign a texture to errors 203 | * 204 | * \param texture The texture handle for error textures 205 | * 206 | * \return void 207 | */ 208 | void assignErrorTexture( GLuint texture ){ 209 | m_errorTexture = texture; 210 | } 211 | 212 | /*! 213 | * \brief assign a font to the view 214 | * 215 | * \param font A GUIFont pointer that references an object 216 | * 217 | * \return void 218 | */ 219 | void assignFont( std::shared_ptr font ){ 220 | m_font = font; 221 | } 222 | 223 | 224 | }; 225 | 226 | } 227 | 228 | #endif -------------------------------------------------------------------------------- /SDL2-GUI/Element.h: -------------------------------------------------------------------------------- 1 | /// \defgroup SDL2-GUI 2 | /** 3 | * \class Element 4 | * 5 | * \ingroup SDL2-GUI 6 | * 7 | * \brief Base class for all HTML elements 8 | * 9 | * This class is the base class for all HTML Elements. 10 | * Elements build a tree by have a list of children. 11 | * Each element draw call must also draw its children. 12 | * 13 | * 14 | * \note All elements must derive from this class 15 | * 16 | * \author Lee Jacobs 17 | * 18 | * \version 1.0 19 | * 20 | * \date 2014/06/10 21 | * 22 | * Contact: leemichaeljacobs@gmail.com 23 | * 24 | * Created on: 2014/05/28 25 | * 26 | * $Id: doxygen-howto.html,v 1.5 2005/04/14 14:16:20 bv Exp $ 27 | * 28 | */ 29 | 30 | #ifndef SDLGUIELEMENT 31 | #define SDLGUIELEMENT 32 | #include 33 | #include 34 | #include "GUIEvent.h" 35 | #include "GUIBound.h" 36 | #include "GUIView.h" 37 | #include 38 | #include 39 | #include 40 | 41 | namespace SDLGUI { 42 | 43 | enum { 44 | LEFT = 0, 45 | RIGHT, 46 | TOP, 47 | BOTTOM, 48 | CENTER, 49 | CENTER_LEFT, 50 | CENTER_RIGHT, 51 | CENTER_TOP, 52 | CENTER_BOTTOM 53 | }; 54 | 55 | //This BoxModel represents HTML CSS box model formatting 56 | struct BoxModel { 57 | glm::vec4 margin; 58 | glm::vec4 border; 59 | glm::vec4 padding; 60 | glm::vec4 content; 61 | }; 62 | 63 | 64 | class Element { 65 | 66 | protected: 67 | 68 | std::shared_ptr m_parent; /*!< The parent Element to this Element */ 69 | std::shared_ptr m_view; /*!< A view object to render this Element */ 70 | std::shared_ptr m_boundary; //a boundary to test hits on 71 | GLuint m_elementVAO; 72 | GLuint m_textVAO; /*!< Vertex Array Object to handle Text geometry and UV-Coords */ 73 | GLuint m_textVBOVerts; /*!< Vertex Buffer Object to hold text vertex data */ 74 | GLuint m_textVBOTexCoords; /*!< Vertex Buffer Object to hold text UV-coord data */ 75 | glm::vec2 m_pos; 76 | glm::vec2 m_screenPos; 77 | glm::vec2 m_scale; 78 | glm::vec4 m_stencilRect; /*!< A rectangle used to define where to draw elements */ 79 | std::string m_text; 80 | float m_width; 81 | float m_height; 82 | unsigned int m_textChars; //number of characters in this elements text 83 | unsigned int m_layer; //layer to draw Element on 84 | std::vector< std::shared_ptr > m_children; //every element can have children 85 | 86 | public: 87 | 88 | /*! 89 | * \brief builds an Elment with empty or zero intial conditions 90 | */ 91 | Element():m_pos(glm::vec2(0.0,0.0)),m_screenPos(glm::vec2(0.0,0.0)), m_scale(glm::vec2(1.0,1.0)), 92 | m_stencilRect(glm::vec4(1.0)), m_text(""), m_width(0), m_height(0),m_textChars(0), m_parent(NULL), 93 | m_view(NULL), m_layer(0) { 94 | 95 | glGenVertexArrays(1, &m_textVAO); 96 | glGenBuffers( 1, &m_textVBOVerts); 97 | glGenBuffers( 1, &m_textVBOTexCoords); 98 | } 99 | 100 | /*! 101 | * \brief Deletes all pointers and children elements of this element 102 | */ 103 | virtual ~Element(); 104 | 105 | /*! 106 | * \brief should be over ridden to draw an element properly 107 | */ 108 | virtual void draw() = 0; 109 | 110 | /*! 111 | * \brief May need to be deleted as it serves not really a purpose 112 | */ 113 | virtual void onClick() = 0; 114 | 115 | /*! 116 | * \brief Used to check whether the mouse is over the current element 117 | * 118 | * \param x The x position of the mouse 119 | * \param y The y position of the mouse 120 | * 121 | * \return True if the mouse is over the element, false otherwise. 122 | */ 123 | virtual bool isOver( int x, int y ) = 0; 124 | 125 | /*! 126 | * \brief Handles mouse motions, should be overridden 127 | * 128 | * \param ev An sdl_event that should be a mouse motion event 129 | * 130 | */ 131 | virtual void onMouseMotion( SDL_Event* ev ) = 0; 132 | 133 | /*! 134 | * \brief Handles mouse button clicked events 135 | * 136 | * \param ev An sdl_event that should be a mouse button event 137 | * \param clicked A GUIEvent reference that will be filled in when the GUIManager handles a button event 138 | */ 139 | virtual void onMouseButton( SDL_Event* ev, std::shared_ptr clicked ) = 0; 140 | 141 | /*! 142 | * \brief Handles mouse scroll event, should be overriden 143 | * 144 | * \param ev An sdl_event should be a scroll event 145 | * 146 | */ 147 | virtual void onMouseScroll( SDL_Event* ev ) {}; 148 | 149 | /*! 150 | * \brief Handles a KeyPress event, should be overriden 151 | * 152 | * \param ev An sdl_event that should be a KeyPress event 153 | * 154 | */ 155 | virtual void onKeyPress( SDL_Event* ev ) {}; 156 | 157 | /*! 158 | * \brief This function appends the child element to the children list in the current element 159 | * 160 | * \param child The child element to add to the child element list 161 | * 162 | */ 163 | virtual void addChild( std::shared_ptr child ); 164 | 165 | /*! 166 | * \brief add a bound to the element 167 | * 168 | * \param bound A GUIBound to add to the element 169 | */ 170 | virtual void addBound( std::shared_ptr bound ); 171 | 172 | /*! 173 | * \brief add a parent element to this element 174 | * 175 | * \param parent A parent element to add to this element 176 | */ 177 | virtual void addParent( std::shared_ptr parent ); 178 | 179 | 180 | /*! 181 | * \brief 182 | * 183 | * \param 184 | * 185 | * \return 186 | */ 187 | virtual void assignView( std::shared_ptr view ) { 188 | m_view = view; 189 | } 190 | 191 | /*! 192 | * \brief 193 | * 194 | * \param 195 | * 196 | * \return 197 | */ 198 | virtual unsigned int getWidth() { 199 | return m_width; 200 | } 201 | 202 | /*! 203 | * \brief 204 | * 205 | * \param 206 | * 207 | * \return 208 | */ 209 | virtual unsigned int getHeight() { 210 | return m_height; 211 | } 212 | 213 | /*! 214 | * \brief 215 | * 216 | * \param 217 | * 218 | * \return 219 | */ 220 | virtual void assignScreenPosition( float x, float y ) { 221 | m_screenPos.x = x; 222 | m_screenPos.y = y; 223 | } 224 | 225 | /*! 226 | * \brief 227 | * 228 | * \param 229 | * 230 | * \return 231 | */ 232 | void assignText( std::string text ) { 233 | m_text = text; 234 | m_view->cacheText( text, m_textVBOVerts, m_textVBOTexCoords, m_textVAO ); 235 | } 236 | 237 | /*! 238 | * \brief 239 | * 240 | * \param 241 | * 242 | * \return 243 | */ 244 | void assignNumChars( unsigned int numChars ){ 245 | m_textChars = numChars; 246 | } 247 | 248 | /*! 249 | * \brief 250 | * 251 | * \param 252 | * 253 | * \return 254 | */ 255 | void updateText( std::string text, int updateLocation ) { 256 | m_text = text; 257 | m_view->updateCachedText( text, m_textVBOVerts, m_textVBOTexCoords, m_textVAO, updateLocation ); 258 | }; 259 | 260 | /*! 261 | * \brief 262 | * 263 | * \param 264 | * 265 | * \return 266 | */ 267 | void assignTextWrap(std::string text, int width){ 268 | m_text = text; 269 | m_view->cacheTextWrap(text, m_textVBOVerts, m_textVBOTexCoords, m_textVAO, width ); 270 | } 271 | 272 | /*! 273 | * \brief 274 | * 275 | * \param 276 | * 277 | * \return 278 | */ 279 | void assignStencil( glm::vec4 stencil ) { 280 | m_stencilRect = stencil; 281 | } 282 | 283 | }; 284 | 285 | } 286 | 287 | 288 | 289 | 290 | #endif -------------------------------------------------------------------------------- /SDL2-GUI/GLSLShader.cpp: -------------------------------------------------------------------------------- 1 | #include"GLSLShader.h" 2 | 3 | GLSLProgram::GLSLProgram(){ 4 | m_handle = glCreateProgram(); 5 | printf("%i \n", m_handle); 6 | } 7 | 8 | GLSLProgram::~GLSLProgram(){ 9 | 10 | } 11 | 12 | bool GLSLProgram::compileShaderFromFile(const char* fileName, GLSLShader::GLSLShaderType type){ 13 | if( fileExists(fileName) ){ 14 | std::ifstream shaderStream (fileName); 15 | std::string shader((std::istreambuf_iterator(shaderStream)), std::istreambuf_iterator()); 16 | return compileShaderFromString(shader, type); 17 | } 18 | return false; 19 | } 20 | 21 | bool GLSLProgram::compileShaderFromString(const std::string & source, GLSLShader::GLSLShaderType type){ 22 | GLuint shader = 0; 23 | switch(type){ 24 | case(GLSLShader::VERTEX): 25 | shader = glCreateShader(GL_VERTEX_SHADER); 26 | break; 27 | case(GLSLShader::FRAGMENT): 28 | shader = glCreateShader(GL_FRAGMENT_SHADER); 29 | break; 30 | } 31 | 32 | if(shader == 0){ 33 | printf("failed to create shader"); 34 | return false; 35 | } 36 | 37 | const char *strFileData = source.c_str(); 38 | glShaderSource(shader, 1, &strFileData, NULL); 39 | 40 | glCompileShader(shader); 41 | 42 | GLint status; 43 | glGetShaderiv(shader, GL_COMPILE_STATUS, &status); 44 | if (status == GL_FALSE) 45 | { 46 | GLint infoLogLength; 47 | glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength); 48 | 49 | GLchar *strInfoLog = new GLchar[infoLogLength + 1]; 50 | glGetShaderInfoLog(shader, infoLogLength, NULL, strInfoLog); 51 | 52 | const char *strShaderType = NULL; 53 | switch(type) 54 | { 55 | case GL_VERTEX_SHADER: strShaderType = "vertex"; break; 56 | case GL_GEOMETRY_SHADER: strShaderType = "geometry"; break; 57 | case GL_FRAGMENT_SHADER: strShaderType = "fragment"; break; 58 | } 59 | 60 | fprintf(stderr, "Compile failure in %s shader:\n%s\n", strShaderType, strInfoLog); 61 | delete[] strInfoLog; 62 | return false; 63 | } 64 | 65 | glAttachShader(m_handle, shader); 66 | 67 | return true; 68 | } 69 | 70 | bool GLSLProgram::fileExists(const std::string & fileName){ 71 | std::ifstream f(fileName.c_str()); 72 | if (f.good()) { 73 | f.close(); 74 | return true; 75 | } else { 76 | f.close(); 77 | return false; 78 | } 79 | } 80 | 81 | int GLSLProgram::getUniformLocation(const char* name){ 82 | return glGetUniformLocation(m_handle, name); 83 | } 84 | 85 | bool GLSLProgram::link(){ 86 | if( m_handle == 0 ){ 87 | printf("No program initiated \n"); 88 | return false; 89 | } 90 | 91 | glLinkProgram( m_handle ); 92 | 93 | GLint status; 94 | glGetProgramiv(m_handle, GL_LINK_STATUS, &status); 95 | 96 | if( GL_FALSE == status ){ 97 | fprintf(stderr, "Failed to link shader program!\n"); 98 | GLint loglen; 99 | glGetProgramiv(m_handle, GL_INFO_LOG_LENGTH, &loglen); 100 | if( loglen > 0 ){ 101 | char* log = (char*)malloc(loglen); 102 | GLsizei written; 103 | glGetProgramInfoLog(m_handle, loglen, &written, log); 104 | fprintf(stderr, "program log: \n %s", log); 105 | free(log); 106 | return false; 107 | } 108 | } 109 | 110 | return true; 111 | } 112 | 113 | void GLSLProgram::use(){ 114 | glUseProgram( m_handle ); 115 | } 116 | 117 | int GLSLProgram::getHandle(){ 118 | return m_handle; 119 | } 120 | 121 | bool GLSLProgram::isLinked(){ 122 | GLint status; 123 | glGetProgramiv(m_handle, GL_LINK_STATUS, &status); 124 | 125 | if( GL_FALSE == status ){ 126 | return false; 127 | } 128 | 129 | return true; 130 | } 131 | 132 | void GLSLProgram::bindAttribLocation( GLuint location, const char* name){ 133 | glBindAttribLocation(m_handle, location, name); 134 | } 135 | 136 | void GLSLProgram::bindFragDataLocation(GLuint location, const char* name){ 137 | glBindFragDataLocation(m_handle, location, name); 138 | } 139 | 140 | void GLSLProgram::setUniform(const char *name, const glm::vec3 & v){ 141 | GLuint location = glGetUniformLocation(m_handle, name); 142 | 143 | if( location >= 0 ){ 144 | glUniform3f(location, v.x, v.y, v.z); 145 | } 146 | } 147 | 148 | void GLSLProgram::setUniform(const char *name, const glm::vec2 & v){ 149 | GLuint location = glGetUniformLocation(m_handle, name); 150 | 151 | if( location >= 0 ){ 152 | glUniform2f(location, v.x, v.y ); 153 | } 154 | } 155 | 156 | void GLSLProgram::setUniform(const char *name, const glm::vec4 & v){ 157 | GLuint location = glGetUniformLocation(m_handle, name); 158 | if( location >= 0 ){ 159 | glUniform4f(location, v.x, v.y, v.z, v.w); 160 | } 161 | } 162 | 163 | void GLSLProgram::setUniform(const char *name, const glm::mat4 & m){ 164 | GLuint location = glGetUniformLocation(m_handle, name); 165 | if( location >= 0 ){ 166 | glUniformMatrix4fv(location, 1, GL_FALSE, &m[0][0]); 167 | } 168 | } 169 | 170 | void GLSLProgram::setUniform(const char *name, const glm::mat3 & m){ 171 | GLuint location = glGetUniformLocation(m_handle, name); 172 | if( location >= 0 ){ 173 | glUniformMatrix3fv(location, 1, GL_FALSE, &m[0][0]); 174 | } 175 | } 176 | 177 | void GLSLProgram::setUniform(const char *name, float val){ 178 | GLuint location = glGetUniformLocation(m_handle, name); 179 | if( location >= 0 ){ 180 | glUniform1f(location, val); 181 | } 182 | } 183 | 184 | void GLSLProgram::setUniform(const char *name, int val){ 185 | GLuint location = glGetUniformLocation(m_handle, name); 186 | if( location >= 0 ){ 187 | glUniform1i(location, val); 188 | } 189 | } 190 | 191 | void GLSLProgram::setUniform(const char *name, bool val){ 192 | GLuint location = glGetUniformLocation(m_handle, name); 193 | if( location >= 0 ){ 194 | glUniform1i(location, val); 195 | } 196 | } 197 | 198 | void GLSLProgram::setUniform( const char *name, float x, float y, float z, float w ){ 199 | GLuint location = glGetUniformLocation(m_handle, name); 200 | if( location >= 0 ){ 201 | glUniform4f(location, x, y, z, w); 202 | } 203 | } 204 | 205 | void GLSLProgram::setUniform(const char *name, float x, float y, float z){ 206 | GLuint location = glGetUniformLocation(m_handle, name); 207 | if( location >= 0 ){ 208 | glUniform3f(location, x, y, z); 209 | } 210 | } 211 | 212 | void GLSLProgram::setUniform(const char *name, float x, float y){ 213 | GLuint location = glGetUniformLocation(m_handle, name); 214 | if( location >= 0 ){ 215 | glUniform2f(location, x, y); 216 | } 217 | } 218 | 219 | void GLSLProgram::printActiveUniforms(){ 220 | GLint maxLength, nUniforms; 221 | glGetProgramiv(m_handle, GL_ACTIVE_UNIFORMS, &nUniforms); 222 | glGetProgramiv(m_handle, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxLength); 223 | 224 | GLchar* name = (GLchar*) malloc(maxLength); 225 | 226 | GLint written, size, location; 227 | GLenum type; 228 | printf("Location | Name\n"); 229 | printf("----------------------------------------------------\n"); 230 | for( int i = 0; i < nUniforms; i++){ 231 | glGetActiveUniform(m_handle, i, maxLength, &written, &size, &type, name); 232 | location = glGetUniformLocation(m_handle, name); 233 | printf(" %-5d | %s\n", location, name); 234 | } 235 | free(name); 236 | } 237 | 238 | void GLSLProgram::printActiveAttribs(){ 239 | GLint maxLength, nAttribs; 240 | glGetProgramiv(m_handle, GL_ACTIVE_ATTRIBUTES, &nAttribs); 241 | glGetProgramiv(m_handle, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxLength); 242 | 243 | GLchar* name = (GLchar*) malloc(maxLength); 244 | 245 | GLint written, size, location; 246 | GLenum type; 247 | printf("Index | Name\n"); 248 | printf("----------------------------------------------------\n"); 249 | for( int i = 0; i < nAttribs; i++){ 250 | glGetActiveAttrib(m_handle, i, maxLength, &written, &size, &type, name); 251 | location = glGetAttribLocation(m_handle, name); 252 | printf(" %-5d | %s\n", location, name); 253 | } 254 | free(name); 255 | } 256 | -------------------------------------------------------------------------------- /SDL2-GUI/SDL2-GUI.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {631977CB-C514-466F-B12C-9BDB15DCE4F7} 15 | SDL2_GUI 16 | 17 | 18 | 19 | Application 20 | true 21 | v110 22 | MultiByte 23 | 24 | 25 | Application 26 | false 27 | v110 28 | true 29 | MultiByte 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | C:\Program Files\Assimp\include;C:\Users\Lee\Desktop\json-cpp-master\include;$(IncludePath) 43 | C:\Program Files\Assimp\lib\x86;$(LibraryPath) 44 | 45 | 46 | 47 | Level3 48 | Disabled 49 | C:\SDL2-2.0.1\include;C:\Users\Lee\Desktop\assimp--3.0.1270-sdk\include;C:\Users\Lee\Desktop\jansson-2.5\src;%(AdditionalIncludeDirectories) 50 | MultiThreadedDLL 51 | false 52 | 53 | 54 | true 55 | C:\Program Files %28x86%29\Microsoft Visual Studio 11.0\VC\lib;C:\SDL2-2.0.1\lib\x86;C:\Program Files\Assimp\lib\x86;C:\Users\Lee\Desktop\jansson-2.5\win32\vs2010\Output\Debug;C:\Users\Lee\Downloads\tinyxml2-master\tinyxml2\bin\Win32-Debug-Dll;%(AdditionalLibraryDirectories) 56 | opengl32.lib;SDL2.lib;SDL2main.lib;glew32.lib;assimp.lib;tinyxml2.lib;%(AdditionalDependencies) 57 | Console 58 | /verbose:lib 59 | 60 | 61 | 62 | 63 | Level3 64 | MaxSpeed 65 | true 66 | true 67 | 68 | 69 | true 70 | true 71 | true 72 | opengl32.lib;%(AdditionalDependencies) 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | CppCode 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | -------------------------------------------------------------------------------- /SDL2-GUI/json/writer.h: -------------------------------------------------------------------------------- 1 | // Copyright 2007-2010 Baptiste Lepilleur 2 | // Distributed under MIT license, or public domain if desired and 3 | // recognized in your jurisdiction. 4 | // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 5 | 6 | #ifndef JSON_WRITER_H_INCLUDED 7 | # define JSON_WRITER_H_INCLUDED 8 | 9 | #if !defined(JSON_IS_AMALGAMATION) 10 | # include "value.h" 11 | #endif // if !defined(JSON_IS_AMALGAMATION) 12 | # include 13 | # include 14 | 15 | namespace Json { 16 | 17 | class Value; 18 | 19 | /** \brief Abstract class for writers. 20 | */ 21 | class JSON_API Writer 22 | { 23 | public: 24 | virtual ~Writer(); 25 | 26 | virtual std::string write( const Value &root ) = 0; 27 | }; 28 | 29 | /** \brief Outputs a Value in JSON format without formatting (not human friendly). 30 | * 31 | * The JSON document is written in a single line. It is not intended for 'human' consumption, 32 | * but may be usefull to support feature such as RPC where bandwith is limited. 33 | * \sa Reader, Value 34 | */ 35 | class JSON_API FastWriter : public Writer 36 | { 37 | public: 38 | FastWriter(); 39 | virtual ~FastWriter(){} 40 | 41 | void enableYAMLCompatibility(); 42 | 43 | /** \brief Drop the "null" string from the writer's output for nullValues. 44 | * Strictly speaking, this is not valid JSON. But when the output is being 45 | * fed to a browser's Javascript, it makes for smaller output and the 46 | * browser can handle the output just fine. 47 | */ 48 | void dropNullPlaceholders(); 49 | 50 | public: // overridden from Writer 51 | virtual std::string write( const Value &root ); 52 | 53 | private: 54 | void writeValue( const Value &value ); 55 | 56 | std::string document_; 57 | bool yamlCompatiblityEnabled_; 58 | bool dropNullPlaceholders_; 59 | }; 60 | 61 | /** \brief Writes a Value in JSON format in a human friendly way. 62 | * 63 | * The rules for line break and indent are as follow: 64 | * - Object value: 65 | * - if empty then print {} without indent and line break 66 | * - if not empty the print '{', line break & indent, print one value per line 67 | * and then unindent and line break and print '}'. 68 | * - Array value: 69 | * - if empty then print [] without indent and line break 70 | * - if the array contains no object value, empty array or some other value types, 71 | * and all the values fit on one lines, then print the array on a single line. 72 | * - otherwise, it the values do not fit on one line, or the array contains 73 | * object or non empty array, then print one value per line. 74 | * 75 | * If the Value have comments then they are outputed according to their #CommentPlacement. 76 | * 77 | * \sa Reader, Value, Value::setComment() 78 | */ 79 | class JSON_API StyledWriter: public Writer 80 | { 81 | public: 82 | StyledWriter(); 83 | virtual ~StyledWriter(){} 84 | 85 | public: // overridden from Writer 86 | /** \brief Serialize a Value in JSON format. 87 | * \param root Value to serialize. 88 | * \return String containing the JSON document that represents the root value. 89 | */ 90 | virtual std::string write( const Value &root ); 91 | 92 | private: 93 | void writeValue( const Value &value ); 94 | void writeArrayValue( const Value &value ); 95 | bool isMultineArray( const Value &value ); 96 | void pushValue( const std::string &value ); 97 | void writeIndent(); 98 | void writeWithIndent( const std::string &value ); 99 | void indent(); 100 | void unindent(); 101 | void writeCommentBeforeValue( const Value &root ); 102 | void writeCommentAfterValueOnSameLine( const Value &root ); 103 | bool hasCommentForValue( const Value &value ); 104 | static std::string normalizeEOL( const std::string &text ); 105 | 106 | typedef std::vector ChildValues; 107 | 108 | ChildValues childValues_; 109 | std::string document_; 110 | std::string indentString_; 111 | int rightMargin_; 112 | int indentSize_; 113 | bool addChildValues_; 114 | }; 115 | 116 | /** \brief Writes a Value in JSON format in a human friendly way, 117 | to a stream rather than to a string. 118 | * 119 | * The rules for line break and indent are as follow: 120 | * - Object value: 121 | * - if empty then print {} without indent and line break 122 | * - if not empty the print '{', line break & indent, print one value per line 123 | * and then unindent and line break and print '}'. 124 | * - Array value: 125 | * - if empty then print [] without indent and line break 126 | * - if the array contains no object value, empty array or some other value types, 127 | * and all the values fit on one lines, then print the array on a single line. 128 | * - otherwise, it the values do not fit on one line, or the array contains 129 | * object or non empty array, then print one value per line. 130 | * 131 | * If the Value have comments then they are outputed according to their #CommentPlacement. 132 | * 133 | * \param indentation Each level will be indented by this amount extra. 134 | * \sa Reader, Value, Value::setComment() 135 | */ 136 | class JSON_API StyledStreamWriter 137 | { 138 | public: 139 | StyledStreamWriter( std::string indentation="\t" ); 140 | ~StyledStreamWriter(){} 141 | 142 | public: 143 | /** \brief Serialize a Value in JSON format. 144 | * \param out Stream to write to. (Can be ostringstream, e.g.) 145 | * \param root Value to serialize. 146 | * \note There is no point in deriving from Writer, since write() should not return a value. 147 | */ 148 | void write( std::ostream &out, const Value &root ); 149 | 150 | private: 151 | void writeValue( const Value &value ); 152 | void writeArrayValue( const Value &value ); 153 | bool isMultineArray( const Value &value ); 154 | void pushValue( const std::string &value ); 155 | void writeIndent(); 156 | void writeWithIndent( const std::string &value ); 157 | void indent(); 158 | void unindent(); 159 | void writeCommentBeforeValue( const Value &root ); 160 | void writeCommentAfterValueOnSameLine( const Value &root ); 161 | bool hasCommentForValue( const Value &value ); 162 | static std::string normalizeEOL( const std::string &text ); 163 | 164 | typedef std::vector ChildValues; 165 | 166 | ChildValues childValues_; 167 | std::ostream* document_; 168 | std::string indentString_; 169 | int rightMargin_; 170 | std::string indentation_; 171 | bool addChildValues_; 172 | }; 173 | 174 | # if defined(JSON_HAS_INT64) 175 | std::string JSON_API valueToString( Int value ); 176 | std::string JSON_API valueToString( UInt value ); 177 | # endif // if defined(JSON_HAS_INT64) 178 | std::string JSON_API valueToString( LargestInt value ); 179 | std::string JSON_API valueToString( LargestUInt value ); 180 | std::string JSON_API valueToString( double value ); 181 | std::string JSON_API valueToString( bool value ); 182 | std::string JSON_API valueToQuotedString( const char *value ); 183 | 184 | /// \brief Output using the StyledStreamWriter. 185 | /// \see Json::operator>>() 186 | std::ostream& operator<<( std::ostream&, const Value &root ); 187 | 188 | } // namespace Json 189 | 190 | 191 | 192 | #endif // JSON_WRITER_H_INCLUDED 193 | -------------------------------------------------------------------------------- /SDL2-GUI/json/reader.h: -------------------------------------------------------------------------------- 1 | // Copyright 2007-2010 Baptiste Lepilleur 2 | // Distributed under MIT license, or public domain if desired and 3 | // recognized in your jurisdiction. 4 | // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 5 | 6 | #ifndef CPPTL_JSON_READER_H_INCLUDED 7 | # define CPPTL_JSON_READER_H_INCLUDED 8 | 9 | #if !defined(JSON_IS_AMALGAMATION) 10 | # include "features.h" 11 | # include "value.h" 12 | #endif // if !defined(JSON_IS_AMALGAMATION) 13 | # include 14 | # include 15 | # include 16 | 17 | namespace Json { 18 | 19 | /** \brief Unserialize a JSON document into a Value. 20 | * 21 | */ 22 | class JSON_API Reader 23 | { 24 | public: 25 | typedef char Char; 26 | typedef const Char *Location; 27 | 28 | /** \brief Constructs a Reader allowing all features 29 | * for parsing. 30 | */ 31 | Reader(); 32 | 33 | /** \brief Constructs a Reader allowing the specified feature set 34 | * for parsing. 35 | */ 36 | Reader( const Features &features ); 37 | 38 | /** \brief Read a Value from a JSON document. 39 | * \param document UTF-8 encoded string containing the document to read. 40 | * \param root [out] Contains the root value of the document if it was 41 | * successfully parsed. 42 | * \param collectComments \c true to collect comment and allow writing them back during 43 | * serialization, \c false to discard comments. 44 | * This parameter is ignored if Features::allowComments_ 45 | * is \c false. 46 | * \return \c true if the document was successfully parsed, \c false if an error occurred. 47 | */ 48 | bool parse( const std::string &document, 49 | Value &root, 50 | bool collectComments = true ); 51 | 52 | /** \brief Read a Value from a JSON document. 53 | * \param beginDoc Pointer on the beginning of the UTF-8 encoded string of the document to read. 54 | * \param endDoc Pointer on the end of the UTF-8 encoded string of the document to read. 55 | \ Must be >= beginDoc. 56 | * \param root [out] Contains the root value of the document if it was 57 | * successfully parsed. 58 | * \param collectComments \c true to collect comment and allow writing them back during 59 | * serialization, \c false to discard comments. 60 | * This parameter is ignored if Features::allowComments_ 61 | * is \c false. 62 | * \return \c true if the document was successfully parsed, \c false if an error occurred. 63 | */ 64 | bool parse( const char *beginDoc, const char *endDoc, 65 | Value &root, 66 | bool collectComments = true ); 67 | 68 | /// \brief Parse from input stream. 69 | /// \see Json::operator>>(std::istream&, Json::Value&). 70 | bool parse( std::istream &is, 71 | Value &root, 72 | bool collectComments = true ); 73 | 74 | /** \brief Returns a user friendly string that list errors in the parsed document. 75 | * \return Formatted error message with the list of errors with their location in 76 | * the parsed document. An empty string is returned if no error occurred 77 | * during parsing. 78 | * \deprecated Use getFormattedErrorMessages() instead (typo fix). 79 | */ 80 | JSONCPP_DEPRECATED("Use getFormattedErrorMessages instead") 81 | std::string getFormatedErrorMessages() const; 82 | 83 | /** \brief Returns a user friendly string that list errors in the parsed document. 84 | * \return Formatted error message with the list of errors with their location in 85 | * the parsed document. An empty string is returned if no error occurred 86 | * during parsing. 87 | */ 88 | std::string getFormattedErrorMessages() const; 89 | 90 | private: 91 | enum TokenType 92 | { 93 | tokenEndOfStream = 0, 94 | tokenObjectBegin, 95 | tokenObjectEnd, 96 | tokenArrayBegin, 97 | tokenArrayEnd, 98 | tokenString, 99 | tokenNumber, 100 | tokenTrue, 101 | tokenFalse, 102 | tokenNull, 103 | tokenArraySeparator, 104 | tokenMemberSeparator, 105 | tokenComment, 106 | tokenError 107 | }; 108 | 109 | class Token 110 | { 111 | public: 112 | TokenType type_; 113 | Location start_; 114 | Location end_; 115 | }; 116 | 117 | class ErrorInfo 118 | { 119 | public: 120 | Token token_; 121 | std::string message_; 122 | Location extra_; 123 | }; 124 | 125 | typedef std::deque Errors; 126 | 127 | bool expectToken( TokenType type, Token &token, const char *message ); 128 | bool readToken( Token &token ); 129 | void skipSpaces(); 130 | bool match( Location pattern, 131 | int patternLength ); 132 | bool readComment(); 133 | bool readCStyleComment(); 134 | bool readCppStyleComment(); 135 | bool readString(); 136 | void readNumber(); 137 | bool readValue(); 138 | bool readObject( Token &token ); 139 | bool readArray( Token &token ); 140 | bool decodeNumber( Token &token ); 141 | bool decodeString( Token &token ); 142 | bool decodeString( Token &token, std::string &decoded ); 143 | bool decodeDouble( Token &token ); 144 | bool decodeUnicodeCodePoint( Token &token, 145 | Location ¤t, 146 | Location end, 147 | unsigned int &unicode ); 148 | bool decodeUnicodeEscapeSequence( Token &token, 149 | Location ¤t, 150 | Location end, 151 | unsigned int &unicode ); 152 | bool addError( const std::string &message, 153 | Token &token, 154 | Location extra = 0 ); 155 | bool recoverFromError( TokenType skipUntilToken ); 156 | bool addErrorAndRecover( const std::string &message, 157 | Token &token, 158 | TokenType skipUntilToken ); 159 | void skipUntilSpace(); 160 | Value ¤tValue(); 161 | Char getNextChar(); 162 | void getLocationLineAndColumn( Location location, 163 | int &line, 164 | int &column ) const; 165 | std::string getLocationLineAndColumn( Location location ) const; 166 | void addComment( Location begin, 167 | Location end, 168 | CommentPlacement placement ); 169 | void skipCommentTokens( Token &token ); 170 | 171 | typedef std::stack Nodes; 172 | Nodes nodes_; 173 | Errors errors_; 174 | std::string document_; 175 | Location begin_; 176 | Location end_; 177 | Location current_; 178 | Location lastValueEnd_; 179 | Value *lastValue_; 180 | std::string commentsBefore_; 181 | Features features_; 182 | bool collectComments_; 183 | }; 184 | 185 | /** \brief Read from 'sin' into 'root'. 186 | 187 | Always keep comments from the input JSON. 188 | 189 | This can be used to read a file into a particular sub-object. 190 | For example: 191 | \code 192 | Json::Value root; 193 | cin >> root["dir"]["file"]; 194 | cout << root; 195 | \endcode 196 | Result: 197 | \verbatim 198 | { 199 | "dir": { 200 | "file": { 201 | // The input stream JSON would be nested here. 202 | } 203 | } 204 | } 205 | \endverbatim 206 | \throw std::exception on parse error. 207 | \see Json::operator<<() 208 | */ 209 | std::istream& operator>>( std::istream&, Value& ); 210 | 211 | } // namespace Json 212 | 213 | #endif // CPPTL_JSON_READER_H_INCLUDED 214 | -------------------------------------------------------------------------------- /SDL2-GUI/SDL2-GUI.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | {799226d1-4a27-4d11-a459-8120b1d97687} 18 | 19 | 20 | {01232fed-f65d-4b1d-bbb1-446cdd7c35d0} 21 | 22 | 23 | {0f98e5eb-d6e7-493a-b54f-6794a91e587e} 24 | 25 | 26 | {0270fc61-583f-44b0-af2c-76e9109a0744} 27 | 28 | 29 | {6bc5525b-0002-477f-a1e9-34abcde7d25e} 30 | 31 | 32 | 33 | 34 | Source Files 35 | 36 | 37 | Source Files\GUI_Components 38 | 39 | 40 | Source Files\GUI_Components 41 | 42 | 43 | Source Files\GUI_Components 44 | 45 | 46 | Source Files\GUI_Components 47 | 48 | 49 | Source Files\GUI_Components 50 | 51 | 52 | Source Files\GUI_Components 53 | 54 | 55 | Source Files\GUI_Components 56 | 57 | 58 | Source Files\GUI_Components 59 | 60 | 61 | Source Files\GUI_Components 62 | 63 | 64 | Source Files\GUI_Components 65 | 66 | 67 | Source Files 68 | 69 | 70 | Source Files\GUI_Components 71 | 72 | 73 | Source Files\GUI_Components 74 | 75 | 76 | Source Files\GUI_Components 77 | 78 | 79 | Source Files\GUI_Components 80 | 81 | 82 | Source Files\OGLImplementation 83 | 84 | 85 | Source Files\OGLImplementation 86 | 87 | 88 | Source Files\OGLImplementation 89 | 90 | 91 | Source Files\OGLImplementation 92 | 93 | 94 | Source Files\OGLImplementation 95 | 96 | 97 | Source Files\OGLImplementation 98 | 99 | 100 | Source Files\OGLImplementation 101 | 102 | 103 | Source Files\OGLImplementation 104 | 105 | 106 | Source Files\OGLImplementation 107 | 108 | 109 | 110 | 111 | Header Files\3DBackground 112 | 113 | 114 | Header Files\3DBackground 115 | 116 | 117 | Header Files\GUI_Components 118 | 119 | 120 | Header Files\GUI_Components 121 | 122 | 123 | Header Files\GUI_Components 124 | 125 | 126 | Header Files\GUI_Components 127 | 128 | 129 | Header Files\GUI_Components 130 | 131 | 132 | Header Files\GUI_Components 133 | 134 | 135 | Header Files\GUI_Components 136 | 137 | 138 | Header Files\GUI_Components 139 | 140 | 141 | Header Files\GUI_Components 142 | 143 | 144 | Header Files\GUI_Components 145 | 146 | 147 | Header Files\GUI_Components 148 | 149 | 150 | Header Files\GUI_Components 151 | 152 | 153 | Header Files\GUI_Components 154 | 155 | 156 | Header Files\GUI_Components 157 | 158 | 159 | Header Files\GUI_Components 160 | 161 | 162 | Header Files 163 | 164 | 165 | Header Files\GUI_Components 166 | 167 | 168 | Header Files\GUI_Components 169 | 170 | 171 | Header Files\GUI_Components 172 | 173 | 174 | Header Files 175 | 176 | 177 | Header Files 178 | 179 | 180 | Header Files 181 | 182 | 183 | Header Files\OGLHeaders 184 | 185 | 186 | Header Files\OGLHeaders 187 | 188 | 189 | Header Files\OGLHeaders 190 | 191 | 192 | Header Files\OGLHeaders 193 | 194 | 195 | Header Files\OGLHeaders 196 | 197 | 198 | Header Files\OGLHeaders 199 | 200 | 201 | Header Files\OGLHeaders 202 | 203 | 204 | Header Files\OGLHeaders 205 | 206 | 207 | Header Files\OGLHeaders 208 | 209 | 210 | Header Files\OGLHeaders 211 | 212 | 213 | Header Files\OGLHeaders 214 | 215 | 216 | Header Files\OGLHeaders 217 | 218 | 219 | Header Files\OGLHeaders 220 | 221 | 222 | Header Files\OGLHeaders 223 | 224 | 225 | Header Files\OGLHeaders 226 | 227 | 228 | -------------------------------------------------------------------------------- /SDL2-GUI/GUIFactory.cpp: -------------------------------------------------------------------------------- 1 | #include"GUIFactory.h" 2 | #include"TextureLoading.h" 3 | 4 | namespace SDLGUI { 5 | 6 | GUIFactory::GUIFactory(SDL_Window* window) { 7 | SDL_GetWindowSize(window, &m_windowWidth, &m_windowHeight); 8 | }; 9 | 10 | GUIFactory::~GUIFactory(){ 11 | 12 | }; 13 | 14 | std::shared_ptr GUIFactory::newGUIManager( const char* xmlFile ){ 15 | m_doc = new tinyxml2::XMLDocument(); 16 | 17 | std::shared_ptr program = this->newProgram( "panel.vert", "panel.frag" ); 18 | std::shared_ptr textProgram = this->newProgram( "text.vert", "text.frag" ); 19 | m_view = std::shared_ptr(new GUIView( program )); 20 | m_view->assignFont( this->newGUIFont("C:\\Users\\Lee\\Documents\\Visual Studio 2012\\Projects\\SDL2-GUI\\SDL2-GUI\\content\\Fonts\\VeraMoBI.ttf_sdf.png", "C:\\Users\\Lee\\Documents\\Visual Studio 2012\\Projects\\SDL2-GUI\\SDL2-GUI\\content\\Fonts\\VeraMoBI.txt", textProgram) ); 21 | m_view->assignErrorTexture( newTexture("error.bmp") ); 22 | 23 | 24 | m_manager = std::shared_ptr(new GUIManager()); 25 | m_manager->assignView(m_view); 26 | m_manager->assignProgram(program); 27 | m_manager->assignFPS( std::static_pointer_cast(newTextBox( 100, 40, 100, 100, "fps_box", NULL, glm::vec2(1.0, 1.0), "FPS: 100000", m_view) )); 28 | 29 | if(m_doc->LoadFile(xmlFile)){ 30 | printf("loading xml file error"); 31 | return m_manager; 32 | } 33 | 34 | 35 | tinyxml2::XMLNode* child = m_doc->FirstChild(); 36 | iterateTree( child->NextSiblingElement(), NULL); 37 | 38 | return m_manager; 39 | } 40 | 41 | std::shared_ptr GUIFactory::newTextBox( int x, int y, int width, int height, const char* id, std::shared_ptr parent, glm::vec2 scale, std::string text, std::shared_ptr view){ 42 | 43 | std::shared_ptr outTextBox = std::shared_ptr(new GUITextBox()); 44 | outTextBox->assignView( view ); 45 | outTextBox->assignHeight( height ); 46 | outTextBox->assignWidth( width ); 47 | outTextBox->addParent( parent ); 48 | outTextBox->assignPosition( this->getPos(x , y ) ); 49 | outTextBox->assignScreenPosition( x, y ); 50 | outTextBox->assignScale( scale ); 51 | outTextBox->assignTextWrap( text , width ); 52 | outTextBox->assignNumChars( text.size() ); 53 | 54 | return outTextBox; 55 | } 56 | 57 | std::shared_ptr GUIFactory::newButton(int x, int y, int width, int height, const char* id, std::shared_ptr parent, const char* texture, glm::vec2 scale){ 58 | 59 | std::shared_ptr outButton = std::shared_ptr(new GUI2DButton()); 60 | outButton->assignHeight(height); 61 | outButton->assignWidth(width); 62 | outButton->assignId(id); 63 | outButton->addParent(parent); 64 | outButton->assignPosition( this->getPos(x + width/2, y + height/2) ); 65 | outButton->assignScreenPosition( x, y ); 66 | outButton->assignTexture( newTexture( texture ) ); 67 | outButton->assignScale( scale ); 68 | 69 | 70 | return outButton; 71 | } 72 | 73 | std::shared_ptr GUIFactory::newLayout(int x, int y, int width, int height, const char* id, std::shared_ptr parent, glm::vec2 scale){ 74 | 75 | std::shared_ptr outLayout = std::shared_ptr(new GUILayout()); 76 | outLayout->assignHeight(height); 77 | outLayout->assignWidth(width); 78 | outLayout->assignPosition( this->getPos(x + width/2, y + height/2) ); 79 | outLayout->assignScreenPosition( x, y ); 80 | outLayout->addParent(parent); 81 | outLayout->assignScale( scale ); 82 | 83 | return outLayout; 84 | } 85 | 86 | std::shared_ptr GUIFactory::newGUIFont(const char* fontTexture , const char* fontData , std::shared_ptr fontProgram){ 87 | 88 | GLuint textTexture = this->newTexture( fontTexture ); 89 | std::shared_ptr localFont = std::shared_ptr(new GUIFont( textTexture, fontData, fontProgram )); 90 | 91 | return localFont; 92 | } 93 | 94 | glm::vec4 GUIFactory::createStencil( std::shared_ptr el, std::shared_ptr parent ) { 95 | glm::vec4 stencil; //represents the x,y position and width and height 96 | 97 | //need parameters defining a stencil for the element 98 | //also need method to obtain the stencil within the parent element 99 | //will need to update this down the tree 100 | 101 | //return created stencil, or just add to the element and make this method null 102 | return stencil; 103 | 104 | } 105 | 106 | 107 | std::shared_ptr GUIFactory::newElement( tinyxml2::XMLElement* type, std::shared_ptr parent ){ 108 | const char* name = type->Name(); 109 | if(std::strcmp( name, "button") == 0){ 110 | float x = type->IntAttribute("width"); 111 | float y = type->IntAttribute("height"); 112 | 113 | std::shared_ptr button = newButton( type->IntAttribute("x"), type->IntAttribute("y"), 114 | type->IntAttribute("width"), type->IntAttribute("height"), type->Attribute("id"), 115 | parent, type->Attribute("texture"), glm::vec2(x/m_windowWidth, y/m_windowHeight) ); 116 | 117 | button->assignView(m_view); 118 | 119 | parent->addChild(button); 120 | 121 | return button; 122 | 123 | } 124 | else if(std::strcmp(name,"layout") == 0 ){ 125 | float x = type->IntAttribute("width"); 126 | float y = type->IntAttribute("height"); 127 | 128 | std::shared_ptr layout = newLayout( type->IntAttribute("x"), type->IntAttribute("y"), 129 | type->IntAttribute("width"), type->IntAttribute("height"), type->Attribute("id"), 130 | parent, glm::vec2(x/m_windowWidth, y/m_windowHeight)); 131 | 132 | layout->assignView(m_view); 133 | 134 | parent->addChild(layout); 135 | 136 | return layout; 137 | } 138 | else if(std::strcmp(name, "text_box") == 0){ 139 | float x = type->IntAttribute("width"); 140 | float y = type->IntAttribute("height"); 141 | std::string boxText = type->GetText(); 142 | 143 | if( boxText.size() == 0 ){ 144 | boxText.append(" "); 145 | } 146 | 147 | std::shared_ptr textBox = newTextBox( type->IntAttribute("x"), type->IntAttribute("y"), 148 | type->IntAttribute("width"), type->IntAttribute("height"), type->Attribute("id"), 149 | parent, glm::vec2(x, y), boxText , m_view); 150 | 151 | textBox->assignView(m_view); 152 | 153 | parent->addChild(textBox); 154 | 155 | return textBox; 156 | } 157 | else if(std::strcmp(name,"window") == 0){ 158 | std::shared_ptr window = newLayout(0, 0 , m_windowWidth, m_windowHeight, "SDL_WINDOW", parent, glm::vec2(1.0, 1.0)); 159 | m_manager->assignWindow(window); 160 | window->assignView(m_view); 161 | return window; 162 | } 163 | } 164 | 165 | void GUIFactory::iterateTree( tinyxml2::XMLElement* node, std::shared_ptr parent){ 166 | 167 | std::shared_ptr element = newElement( node->ToElement(), parent); 168 | 169 | for( tinyxml2::XMLElement* loopNode = node->FirstChildElement(); loopNode != NULL; loopNode=loopNode->NextSiblingElement()){ 170 | iterateTree(loopNode, element); 171 | } 172 | } 173 | 174 | /*unsigned char* GUIFactory::loadImage(const char* file, int* x, int* y){ 175 | int n; 176 | int force_channels = 4; 177 | unsigned char* image_data = stbi_load (file, x, y, &n, force_channels); 178 | if (!image_data) { 179 | fprintf (stderr, "ERROR: could not load %s\n", file); 180 | } 181 | 182 | // NPOT check 183 | if ((*x & (*x - 1)) != 0 || (*y & (*y - 1)) != 0) { 184 | fprintf ( 185 | stderr, "WARNING: texture %s is not power-of-2 dimensions\n", file 186 | ); 187 | } 188 | 189 | int width_in_bytes = *x * 4; 190 | unsigned char *top = NULL; 191 | unsigned char *bottom = NULL; 192 | unsigned char temp = 0; 193 | int half_height = (*y) / 2; 194 | 195 | for (int row = 0; row < half_height; row++) { 196 | top = image_data + row * width_in_bytes; 197 | bottom = image_data + (*y - row - 1) * width_in_bytes; 198 | for (int col = 0; col < width_in_bytes; col++) { 199 | temp = *top; 200 | *top = *bottom; 201 | *bottom = temp; 202 | top++; 203 | bottom++; 204 | } 205 | } 206 | 207 | return image_data; 208 | }*/ 209 | 210 | GLuint GUIFactory::newTexture(const char* file){ 211 | int x, y; 212 | unsigned char* image = loadImage(file, &x, &y); 213 | 214 | GLuint localTexture; 215 | 216 | glGenTextures (1, &localTexture); 217 | glActiveTexture (GL_TEXTURE0); 218 | glBindTexture (GL_TEXTURE_2D, localTexture); 219 | glTexImage2D ( 220 | GL_TEXTURE_2D, 221 | 0, 222 | GL_RGBA, 223 | x, 224 | y, 225 | 0, 226 | GL_RGBA, 227 | GL_UNSIGNED_BYTE, 228 | image 229 | ); 230 | 231 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 232 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 233 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 234 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 235 | 236 | delete[](image); 237 | 238 | return localTexture; 239 | } 240 | 241 | std::shared_ptr GUIFactory::newProgram( const char* vertShader, const char* fragShader){ 242 | std::shared_ptr program = std::shared_ptr(new GLSLProgram()); 243 | program->compileShaderFromFile(vertShader, GLSLShader::VERTEX); 244 | program->compileShaderFromFile(fragShader, GLSLShader::FRAGMENT); 245 | program->link(); 246 | return program; 247 | } 248 | 249 | glm::vec2 GUIFactory::getPos( float x, float y ){ 250 | float xPos = (2*x - (float)m_windowWidth)/(float)m_windowWidth; 251 | float yPos = ((float)m_windowHeight - 2*y)/(float)m_windowHeight; 252 | return glm::vec2(xPos, yPos); 253 | } 254 | 255 | } -------------------------------------------------------------------------------- /SDL2-GUI/jansson.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2013 Petri Lehtinen 3 | * 4 | * Jansson is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef JANSSON_H 9 | #define JANSSON_H 10 | 11 | #include 12 | #include /* for size_t */ 13 | #include 14 | 15 | #include 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | /* version */ 22 | 23 | #define JANSSON_MAJOR_VERSION 2 24 | #define JANSSON_MINOR_VERSION 5 25 | #define JANSSON_MICRO_VERSION 0 26 | 27 | /* Micro version is omitted if it's 0 */ 28 | #define JANSSON_VERSION "2.5" 29 | 30 | /* Version as a 3-byte hex number, e.g. 0x010201 == 1.2.1. Use this 31 | for numeric comparisons, e.g. #if JANSSON_VERSION_HEX >= ... */ 32 | #define JANSSON_VERSION_HEX ((JANSSON_MAJOR_VERSION << 16) | \ 33 | (JANSSON_MINOR_VERSION << 8) | \ 34 | (JANSSON_MICRO_VERSION << 0)) 35 | 36 | 37 | /* types */ 38 | 39 | typedef enum { 40 | JSON_OBJECT, 41 | JSON_ARRAY, 42 | JSON_STRING, 43 | JSON_INTEGER, 44 | JSON_REAL, 45 | JSON_TRUE, 46 | JSON_FALSE, 47 | JSON_NULL 48 | } json_type; 49 | 50 | typedef struct json_t { 51 | json_type type; 52 | size_t refcount; 53 | } json_t; 54 | 55 | #ifndef JANSSON_USING_CMAKE /* disabled if using cmake */ 56 | #if JSON_INTEGER_IS_LONG_LONG 57 | #ifdef _WIN32 58 | #define JSON_INTEGER_FORMAT "I64d" 59 | #else 60 | #define JSON_INTEGER_FORMAT "lld" 61 | #endif 62 | typedef long long json_int_t; 63 | #else 64 | #define JSON_INTEGER_FORMAT "ld" 65 | typedef long json_int_t; 66 | #endif /* JSON_INTEGER_IS_LONG_LONG */ 67 | #endif 68 | 69 | #define json_typeof(json) ((json)->type) 70 | #define json_is_object(json) (json && json_typeof(json) == JSON_OBJECT) 71 | #define json_is_array(json) (json && json_typeof(json) == JSON_ARRAY) 72 | #define json_is_string(json) (json && json_typeof(json) == JSON_STRING) 73 | #define json_is_integer(json) (json && json_typeof(json) == JSON_INTEGER) 74 | #define json_is_real(json) (json && json_typeof(json) == JSON_REAL) 75 | #define json_is_number(json) (json_is_integer(json) || json_is_real(json)) 76 | #define json_is_true(json) (json && json_typeof(json) == JSON_TRUE) 77 | #define json_is_false(json) (json && json_typeof(json) == JSON_FALSE) 78 | #define json_is_boolean(json) (json_is_true(json) || json_is_false(json)) 79 | #define json_is_null(json) (json && json_typeof(json) == JSON_NULL) 80 | 81 | /* construction, destruction, reference counting */ 82 | 83 | json_t *json_object(void); 84 | json_t *json_array(void); 85 | json_t *json_string(const char *value); 86 | json_t *json_string_nocheck(const char *value); 87 | json_t *json_integer(json_int_t value); 88 | json_t *json_real(double value); 89 | json_t *json_true(void); 90 | json_t *json_false(void); 91 | #define json_boolean(val) ((val) ? json_true() : json_false()) 92 | json_t *json_null(void); 93 | 94 | static JSON_INLINE 95 | json_t *json_incref(json_t *json) 96 | { 97 | if(json && json->refcount != (size_t)-1) 98 | ++json->refcount; 99 | return json; 100 | } 101 | 102 | /* do not call json_delete directly */ 103 | void json_delete(json_t *json); 104 | 105 | static JSON_INLINE 106 | void json_decref(json_t *json) 107 | { 108 | if(json && json->refcount != (size_t)-1 && --json->refcount == 0) 109 | json_delete(json); 110 | } 111 | 112 | 113 | /* error reporting */ 114 | 115 | #define JSON_ERROR_TEXT_LENGTH 160 116 | #define JSON_ERROR_SOURCE_LENGTH 80 117 | 118 | typedef struct { 119 | int line; 120 | int column; 121 | int position; 122 | char source[JSON_ERROR_SOURCE_LENGTH]; 123 | char text[JSON_ERROR_TEXT_LENGTH]; 124 | } json_error_t; 125 | 126 | 127 | /* getters, setters, manipulation */ 128 | 129 | size_t json_object_size(const json_t *object); 130 | json_t *json_object_get(const json_t *object, const char *key); 131 | int json_object_set_new(json_t *object, const char *key, json_t *value); 132 | int json_object_set_new_nocheck(json_t *object, const char *key, json_t *value); 133 | int json_object_del(json_t *object, const char *key); 134 | int json_object_clear(json_t *object); 135 | int json_object_update(json_t *object, json_t *other); 136 | int json_object_update_existing(json_t *object, json_t *other); 137 | int json_object_update_missing(json_t *object, json_t *other); 138 | void *json_object_iter(json_t *object); 139 | void *json_object_iter_at(json_t *object, const char *key); 140 | void *json_object_key_to_iter(const char *key); 141 | void *json_object_iter_next(json_t *object, void *iter); 142 | const char *json_object_iter_key(void *iter); 143 | json_t *json_object_iter_value(void *iter); 144 | int json_object_iter_set_new(json_t *object, void *iter, json_t *value); 145 | 146 | #define json_object_foreach(object, key, value) \ 147 | for(key = json_object_iter_key(json_object_iter(object)); \ 148 | key && (value = json_object_iter_value(json_object_key_to_iter(key))); \ 149 | key = json_object_iter_key(json_object_iter_next(object, json_object_key_to_iter(key)))) 150 | 151 | #define json_array_foreach(array, index, value) \ 152 | for(index = 0; \ 153 | index < json_array_size(array) && (value = json_array_get(array, index)); \ 154 | index++) 155 | 156 | static JSON_INLINE 157 | int json_object_set(json_t *object, const char *key, json_t *value) 158 | { 159 | return json_object_set_new(object, key, json_incref(value)); 160 | } 161 | 162 | static JSON_INLINE 163 | int json_object_set_nocheck(json_t *object, const char *key, json_t *value) 164 | { 165 | return json_object_set_new_nocheck(object, key, json_incref(value)); 166 | } 167 | 168 | static JSON_INLINE 169 | int json_object_iter_set(json_t *object, void *iter, json_t *value) 170 | { 171 | return json_object_iter_set_new(object, iter, json_incref(value)); 172 | } 173 | 174 | size_t json_array_size(const json_t *array); 175 | json_t *json_array_get(const json_t *array, size_t index); 176 | int json_array_set_new(json_t *array, size_t index, json_t *value); 177 | int json_array_append_new(json_t *array, json_t *value); 178 | int json_array_insert_new(json_t *array, size_t index, json_t *value); 179 | int json_array_remove(json_t *array, size_t index); 180 | int json_array_clear(json_t *array); 181 | int json_array_extend(json_t *array, json_t *other); 182 | 183 | static JSON_INLINE 184 | int json_array_set(json_t *array, size_t ind, json_t *value) 185 | { 186 | return json_array_set_new(array, ind, json_incref(value)); 187 | } 188 | 189 | static JSON_INLINE 190 | int json_array_append(json_t *array, json_t *value) 191 | { 192 | return json_array_append_new(array, json_incref(value)); 193 | } 194 | 195 | static JSON_INLINE 196 | int json_array_insert(json_t *array, size_t ind, json_t *value) 197 | { 198 | return json_array_insert_new(array, ind, json_incref(value)); 199 | } 200 | 201 | const char *json_string_value(const json_t *string); 202 | json_int_t json_integer_value(const json_t *integer); 203 | double json_real_value(const json_t *real); 204 | double json_number_value(const json_t *json); 205 | 206 | int json_string_set(json_t *string, const char *value); 207 | int json_string_set_nocheck(json_t *string, const char *value); 208 | int json_integer_set(json_t *integer, json_int_t value); 209 | int json_real_set(json_t *real, double value); 210 | 211 | 212 | /* pack, unpack */ 213 | 214 | json_t *json_pack(const char *fmt, ...); 215 | json_t *json_pack_ex(json_error_t *error, size_t flags, const char *fmt, ...); 216 | json_t *json_vpack_ex(json_error_t *error, size_t flags, const char *fmt, va_list ap); 217 | 218 | #define JSON_VALIDATE_ONLY 0x1 219 | #define JSON_STRICT 0x2 220 | 221 | int json_unpack(json_t *root, const char *fmt, ...); 222 | int json_unpack_ex(json_t *root, json_error_t *error, size_t flags, const char *fmt, ...); 223 | int json_vunpack_ex(json_t *root, json_error_t *error, size_t flags, const char *fmt, va_list ap); 224 | 225 | 226 | /* equality */ 227 | 228 | int json_equal(json_t *value1, json_t *value2); 229 | 230 | 231 | /* copying */ 232 | 233 | json_t *json_copy(json_t *value); 234 | json_t *json_deep_copy(const json_t *value); 235 | 236 | 237 | /* decoding */ 238 | 239 | #define JSON_REJECT_DUPLICATES 0x1 240 | #define JSON_DISABLE_EOF_CHECK 0x2 241 | #define JSON_DECODE_ANY 0x4 242 | #define JSON_DECODE_INT_AS_REAL 0x8 243 | 244 | typedef size_t (*json_load_callback_t)(void *buffer, size_t buflen, void *data); 245 | 246 | json_t *json_loads(const char *input, size_t flags, json_error_t *error); 247 | json_t *json_loadb(const char *buffer, size_t buflen, size_t flags, json_error_t *error); 248 | json_t *json_loadf(FILE *input, size_t flags, json_error_t *error); 249 | json_t *json_load_file(const char *path, size_t flags, json_error_t *error); 250 | json_t *json_load_callback(json_load_callback_t callback, void *data, size_t flags, json_error_t *error); 251 | 252 | 253 | /* encoding */ 254 | 255 | #define JSON_INDENT(n) (n & 0x1F) 256 | #define JSON_COMPACT 0x20 257 | #define JSON_ENSURE_ASCII 0x40 258 | #define JSON_SORT_KEYS 0x80 259 | #define JSON_PRESERVE_ORDER 0x100 260 | #define JSON_ENCODE_ANY 0x200 261 | #define JSON_ESCAPE_SLASH 0x400 262 | 263 | typedef int (*json_dump_callback_t)(const char *buffer, size_t size, void *data); 264 | 265 | char *json_dumps(const json_t *json, size_t flags); 266 | int json_dumpf(const json_t *json, FILE *output, size_t flags); 267 | int json_dump_file(const json_t *json, const char *path, size_t flags); 268 | int json_dump_callback(const json_t *json, json_dump_callback_t callback, void *data, size_t flags); 269 | 270 | /* custom memory allocation */ 271 | 272 | typedef void *(*json_malloc_t)(size_t); 273 | typedef void (*json_free_t)(void *); 274 | 275 | void json_set_alloc_funcs(json_malloc_t malloc_fn, json_free_t free_fn); 276 | 277 | #ifdef __cplusplus 278 | } 279 | #endif 280 | 281 | #endif 282 | -------------------------------------------------------------------------------- /SDL2-GUI/GUIFont.cpp: -------------------------------------------------------------------------------- 1 | #include"GUIFont.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include"StringUtils.h" 7 | 8 | namespace SDLGUI { 9 | 10 | GUIFont::GUIFont( GLuint fontTexture , const char* fontData , std::shared_ptr fontProgram ){ 11 | m_fontTexture = fontTexture; 12 | m_fontProgram = fontProgram; 13 | m_alpha = 1.0; 14 | m_color = glm::vec3(1.0,1.0,1.0); 15 | 16 | std::ifstream inFile(fontData); 17 | if( !inFile.is_open() ){ 18 | std::cout << "FAILED TO OPEN: " << fontData << std::endl; 19 | } 20 | this->parseFont( inFile ); 21 | inFile.close(); 22 | 23 | 24 | } 25 | 26 | GUIFont::~GUIFont(){ 27 | 28 | } 29 | 30 | void GUIFont::renderText( std::string text , float x , float y , int size ){ 31 | 32 | } 33 | 34 | void GUIFont::renderText( GLuint textVAO , float x, float y, int size, int stringSize ){ 35 | m_fontProgram->use(); 36 | glBindTexture(GL_TEXTURE_2D, m_fontTexture); 37 | m_fontProgram->setUniform("text_pos", x, y ); 38 | m_fontProgram->setUniform("text_color", m_color.x, m_color.y, m_color.z, m_alpha); 39 | glBindVertexArray(textVAO); 40 | glDrawArrays(GL_TRIANGLES, 0, stringSize*6); 41 | } 42 | 43 | void GUIFont::assignColor( glm::vec3 color ){ 44 | m_color = color; 45 | } 46 | 47 | void GUIFont::assignTransparency( float alpha ){ 48 | m_alpha = alpha; 49 | } 50 | 51 | GLuint GUIFont::cacheText( std::string text , GLuint vertVBO, GLuint texcoordVBO, GLuint textVAO ){ 52 | 53 | std::vector Verts; 54 | std::vector TexCoords; 55 | 56 | this->textListFill( text, Verts, TexCoords, 0 ); 57 | 58 | glBindVertexArray(textVAO); 59 | 60 | m_fontProgram->use(); 61 | 62 | //Bind VBO to hold surface data 63 | glBindBuffer(GL_ARRAY_BUFFER, vertVBO); 64 | glBufferData(GL_ARRAY_BUFFER, sizeof(float)*Verts.size(), &Verts[0], GL_DYNAMIC_DRAW); 65 | //bind vertex position attribute to GLSL program 66 | glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, NULL); 67 | m_fontProgram->bindAttribLocation(0, "vert_pos"); 68 | glEnableVertexAttribArray(0); 69 | 70 | //Bind VBO to hold surface data 71 | glBindBuffer(GL_ARRAY_BUFFER, texcoordVBO); 72 | glBufferData(GL_ARRAY_BUFFER, sizeof(float)*TexCoords.size(), &TexCoords[0], GL_DYNAMIC_DRAW); 73 | //bind texture coordinate attribute to GLSL program 74 | glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, NULL); 75 | m_fontProgram->bindAttribLocation(1, "vert_texcoord"); 76 | glEnableVertexAttribArray(1); 77 | 78 | glUseProgram(0); 79 | 80 | glBindVertexArray(0); 81 | 82 | return 0; 83 | 84 | } 85 | 86 | GLuint GUIFont::cacheTextWrap( std::string text, GLuint vertVBO, GLuint texcoordVBO, GLuint textVAO , int width ) { 87 | 88 | //request GPU memory allocation of the size neccesary to hold all the vertex data in this text. 89 | glBindVertexArray(textVAO); 90 | 91 | m_fontProgram->use(); 92 | 93 | //Bind VBO to hold surface data 94 | glBindBuffer(GL_ARRAY_BUFFER, vertVBO); 95 | glBufferData(GL_ARRAY_BUFFER, sizeof(float)*(text.size() + 1)*12, NULL , GL_DYNAMIC_DRAW); 96 | //bind vertex position attribute to GLSL program 97 | glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, NULL); 98 | m_fontProgram->bindAttribLocation(0, "vert_pos"); 99 | glEnableVertexAttribArray(0); 100 | 101 | //Bind VBO to hold surface data 102 | glBindBuffer(GL_ARRAY_BUFFER, texcoordVBO); 103 | glBufferData(GL_ARRAY_BUFFER, sizeof(float)*(text.size() + 1)*12, NULL , GL_DYNAMIC_DRAW); 104 | //bind texture coordinate attribute to GLSL program 105 | glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, NULL); 106 | m_fontProgram->bindAttribLocation(1, "vert_texcoord"); 107 | glEnableVertexAttribArray(1); 108 | 109 | glUseProgram(0); 110 | 111 | glBindVertexArray(0); 112 | 113 | 114 | std::vector lines = split(text, '\n'); 115 | 116 | std::vector::iterator textLines = lines.begin(); 117 | 118 | int Yoffset = 0; 119 | int totalText = 0; 120 | std::string currentLine; 121 | int totalWordLength = 0; 122 | int lineNum = 0; 123 | 124 | //add each line to the cached text 125 | for(; textLines != lines.end(); textLines++) { 126 | 127 | std::vector words = split( *textLines , ' '); 128 | std::vector::iterator wordList = words.begin(); 129 | 130 | totalWordLength = 0; 131 | lineNum = 0; 132 | 133 | //add words to the cached text 134 | for(; wordList != words.end(); wordList++) { 135 | 136 | if( currentLine.size() * m_charSet.Chars[' '].XAdvance > width ) { 137 | 138 | this->updateCacheText(currentLine, vertVBO, texcoordVBO, textVAO, totalText , Yoffset ); 139 | 140 | Yoffset += m_charSet.LineHeight; 141 | totalText += totalWordLength; 142 | totalWordLength = 0; 143 | lineNum++; 144 | currentLine.clear(); 145 | } 146 | 147 | totalWordLength += wordList->size(); 148 | 149 | wordList->append(" "); 150 | totalWordLength += 1; 151 | 152 | currentLine.append(*wordList); 153 | 154 | 155 | } 156 | 157 | //Add last line to the cache 158 | if( currentLine.size() != 0 ){ 159 | this->updateCacheText(currentLine, vertVBO, texcoordVBO, textVAO, totalText , Yoffset ); 160 | 161 | Yoffset += m_charSet.LineHeight; 162 | totalText += totalWordLength; 163 | lineNum++; 164 | currentLine.clear(); 165 | } 166 | 167 | Yoffset += m_charSet.LineHeight; 168 | } 169 | 170 | return 0; 171 | } 172 | 173 | GLuint GUIFont::updateCacheText( std::string text, GLuint vertVBO, GLuint texcoordVBO, GLuint textVAO , int updateLocation, int CurY, int CurX ) { 174 | 175 | std::vector vertData; 176 | std::vector texcoordData; 177 | 178 | textListFill( text, vertData, texcoordData, CurY , CurX ); 179 | 180 | glBindBuffer(GL_ARRAY_BUFFER, vertVBO); 181 | glBufferSubData( GL_ARRAY_BUFFER , updateLocation*sizeof(float)*12, vertData.size()*sizeof(float), &vertData[0] ); 182 | 183 | glBindBuffer(GL_ARRAY_BUFFER, texcoordVBO); 184 | glBufferSubData( GL_ARRAY_BUFFER , updateLocation*sizeof(float)*12, texcoordData.size()*sizeof(float), &texcoordData[0] ); 185 | 186 | return 0; 187 | } 188 | 189 | void GUIFont::textListFill( std::string text, std::vector &Verts, std::vector &TexCoords , int CurY , int CurX ) { 190 | const unsigned int characters = text.size(); 191 | unsigned short CharX, CharY; 192 | unsigned short Width, Height; 193 | float OffsetX, OffsetY; 194 | float XAdvance; 195 | 196 | for( unsigned int i = 0; i < characters; ++i ) 197 | { 198 | CharX = m_charSet.Chars[text[i]].x; 199 | CharY = m_charSet.Chars[text[i]].y; 200 | Width = m_charSet.Chars[text[i]].Width; 201 | Height = m_charSet.Chars[text[i]].Height; 202 | OffsetX = m_charSet.Chars[text[i]].XOffset; 203 | OffsetY = m_charSet.Chars[text[i]].YOffset; 204 | 205 | //TRIANGLE ONE 206 | //upper right 207 | TexCoords.push_back((float) (CharX+Width) / (float) m_charSet.Width); 208 | TexCoords.push_back((float) (m_charSet.Height - (CharY)) / (float) m_charSet.Height); 209 | Verts.push_back((float) (Width + CurX + OffsetX) / 800.0f); 210 | Verts.push_back((float) (float)(Height - CurY) / 600.0f); 211 | //upper left 212 | TexCoords.push_back((float) CharX / (float) m_charSet.Width); 213 | TexCoords.push_back((float) (m_charSet.Height - (CharY)) / (float) m_charSet.Height); 214 | Verts.push_back((float) (CurX + OffsetX) / 800.0f ); 215 | Verts.push_back((float) (float)(Height - CurY) / 600.0f); 216 | //lower left 217 | TexCoords.push_back((float) CharX / (float) m_charSet.Width); 218 | TexCoords.push_back((float) (m_charSet.Height-(CharY+Height)) / (float) m_charSet.Height); 219 | Verts.push_back((float) (CurX + OffsetX) / 800.0f) ; 220 | Verts.push_back((float) -CurY / 600.0f); 221 | 222 | //TRIANGLE TWO 223 | //lower right 224 | TexCoords.push_back((float) (CharX+Width) / (float) m_charSet.Width); 225 | TexCoords.push_back((float) (m_charSet.Height-(CharY+Height))/ (float) m_charSet.Height); 226 | Verts.push_back((float) (Width + CurX + OffsetX) / 800.0f); 227 | Verts.push_back((float)-CurY / 600.0f); 228 | //upper right 229 | TexCoords.push_back((float) (CharX+Width) / (float) m_charSet.Width); 230 | TexCoords.push_back((float) (m_charSet.Height - (CharY)) / (float) m_charSet.Height); 231 | Verts.push_back((float) (Width + CurX + OffsetX) / 800.0f ); 232 | Verts.push_back((float) (float)(Height - CurY) / 600.0f ); 233 | //lower left 234 | TexCoords.push_back((float) CharX / (float) m_charSet.Width); 235 | TexCoords.push_back((float) (m_charSet.Height-(CharY+Height)) / (float) m_charSet.Height); 236 | Verts.push_back((float) (CurX + OffsetX) / 800.0f ); 237 | Verts.push_back((float) -CurY/ 600.0f); 238 | 239 | 240 | 241 | CurX += m_charSet.Chars[text[i]].XAdvance; 242 | } 243 | } 244 | 245 | bool GUIFont::parseFont( std::istream& Stream ) { 246 | std::string Line; 247 | std::string Read, Key, Value; 248 | std::size_t i; 249 | while( !Stream.eof() ) 250 | { 251 | std::stringstream LineStream; 252 | std::getline( Stream, Line ); 253 | LineStream << Line; 254 | 255 | //read the line's type 256 | LineStream >> Read; 257 | if( Read == "common" ) 258 | { 259 | //this holds common data 260 | while( !LineStream.eof() ) 261 | { 262 | std::stringstream Converter; 263 | LineStream >> Read; 264 | i = Read.find( '=' ); 265 | Key = Read.substr( 0, i ); 266 | Value = Read.substr( i + 1 ); 267 | 268 | //assign the correct value 269 | Converter << Value; 270 | if( Key == "lineHeight" ) 271 | Converter >> m_charSet.LineHeight; 272 | else if( Key == "base" ) 273 | Converter >> m_charSet.Base; 274 | else if( Key == "scaleW" ) 275 | Converter >> m_charSet.Width; 276 | else if( Key == "scaleH" ) 277 | Converter >> m_charSet.Height; 278 | else if( Key == "pages" ) 279 | Converter >> m_charSet.Pages; 280 | } 281 | } 282 | else if( Read == "char" ) 283 | { 284 | //this is data for a specific char 285 | unsigned short CharID = 0; 286 | 287 | while( !LineStream.eof() ) 288 | { 289 | std::stringstream Converter; 290 | LineStream >> Read; 291 | i = Read.find( '=' ); 292 | Key = Read.substr( 0, i ); 293 | Value = Read.substr( i + 1 ); 294 | 295 | //assign the correct value 296 | Converter << Value; 297 | if( Key == "id" ) 298 | Converter >> CharID; 299 | else if( Key == "x" ) 300 | Converter >> m_charSet.Chars[CharID].x; 301 | else if( Key == "y" ) 302 | Converter >> m_charSet.Chars[CharID].y; 303 | else if( Key == "width" ) 304 | Converter >> m_charSet.Chars[CharID].Width; 305 | else if( Key == "height" ) 306 | Converter >> m_charSet.Chars[CharID].Height; 307 | else if( Key == "xoffset" ) 308 | Converter >> m_charSet.Chars[CharID].XOffset; 309 | else if( Key == "yoffset" ) 310 | Converter >> m_charSet.Chars[CharID].YOffset; 311 | else if( Key == "xadvance" ) 312 | Converter >> m_charSet.Chars[CharID].XAdvance; 313 | else if( Key == "page" ) 314 | Converter >> m_charSet.Chars[CharID].Page; 315 | } 316 | } 317 | } 318 | 319 | return true; 320 | } 321 | 322 | } --------------------------------------------------------------------------------