Browse Source

FBO, game states

Eduardo Bart 10 years ago
parent
commit
4b2886ebec
14 changed files with 421 additions and 26 deletions
  1. 2
    0
      CMakeLists.txt
  2. 19
    4
      src/engine.cpp
  3. 9
    0
      src/engine.h
  4. 120
    0
      src/framebuffer.cpp
  5. 52
    0
      src/framebuffer.h
  6. 46
    0
      src/gamestate.h
  7. 13
    8
      src/graphics.cpp
  8. 16
    3
      src/graphics.h
  9. 12
    1
      src/main.cpp
  10. 67
    0
      src/menustate.cpp
  11. 47
    0
      src/menustate.h
  12. 11
    8
      src/texture.cpp
  13. 6
    1
      src/texture.h
  14. 1
    1
      src/textureloader.cpp

+ 2
- 0
CMakeLists.txt View File

@@ -50,6 +50,8 @@ ENDIF(CMAKE_BUILD_TYPE STREQUAL "Debug")
50 50
 
51 51
 # find sources
52 52
 SET(SOURCES
53
+    src/menustate.cpp
54
+    src/framebuffer.cpp
53 55
     src/textureloader.cpp
54 56
     src/texture.cpp
55 57
     src/texturemanager.cpp

+ 19
- 4
src/engine.cpp View File

@@ -29,13 +29,15 @@
29 29
 #include "input.h"
30 30
 #include "configmanager.h"
31 31
 #include "logger.h"
32
+#include "gamestate.h"
32 33
 
33 34
 Engine g_engine;
34 35
 
35 36
 Engine::Engine() :
36 37
     m_stopping(false),
37 38
     m_running(false),
38
-    m_lastFrameTicks(0)
39
+    m_lastFrameTicks(0),
40
+    m_currentState(NULL)
39 41
 {
40 42
 }
41 43
 
@@ -108,20 +110,32 @@ void Engine::stop()
108 110
     m_stopping = true;
109 111
 }
110 112
 
113
+void Engine::changeState(GameState* newState)
114
+{
115
+    if(m_currentState)
116
+        m_currentState->onLeave();
117
+    m_currentState = newState;
118
+    m_currentState->onEnter();
119
+}
120
+
111 121
 void Engine::render()
112 122
 {
113 123
     g_graphics.beginRender();
124
+    if(m_currentState)
125
+        m_currentState->render();
114 126
     g_graphics.endRender();
115 127
 }
116 128
 
117 129
 void Engine::update(int elapsedTicks)
118 130
 {
119
-
131
+    if(m_currentState)
132
+        m_currentState->update(elapsedTicks);
120 133
 }
121 134
 
122 135
 void Engine::onClose()
123 136
 {
124
-    stop();
137
+    if(m_currentState)
138
+        m_currentState->onClose();
125 139
 }
126 140
 
127 141
 void Engine::onResize(int width, int height)
@@ -131,5 +145,6 @@ void Engine::onResize(int width, int height)
131 145
 
132 146
 void Engine::onInputEvent(InputEvent *event)
133 147
 {
134
-
148
+    if(m_currentState)
149
+        m_currentState->onInputEvent(event);
135 150
 }

+ 9
- 0
src/engine.h View File

@@ -27,6 +27,8 @@
27 27
 
28 28
 struct InputEvent;
29 29
 
30
+class GameState;
31
+
30 32
 class Engine
31 33
 {
32 34
 public:
@@ -38,8 +40,13 @@ public:
38 40
 
39 41
     /// Main loop
40 42
     void run();
43
+
44
+    /// Stops main loop
41 45
     void stop();
42 46
 
47
+    /// Change current game state
48
+    void changeState(GameState *newState);
49
+
43 50
     bool isRunning() const { return m_running; }
44 51
     bool isStopping() const { return m_stopping; }
45 52
 
@@ -60,6 +67,8 @@ private:
60 67
     bool m_running;
61 68
 
62 69
     unsigned long m_lastFrameTicks;
70
+
71
+    GameState *m_currentState;
63 72
 };
64 73
 
65 74
 extern Engine g_engine;

+ 120
- 0
src/framebuffer.cpp View File

