├── 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 | 
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