Mercurial > fife-parpg
comparison engine/core/video/opengl/renderbackendopengl.cpp @ 579:b2feacaed53c
* Added the colorbuffer patch with a small change due to SDL. Performance boost between 20-30% under OpenGL.
* Improved the most renderers with setColor() function.
* Fixed the genericrenderer, is now tested whether the images are in the viewport.
* Fixed the gridrenderer, the grid is now drawn only up to the viewport.
* Changed the vertex functions in opengl/renderbackendopengl.cpp from vertex3f() to vertex2f().
* Improved the Editor, now you can use blocking, grid and coordinate renderer over gui or keys. Additionally, the colors can be changed with the settings.xml.
author | helios2000@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sat, 31 Jul 2010 17:46:19 +0000 |
parents | ad1f09d954f9 |
children | 47b49b9b0c0a |
comparison
equal
deleted
inserted
replaced
578:54d83a0462ee | 579:b2feacaed53c |
---|---|
41 SDL_Surface* testsurface = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_SRCALPHA, 1, 1, 32, | 41 SDL_Surface* testsurface = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_SRCALPHA, 1, 1, 32, |
42 RMASK, GMASK, BMASK ,AMASK); | 42 RMASK, GMASK, BMASK ,AMASK); |
43 | 43 |
44 m_rgba_format = *(testsurface->format); | 44 m_rgba_format = *(testsurface->format); |
45 SDL_FreeSurface(testsurface); | 45 SDL_FreeSurface(testsurface); |
46 m_clear = true; | |
46 } | 47 } |
47 | 48 |
48 const std::string& RenderBackendOpenGL::getName() const { | 49 const std::string& RenderBackendOpenGL::getName() const { |
49 static std::string backend_name = "OpenGL"; | 50 static std::string backend_name = "OpenGL"; |
50 return backend_name; | 51 return backend_name; |
130 m_screen = new GLImage(screen); | 131 m_screen = new GLImage(screen); |
131 return m_screen; | 132 return m_screen; |
132 } | 133 } |
133 | 134 |
134 void RenderBackendOpenGL::startFrame() { | 135 void RenderBackendOpenGL::startFrame() { |
135 glDisable(GL_SCISSOR_TEST); | 136 if(m_clear) { |
136 glClear(GL_COLOR_BUFFER_BIT); | 137 glDisable(GL_SCISSOR_TEST); |
137 glEnable(GL_SCISSOR_TEST); | 138 glClear(GL_COLOR_BUFFER_BIT); |
139 glEnable(GL_SCISSOR_TEST); | |
140 } | |
138 } | 141 } |
139 | 142 |
140 void RenderBackendOpenGL::endFrame() { | 143 void RenderBackendOpenGL::endFrame() { |
141 SDL_GL_SwapBuffers(); | 144 SDL_GL_SwapBuffers(); |
142 } | 145 } |
174 | 177 |
175 Image* RenderBackendOpenGL::createImage(const uint8_t* data, unsigned int width, unsigned int height) { | 178 Image* RenderBackendOpenGL::createImage(const uint8_t* data, unsigned int width, unsigned int height) { |
176 return new GLImage(data, width, height); | 179 return new GLImage(data, width, height); |
177 } | 180 } |
178 | 181 |
182 void RenderBackendOpenGL::isClearNeeded(bool clear) { | |
183 m_clear = clear; | |
184 } | |
185 | |
179 bool RenderBackendOpenGL::putPixel(int x, int y, int r, int g, int b) { | 186 bool RenderBackendOpenGL::putPixel(int x, int y, int r, int g, int b) { |
180 if ((x < 0) || (x >= (int)getWidth()) || (y < 0) || (y >= (int)getHeight())) { | 187 if ((x < 0) || (x >= (int)getWidth()) || (y < 0) || (y >= (int)getHeight())) { |
181 return false; | 188 return false; |
182 } | 189 } |
183 glColor4ub(r, g, b, 255); | 190 glColor3ub(r, g, b); |
184 glBegin(GL_POINTS); | 191 glBegin(GL_POINTS); |
185 glVertex2i(x, y); | 192 glVertex2i(x, y); |
186 glEnd(); | 193 glEnd(); |
187 return true; | 194 return true; |
188 } | 195 } |
189 | 196 |
190 void RenderBackendOpenGL::drawLine(const Point& p1, const Point& p2, int r, int g, int b) { | 197 void RenderBackendOpenGL::drawLine(const Point& p1, const Point& p2, int r, int g, int b) { |
191 glColor4ub(r, g, b, 255); | 198 glColor3ub(r, g, b); |
192 glBegin(GL_LINES); | 199 glBegin(GL_LINES); |
193 glVertex3f(p1.x+0.5f, p1.y+0.5f, 0); | 200 glVertex2f(p1.x+0.5f, p1.y+0.5f); |
194 glVertex3f(p2.x+0.5f, p2.y+0.5f, 0); | 201 glVertex2f(p2.x+0.5f, p2.y+0.5f); |
195 glEnd(); | 202 glEnd(); |
196 | 203 |
197 glBegin(GL_POINTS); | 204 glBegin(GL_POINTS); |
198 glVertex3f(p2.x+0.5f, p2.y+0.5f, 0); | 205 glVertex2f(p2.x+0.5f, p2.y+0.5f); |
199 glEnd(); | 206 glEnd(); |
200 } | 207 } |
201 | 208 |
202 void RenderBackendOpenGL::drawQuad(const Point& p1, const Point& p2, const Point& p3, const Point& p4, int r, int g, int b) { | 209 void RenderBackendOpenGL::drawQuad(const Point& p1, const Point& p2, const Point& p3, const Point& p4, int r, int g, int b) { |
203 glColor4ub(r, g, b, 165); | 210 glColor4ub(r, g, b, 165); |
204 glBegin(GL_QUADS); | 211 glBegin(GL_QUADS); |
205 glVertex3f(p1.x, p1.y, 0); | 212 glVertex2f(p1.x, p1.y); |
206 glVertex3f(p2.x, p2.y, 0); | 213 glVertex2f(p2.x, p2.y); |
207 glVertex3f(p3.x, p3.y, 0); | 214 glVertex2f(p3.x, p3.y); |
208 glVertex3f(p4.x, p4.y, 0); | 215 glVertex2f(p4.x, p4.y); |
209 glEnd(); | 216 glEnd(); |
210 } | 217 } |
211 | 218 |
212 void RenderBackendOpenGL::drawVertex(const Point& p, const uint8_t size, int r, int g, int b){ | 219 void RenderBackendOpenGL::drawVertex(const Point& p, const uint8_t size, int r, int g, int b){ |
213 | |
214 GLfloat width; | 220 GLfloat width; |
215 | |
216 glGetFloatv(GL_LINE_WIDTH, &width); | 221 glGetFloatv(GL_LINE_WIDTH, &width); |
217 glLineWidth(1.0); | 222 glLineWidth(1.0); |
218 | 223 |
224 glColor3ub(r, g, b); | |
219 glBegin(GL_LINE_LOOP); | 225 glBegin(GL_LINE_LOOP); |
220 glColor4ub(r, g, b, 255); | 226 glVertex2f(p.x-size, p.y+size); |
221 | 227 glVertex2f(p.x+size, p.y+size); |
222 glVertex3f(p.x-size, p.y+size, 0); | 228 glVertex2f(p.x+size, p.y-size); |
223 glVertex3f(p.x+size, p.y+size, 0); | 229 glVertex2f(p.x-size, p.y-size); |
224 glVertex3f(p.x+size, p.y-size, 0); | |
225 glVertex3f(p.x-size, p.y-size, 0); | |
226 | |
227 glEnd(); | 230 glEnd(); |
228 | 231 |
229 glLineWidth(width); | 232 glLineWidth(width); |
230 } | 233 } |
231 } | 234 } |