@@ -0,0 +1,120 @@
1
+/* The MIT License
2
+ *
3
+ * Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in
13
+ * all copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ * THE SOFTWARE.
22
+ */
23
+
24
+#define GL_GLEXT_PROTOTYPES
25
+
26
+#include "framebuffer.h"
27
+
28
+#include <GL/glext.h>
29
+#include <GL/glu.h>
30
+#include "platform.h"
31
+#include "graphics.h"
32
+
33
+FrameBuffer::FrameBuffer(int width, int height) :
34
+    m_fbo(0)
35
+{
36
+    m_width = width;
37
+    m_height = height;
38
+
39
+    // texture where the framebuffer will be store
40
+    m_frameTexture = TexturePtr(new Texture(width, height, 4));
41
+
42
+    // we want a smooth framebuffer
43
+    m_frameTexture->enableBilinearFilter();
44
+
45
+    // use FBO only if supported
46
+    if(Platform::isExtensionSupported("EXT_framebuffer_object")) {
47
+        m_fallbackOldImp = false;
48
+
49
+        // generate FBO
50
+        glGenFramebuffersEXT(1, &m_fbo);
51
+        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
52
+
53
+        // attach 2D texture to this FBO
54
+        glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, m_frameTexture->getTextureId(), 0);
55
+
56
+        // must be called before checking
57
+        glDrawBuffer(GL_NONE);
58
+        glReadBuffer(GL_NONE);
59
+
60
+        GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
61
+        switch(status) {
62
+            case GL_FRAMEBUFFER_COMPLETE_EXT:
63
+                //ok
64
+                break;
65
+            default:
66
+                m_fallbackOldImp = true;
67
+                break;
68
+        }
69
+    } else {
70
+        // otherwise fallback to copy texture from screen implementation
71
+        m_fallbackOldImp = true;
72
+    }
73
+}
74
+
75
+FrameBuffer::~FrameBuffer()
76
+{
77
+    if(m_fbo)
78
+        glDeleteFramebuffersEXT(1, &m_fbo);
79
+}
80
+
81
+void FrameBuffer::bind()
82
+{
83
+    if(!m_fallbackOldImp) {
84
+        // bind framebuffer
85
+        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
86
+
87
+        // must be called before rendering to framebuffer
88
+        glDrawBuffer(GL_NONE);
89
+        glReadBuffer(GL_NONE);
90
+    }
91
+
92
+    // clear framebuffer
93
+    glClearColor(0.0, 0.0, 0.0, 0.0);
94
+    glClear(GL_COLOR_BUFFER_BIT);
95
+
96
+    // setup framebuffer viewport
97
+    g_graphics.setViewport(m_width, m_height);
98
+}
99
+
100
+void FrameBuffer::unbind()
101
+{
102
+    if(!m_fallbackOldImp) {
103
+        // bind back buffer again
104
+        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
105
+
106
+        // must be called to render to back buffer again
107
+        glDrawBuffer(GL_BACK);
108
+        glReadBuffer(GL_BACK);
109
+    } else {
110
+        // copy screen to texture
111
+        m_frameTexture->copyFromScreen(0, 0, 0, 0, m_width, m_height);
112
+
113
+        // clear screen
114
+        glClearColor(0.0, 0.0, 0.0, 0.0);
115
+        glClear(GL_COLOR_BUFFER_BIT);
116
+    }
117
+
118
+    // restore graphics viewport
119
+    g_graphics.restoreViewport();
120
+}

+ 52
- 0
src/framebuffer.h View File

@@ -0,0 +1,52 @@
1
+/* The MIT License
2
+ *
3
+ * Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in
13
+ * all copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ * THE SOFTWARE.
22
+ */
23
+
24
+
25
+#ifndef FRAMEBUFFER_H
26
+#define FRAMEBUFFER_H
27
+
28
+#include "texture.h"
29
+
30
+class FrameBuffer
31
+{
32
+    FrameBuffer(int width, int height);
33
+    virtual ~FrameBuffer();
34
+
35
+    /// Return the texture where everything was drawn
36
+    TexturePtr getFramebufferTexture();
37
+
38
+    /// Bind the framebuffer, everything rendered will be draw on it
39
+    void bind();
40
+
41
+    /// Unbind the framebuffer, render on back buffer again
42
+    void unbind();
43
+
44
+private:
45
+    TexturePtr m_frameTexture;
46
+    GLuint m_fbo;
47
+    bool m_fallbackOldImp;
48
+    int m_width;
49
+    int m_height;
50
+};
51
+
52
+#endif // FRAMEBUFFER_H

+ 46
- 0
src/gamestate.h View File

@@ -0,0 +1,46 @@
1
+/* The MIT License
2
+ *
3
+ * Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in
13
+ * all copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ * THE SOFTWARE.
22
+ */
23
+
24
+
25
+#ifndef GAMESTATE_H
26
+#define GAMESTATE_H
27
+
28
+struct InputEvent;
29
+
30
+class GameState
31
+{
32
+public:
33
+    GameState() { }
34
+    virtual ~GameState() { }
35
+
36
+    virtual void onEnter() = 0;
37
+    virtual void onLeave() = 0;
38
+
39
+    virtual void onClose() = 0;
40
+    virtual void onInputEvent(InputEvent *event) = 0;
41
+
42
+    virtual void render() = 0;
43
+    virtual void update(int elapsedTicks) = 0;
44
+};
45
+
46
+#endif // GAMESTATE_H

+ 13
- 8
src/graphics.cpp View File

@@ -24,11 +24,9 @@
24 24
 
25 25
 #include "graphics.h"
26 26
 #include "logger.h"
27
-#include "texturemanager.h"
28 27
 
29 28
 #include <GL/gl.h>
30 29
 #include <GL/glu.h>
31
-#include "platform.h"
32 30
 
33 31
 Graphics g_graphics;
34 32
 
@@ -60,17 +58,24 @@ void Graphics::terminate()
60 58
 }
61 59
 
62 60
 void Graphics::resize(int width, int height)
61
+{
62
+    m_width = width;
63
+    m_height = height;
64
+    restoreViewport();
65
+}
66
+
67
+void Graphics::setViewport(int width, int height)
63 68
 {
64 69
     // resize gl viewport
65 70
     glViewport(0, 0, width, height);
66 71
 
67 72
     /*
68
-      0,0---------0,w
69
-       |           |
70
-       |           |
71
-       |           |
72
-      h,0---------h,w
73
-    */
73
+     0 ,0---------0,w**
74
+     |           |
75
+     |           |
76
+     |           |
77
+     h,0---------h,w
78
+     */
74 79
     // setup view region like above
75 80
     glMatrixMode(GL_PROJECTION);
76 81
     glLoadIdentity();

+ 16
- 3
src/graphics.h View File

@@ -34,14 +34,27 @@ public:
34 34
     void init();
35 35
     void terminate();
36 36
 
37
-    ///Called after every window resize
37
+    /// Called after every window resize
38 38
     void resize(int width, int height);
39 39
 
40
-    ///Called before every render
40
+    /// Called before every render
41 41
     void beginRender();
42 42
 
43
-    ///Called after every render
43
+    /// Called after every render
44 44
     void endRender();
45
+
46
+    /// Restore original viewport
47
+    void restoreViewport() { setViewport(m_width, m_height); }
48
+
49
+    /// Set viewport, used by FrameBuffer
50
+    void setViewport(int width, int height);
51
+
52
+    int getWidth() { return m_width; }
53
+    int getHeight() { return m_height; }
54
+
55
+private:
56
+    int m_width;
57
+    int m_height;
45 58
 };
46 59
 
47 60
 extern Graphics g_graphics;

+ 12
- 1
src/main.cpp View File

@@ -28,9 +28,12 @@
28 28
 #include "configmanager.h"
29 29
 #include "resourcemanager.h"
30 30
 #include "platform.h"
31
+#include "menustate.h"
31 32
 
32 33
 #include <csignal>
33 34
 
35
+#include <boost/scoped_ptr.hpp>
36
+
34 37
 /// Catches signals so we can exit nicely
35 38
 void signal_handler(int sig)
36 39
 {
@@ -77,9 +80,17 @@ int main(int argc, const char *argv[])
77 80
 
78 81
     notice(APP_LONGNAME);
79 82
 
80
-    // setup the engine and run
83
+    // setup the engine
81 84
     g_engine.init();
85
+
86
+    // create initial state
87
+    boost::scoped_ptr<MenuState> menuState(new MenuState);
88
+    g_engine.changeState(menuState.get());
89
+
90
+    // run
82 91
     g_engine.run();
92
+
93
+    // terminate stuff
83 94
     g_engine.terminate();
84 95
 
85 96
     // save configurations before exiting

+ 67
- 0
src/menustate.cpp View File

@@ -0,0 +1,67 @@
1
+/* The MIT License
2
+ *
3
+ * Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in
13
+ * all copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ * THE SOFTWARE.
22
+ */
23
+
24
+
25
+#include "menustate.h"
26
+#include "framebuffer.h"
27
+#include "graphics.h"
28
+#include "texturemanager.h"
29
+
30
+MenuState::MenuState()
31
+{
32
+}
33
+
34
+MenuState::~MenuState()
35
+{
36
+
37
+}
38
+
39
+void MenuState::onEnter()
40
+{
41
+
42
+}
43
+
44
+void MenuState::onLeave()
45
+{
46
+
47
+}
48
+
49
+void MenuState::onClose()
50
+{
51
+
52
+}
53
+
54
+void MenuState::onInputEvent(InputEvent* event)
55
+{
56
+
57
+}
58
+
59
+void MenuState::render()
60
+{
61
+
62
+}
63
+
64
+void MenuState::update(int elapsedTicks)
65
+{
66
+
67
+}

+ 47
- 0
src/menustate.h View File

@@ -0,0 +1,47 @@
1
+/* The MIT License
2
+ *
3
+ * Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in
13
+ * all copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ * THE SOFTWARE.
22
+ */
23
+
24
+
25
+#ifndef MENUSTATE_H
26
+#define MENUSTATE_H
27
+
28
+#include "gamestate.h"
29
+
30
+class MenuState : public GameState
31
+{
32
+
33
+public:
34
+    MenuState();
35
+    virtual ~MenuState();
36
+
37
+    void onEnter();
38
+    void onLeave();
39
+
40
+    void onClose();
41
+    void onInputEvent(InputEvent *event);
42
+
43
+    void render();
44
+    void update(int elapsedTicks);
45
+};
46
+
47
+#endif // MENUSTATE_H

+ 11
- 8
src/texture.cpp View File

@@ -27,14 +27,13 @@
27 27
 #include <GL/gl.h>
28 28
 #include <GL/glu.h>
29 29
 
30
-Texture::Texture(int width, int height, unsigned char *pixels, int components)
30
+Texture::Texture(int width, int height, int components, unsigned char *pixels)
31 31
 {
32 32
     m_width = width;
33 33
     m_height = height;
34 34
 
35 35
     glGenTextures(1, &m_textureId);
36 36
     glBindTexture(GL_TEXTURE_2D, m_textureId);
37
-    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
38 37
 
39 38
     GLenum format = 0;
40 39
     switch(components) {
@@ -54,9 +53,6 @@ Texture::Texture(int width, int height, unsigned char *pixels, int components)
54 53
 
55 54
     glTexImage2D(GL_TEXTURE_2D, 0, components, width, height, 0, format, GL_UNSIGNED_BYTE, pixels);
56 55
 
57
-    glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
58
-    glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height);
59
-
60 56
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
61 57
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
62 58
 
@@ -70,14 +66,21 @@ Texture::~Texture()
70 66
         glDeleteTextures(1, &m_textureId);
71 67
 }
72 68
 
73
-void Texture::enableBilinearFilter()
69
+void Texture::bind()
74 70
 {
75 71
     glBindTexture(GL_TEXTURE_2D, m_textureId);
72
+}
73
+
74
+void Texture::enableBilinearFilter()
75
+{
76
+    bind();
76 77
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
77 78
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
78 79
 }
79 80
 
80
-void Texture::bind()
81
+void Texture::copyFromScreen(int xoffset, int yoffset, int x, int y, int width, int height)
81 82
 {
82
-    glBindTexture(GL_TEXTURE_2D, m_textureId);
83
+    bind();
84
+    glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, width, height);
83 85
 }
86
+

+ 6
- 1
src/texture.h View File

@@ -33,7 +33,8 @@ class TextureManager;
33 33
 class Texture
34 34
 {
35 35
 public:
36
-    Texture(int width, int height, unsigned char *pixels, int components);
36
+    /// Create a texture, width and height must be a multiple of 2
37
+    Texture(int width, int height, int components, unsigned char *pixels = NULL);
37 38
     virtual ~Texture();
38 39
 
39 40
     /// Bind texture for drawing
@@ -42,8 +43,12 @@ public:
42 43
     /// Enable texture bilinear filter (smooth scaled textures)
43 44
     void enableBilinearFilter();
44 45
 
46
+    /// Copy screen pixels to texture
47
+    void copyFromScreen(int xoffset, int yoffset, int x, int y, int width, int height);
48
+
45 49
     int getWidth() const { return m_width; }
46 50
     int getHeight() const { return m_height; }
51
+    GLuint getTextureId() const { return m_textureId; }
47 52
 
48 53
 private:
49 54
     GLuint m_textureId;

+ 1
- 1
src/textureloader.cpp View File

@@ -117,7 +117,7 @@ TexturePtr TextureLoader::loadPNG(const unsigned char *fileData, unsigned int fi
117 117
     fclose(pngFile);
118 118
     delete[] row_pointers;
119 119
 
120
-    texture = TexturePtr(new Texture(width, height, pixels, components));
120
+    texture = TexturePtr(new Texture(width, height, components, pixels));
121 121
 
122 122
     delete[] pixels;
123 123
 

Loading…
Cancel
Save