36 #include "SDL_image.h" 131 static std::string backend_name =
"OpenGL";
136 Uint32 flags = SDL_INIT_VIDEO;
137 if (SDL_InitSubSystem(flags) < 0) {
138 throw SDLException(SDL_GetError());
141 if (SDL_VideoInit(driver.c_str()) < 0) {
142 throw SDLException(SDL_GetError());
147 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
148 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
151 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
152 SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
153 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
154 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
155 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
156 SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
157 SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
163 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
171 SDL_Surface *img = IMG_Load(icon.c_str());
174 SDL_FreeSurface(img);
177 SDL_SetWindowTitle(
m_window, title.c_str());
200 m_window = SDL_CreateWindow(
"", SDL_WINDOWPOS_UNDEFINED_DISPLAY(displayIndex), SDL_WINDOWPOS_UNDEFINED_DISPLAY(displayIndex), width, height, flags | SDL_WINDOW_SHOWN);
202 m_window = SDL_CreateWindow(
"", SDL_WINDOWPOS_CENTERED_DISPLAY(displayIndex), SDL_WINDOWPOS_CENTERED_DISPLAY(displayIndex), width, height, flags | SDL_WINDOW_SHOWN);
206 throw SDLException(SDL_GetError());
209 SDL_DisplayMode displayMode;
211 displayMode.w = width;
212 displayMode.h = height;
214 if (SDL_SetWindowDisplayMode(
m_window, &displayMode) != 0) {
215 throw SDLException(SDL_GetError());
221 throw SDLException(SDL_GetError());
230 throw SDLException(SDL_GetError());
234 glewExperimental = GL_TRUE;
235 GLenum glewError = glewInit();
236 if (glewError != GLEW_OK) {
237 FL_LOG(
_log,
LMsg(
"RenderBackendOpenGL") <<
"Error initializing GLEW!" << glewGetErrorString(glewError));
241 <<
"Videomode " << width <<
"x" << height
242 <<
" at " << int32_t(bitsPerPixel) <<
" bpp with " << displayMode.refresh_rate <<
" Hz");
247 if (bitsPerPixel != 16) {
262 glViewport(0, 0, width, height);
263 glMatrixMode(GL_PROJECTION);
265 glOrtho(0, width, height, 0, -100, 100);
266 glMatrixMode(GL_MODELVIEW);
269 glEnable(GL_CULL_FACE);
273 glPixelStorei(GL_PACK_ALIGNMENT, 1);
274 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
278 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
284 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
288 glEnable(GL_DEPTH_TEST);
289 glDepthFunc(GL_LEQUAL);
291 glEnable(GL_SCISSOR_TEST);
293 glEnableClientState(GL_COLOR_ARRAY);
294 glEnableClientState(GL_VERTEX_ARRAY);
306 if (GLEW_EXT_texture_filter_anisotropic) {
308 glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &largest);
318 SDL_GL_SetSwapInterval(static_cast<uint8_t>(
m_vSync));
327 for(std::vector<uint32_t>::size_type i = 0; i !=
m_indices.size(); i+=6) {
360 return new GLImage(name, loader);
370 if (32 == surface->format->BitsPerPixel
389 SDL_Surface* conv = SDL_ConvertSurface(surface, &
m_rgba_format, 0);
393 SDL_FreeSurface(surface);
404 if (32 == surface->format->BitsPerPixel
418 return new GLImage(name, surface);
423 SDL_Surface* conv = SDL_ConvertSurface(surface, &
m_rgba_format, 0);
427 SDL_FreeSurface(surface);
432 return new GLImage(data, width, height);
436 return new GLImage(name, data, width, height);
443 glDisable(GL_COLOR_MATERIAL);
444 }
else if (lighting != 0) {
447 glColorMaterial(GL_FRONT, GL_DIFFUSE);
448 glEnable(GL_COLOR_MATERIAL);
462 glActiveTexture(GL_TEXTURE0 + texUnit);
466 glClientActiveTexture(GL_TEXTURE0 + texUnit);
470 glEnable(GL_TEXTURE_2D);
471 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
479 glActiveTexture(GL_TEXTURE0 + texUnit);
483 glClientActiveTexture(GL_TEXTURE0 + texUnit);
487 glDisable(GL_TEXTURE_2D);
488 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
498 glActiveTexture(GL_TEXTURE0 + texUnit);
502 glClientActiveTexture(GL_TEXTURE0 + texUnit);
505 glBindTexture(GL_TEXTURE_2D, texId);
512 glBindTexture(GL_TEXTURE_2D, texId);
518 glEnable(GL_LIGHTING);
525 glDisable(GL_LIGHTING);
532 GLfloat lightDiffuse[] = {red, green, blue, 1.0f};
533 glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse);
545 glEnable(GL_STENCIL_TEST);
552 glDisable(GL_STENCIL_TEST);
574 glClearStencil(buffer);
577 glClear(GL_STENCIL_BUFFER_BIT);
587 glEnable(GL_ALPHA_TEST);
594 glDisable(GL_ALPHA_TEST);
603 glAlphaFunc(GL_GREATER, ref_alpha);
609 glEnable(GL_DEPTH_TEST);
616 glDisable(GL_DEPTH_TEST);
623 glEnableClientState(GL_COLOR_ARRAY);
630 glDisableClientState(GL_COLOR_ARRAY);
631 glColor4ub(255,255,255,255);
648 glActiveTexture(GL_TEXTURE0 + texUnit);
650 glClientActiveTexture(GL_TEXTURE0 + texUnit);
653 glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, rgbaf);
661 glVertexPointer(size, GL_FLOAT, stride, ptr);
668 glColorPointer(4, GL_UNSIGNED_BYTE, stride, ptr);
676 glActiveTexture(GL_TEXTURE0 + texUnit);
680 glClientActiveTexture(GL_TEXTURE0 + texUnit);
683 glTexCoordPointer(2, GL_FLOAT, stride, ptr);
690 glEnable(GL_SCISSOR_TEST);
697 glDisable(GL_SCISSOR_TEST);
706 case 0 : src_fact = GL_ZERO;
break;
707 case 1 : src_fact = GL_ONE;
break;
708 case 2 : src_fact = GL_DST_COLOR;
break;
709 case 3 : src_fact = GL_ONE_MINUS_DST_COLOR;
break;
710 case 4 : src_fact = GL_SRC_ALPHA;
break;
711 case 5 : src_fact = GL_ONE_MINUS_SRC_ALPHA;
break;
712 case 6 : src_fact = GL_DST_ALPHA;
break;
713 case 7 : src_fact = GL_ONE_MINUS_DST_ALPHA;
break;
715 default : src_fact = GL_DST_COLOR;
break;
719 case 0 : dst_fact = GL_ZERO;
break;
720 case 1 : dst_fact = GL_ONE;
break;
721 case 2 : dst_fact = GL_SRC_COLOR;
break;
722 case 3 : dst_fact = GL_ONE_MINUS_SRC_COLOR;
break;
723 case 4 : dst_fact = GL_SRC_ALPHA;
break;
724 case 5 : dst_fact = GL_ONE_MINUS_SRC_ALPHA;
break;
725 case 6 : dst_fact = GL_DST_ALPHA;
break;
726 case 7 : dst_fact = GL_ONE_MINUS_DST_ALPHA;
break;
728 default : dst_fact = GL_SRC_ALPHA;
break;
734 glBlendFunc(src_fact, dst_fact);
745 while (count != elements) {
769 while (count != elements) {
794 bool texture =
false;
795 bool blending =
false;
797 bool stencil =
false;
803 GLenum mode = GL_TRIANGLES;
820 int32_t index2TC = 0;
827 int32_t* currentIndex = 0;
851 currentIndex = &indexT;
852 currentElements = &elementsT;
861 currentIndex = &indexTC;
862 currentElements = &elementsTC;
870 currentIndex = &indexP;
871 currentElements = &elementsP;
880 currentIndex = &index2TC;
881 currentElements = &elements2TC;
888 if (ro.
mode != mode) {
891 }
else if (ro.
mode == GL_LINE_STRIP || ro.
mode == GL_LINE_LOOP) {
909 if (ro.
src != src || ro.
dst != dst) {
932 if (*currentElements > 0) {
934 glDrawElements(mode, *currentElements, GL_UNSIGNED_INT, indexBuffer + *currentIndex);
935 *currentIndex += *currentElements;
952 currentElements = &elementsTC;
953 currentIndex = &indexTC;
958 currentElements = &elementsP;
959 currentIndex = &indexP;
968 currentElements = &elementsT;
969 currentIndex = &indexT;
989 currentElements = &elementsTC;
990 currentIndex = &indexTC;
995 currentIndex = &indexT;
996 currentElements = &elementsT;
1002 currentElements = &elementsP;
1003 currentIndex = &indexP;
1022 currentElements = &elements2TC;
1023 currentIndex = &index2TC;
1040 currentElements = &elements2TC;
1041 currentIndex = &index2TC;
1058 currentElements = &elements2TC;
1059 currentIndex = &index2TC;
1077 currentElements = &elementsTC;
1078 currentIndex = &indexTC;
1083 currentElements = &elementsT;
1084 currentIndex = &indexT;
1094 currentElements = &elementsP;
1095 currentIndex = &indexP;
1102 *currentElements = ro.
size;
1138 *currentElements += ro.
size;
1142 glDrawElements(mode, *currentElements, GL_UNSIGNED_INT, indexBuffer + *currentIndex);
1187 int32_t* currentIndex = &index;
1188 uint32_t* currentElements = &elements;
1200 if (*currentElements > 0) {
1202 glDrawElements(GL_TRIANGLES, *currentElements, GL_UNSIGNED_INT, &
m_indices[*currentIndex]);
1203 *currentIndex += *currentElements;
1215 *currentElements = 6;
1218 *currentElements += 6;
1223 glDrawElements(GL_TRIANGLES, *currentElements, GL_UNSIGNED_INT, &
m_indices[*currentIndex]);
1253 glDrawArrays(GL_QUADS, iter->index, iter->elements);
1281 int32_t* currentIndex = &index;
1282 uint32_t* currentElements = &elements;
1294 if (*currentElements > 0) {
1296 glDrawElements(GL_TRIANGLES, *currentElements, GL_UNSIGNED_INT, &
m_indices[*currentIndex]);
1297 *currentIndex += *currentElements;
1309 *currentElements = 6;
1312 *currentElements += 6;
1317 glDrawElements(GL_TRIANGLES, *currentElements, GL_UNSIGNED_INT, &
m_indices[*currentIndex]);
1332 bool texture =
false;
1333 bool render =
false;
1359 int32_t* currentIndex = &index;
1360 uint32_t* currentElements = &elements;
1383 if (*currentElements > 0) {
1385 glDrawElements(GL_TRIANGLES, *currentElements, GL_UNSIGNED_INT, &
m_indices[*currentIndex]);
1386 *currentIndex += *currentElements;
1445 *currentElements = ro.
size;
1449 *currentElements += ro.
size;
1453 glDrawElements(GL_TRIANGLES, *currentElements, GL_UNSIGNED_INT, &
m_indices[*currentIndex]);
1492 if ((x < 0) || (x >= (int32_t)
m_target->w) ||
1493 (y < 0) || (y >= (int32_t)
m_target->h)) {
1497 rd.
vertex[0] =
static_cast<float>(x)+0.375;
1498 rd.
vertex[1] =
static_cast<float>(y)+0.375;
1515 rd.
vertex[0] =
static_cast<float>(p1.
x)+0.375;
1516 rd.
vertex[1] =
static_cast<float>(p1.
y)+0.375;
1523 rd.
vertex[0] =
static_cast<float>(p2.
x)+0.375;
1524 rd.
vertex[1] =
static_cast<float>(p2.
y)+0.375;
1535 float xDiff = p2.
x - p1.
x;
1536 float yDiff = p2.
y - p1.
y;
1537 float halfW =
static_cast<float>(width) / 2.0;
1541 }
else if (angle > 360.0) {
1549 rd.
vertex[0] =
static_cast<float>(p1.
x) + cornerX;
1550 rd.
vertex[1] =
static_cast<float>(p1.
y) + cornerY;
1556 rd.
vertex[0] =
static_cast<float>(p2.
x) + cornerX;
1557 rd.
vertex[1] =
static_cast<float>(p2.
y) + cornerY;
1559 rd.
vertex[0] =
static_cast<float>(p2.
x) - cornerX;
1560 rd.
vertex[1] =
static_cast<float>(p2.
y) - cornerY;
1562 rd.
vertex[0] =
static_cast<float>(p1.
x) - cornerX;
1563 rd.
vertex[1] =
static_cast<float>(p1.
y) - cornerY;
1567 uint32_t indices[] = { index, index + 1, index + 2, index, index + 2, index + 3 };
1575 if (points.size() < 2) {
1578 std::vector<Point>::const_iterator it = points.begin();
1582 for (; it != points.end(); ++it) {
1594 for (; it != points.end(); ++it) {
1595 rd.
vertex[0] =
static_cast<float>((*it).x);
1596 rd.
vertex[1] =
static_cast<float>((*it).y);
1606 if (points.size() < 2) {
1609 int32_t elements = points.size();
1610 if (elements < 3 || steps < 2) {
1614 bool thick = width > 1;
1615 float step = 1.0 /
static_cast<float>(steps-1);
1619 for (int32_t i = 0; i <= (elements*steps); ++i) {
1633 for (int32_t i = 0; i <= (elements*steps); ++i) {
1636 rd.
vertex[0] =
static_cast<float>(old.
x);
1637 rd.
vertex[1] =
static_cast<float>(old.
y);
1649 rd.
vertex[0] =
static_cast<float>(p1.
x);
1650 rd.
vertex[1] =
static_cast<float>(p1.
y);
1657 rd.
vertex[0] =
static_cast<float>(p2.
x);
1658 rd.
vertex[1] =
static_cast<float>(p2.
y);
1661 rd.
vertex[0] =
static_cast<float>(p3.
x);
1662 rd.
vertex[1] =
static_cast<float>(p3.
y);
1666 uint32_t indices[] = { index, index + 1, index + 2 };
1675 rd.
vertex[0] =
static_cast<float>(p.
x);
1676 rd.
vertex[1] =
static_cast<float>(p.
y);
1683 rd.
vertex[0] =
static_cast<float>(p.
x+w);
1686 rd.
vertex[1] =
static_cast<float>(p.
y+h);
1689 rd.
vertex[0] =
static_cast<float>(p.
x);
1693 uint32_t indices[] = { index, index + 1, index + 2, index + 3 };
1702 rd.
vertex[0] =
static_cast<float>(p.
x);
1703 rd.
vertex[1] =
static_cast<float>(p.
y);
1710 rd.
vertex[1] =
static_cast<float>(p.
y+h);
1713 rd.
vertex[0] =
static_cast<float>(p.
x+w);
1716 rd.
vertex[1] =
static_cast<float>(p.
y);
1720 uint32_t indices[] = { index, index + 1, index + 2, index, index + 2, index + 3 };
1729 rd.
vertex[0] =
static_cast<float>(p1.
x);
1730 rd.
vertex[1] =
static_cast<float>(p1.
y);
1737 rd.
vertex[0] =
static_cast<float>(p2.
x);
1738 rd.
vertex[1] =
static_cast<float>(p2.
y);
1741 rd.
vertex[0] =
static_cast<float>(p3.
x);
1742 rd.
vertex[1] =
static_cast<float>(p3.
y);
1745 rd.
vertex[0] =
static_cast<float>(p4.
x);
1746 rd.
vertex[1] =
static_cast<float>(p4.
y);
1750 uint32_t indices[] = { index, index + 1, index + 2, index, index + 2, index + 3 };
1759 rd.
vertex[0] =
static_cast<float>(p.
x-size);
1760 rd.
vertex[1] =
static_cast<float>(p.
y+size);
1767 rd.
vertex[0] =
static_cast<float>(p.
x+size);
1770 rd.
vertex[1] =
static_cast<float>(p.
y-size);
1773 rd.
vertex[0] =
static_cast<float>(p.
x-size);
1777 uint32_t indices[] = { index, index + 1, index + 2, index + 3 };
1786 int32_t subdivisions = round(
Mathf::pi() / ( 5.0 / (2.0 * radius)));
1787 if (subdivisions < 12) {
1798 for (
uint16_t i = 0; i < subdivisions-1; ++i) {
1812 int32_t subdivisions = round(
Mathf::pi() / ( 5.0 / (2.0 * radius)));
1813 if (subdivisions < 12) {
1823 rd.
vertex[0] =
static_cast<float>(p.
x);
1824 rd.
vertex[1] =
static_cast<float>(p.
y);
1831 for (
uint16_t i = 0; i <= subdivisions; ++i) {
1837 uint32_t indices[] = { index, lastIndex, ++lastIndex };
1846 int32_t elements = 0;
1847 int32_t s = (sangle + 360) % 360;
1848 int32_t e = (eangle + 360) % 360;
1861 float angle =
static_cast<float>(s) * step;
1862 for (;s <= e; ++s, angle += step, ++elements) {
1875 int32_t s = (sangle + 360) % 360;
1876 int32_t e = (eangle + 360) % 360;
1888 rd.
vertex[0] =
static_cast<float>(p.
x);
1889 rd.
vertex[1] =
static_cast<float>(p.
y);
1895 int32_t elements = 0;
1897 float angle =
static_cast<float>(e) * step;
1898 for (;s <= e; ++s, angle -= step, ++elements) {
1904 uint32_t indices[] = { index, lastIndex, ++lastIndex };
1919 rd.
vertex[0] =
static_cast<float>(p.
x);
1920 rd.
vertex[1] =
static_cast<float>(p.
y);
1922 rd.
color[1] = green;
1924 rd.
color[3] = intensity;
1926 for (
float angle = 0; angle <=
Mathf::twoPi(); angle += step, elements += 3) {
1939 uint32_t indices[] = { index, ++lastIndex, ++lastIndex };
1950 if (alpha == 255 && !rgba) {
1952 rd.
vertex[0] =
static_cast<float>(rect.
x);
1953 rd.
vertex[1] =
static_cast<float>(rect.
y);
1954 rd.
texel[0] = st[0];
1955 rd.
texel[1] = st[1];
1958 rd.
vertex[0] =
static_cast<float>(rect.
x);
1959 rd.
vertex[1] =
static_cast<float>(rect.
y+rect.
h);
1960 rd.
texel[1] = st[3];
1963 rd.
vertex[0] =
static_cast<float>(rect.
x+rect.
w);
1964 rd.
vertex[1] =
static_cast<float>(rect.
y+rect.
h);
1965 rd.
texel[0] = st[2];
1968 rd.
vertex[0] =
static_cast<float>(rect.
x+rect.
w);
1969 rd.
vertex[1] =
static_cast<float>(rect.
y);
1970 rd.
texel[1] = st[1];
1976 uint32_t indices[] = { index, index + 1, index + 2, index, index + 2, index + 3 };
1981 rd.
vertex[0] =
static_cast<float>(rect.
x);
1982 rd.
vertex[1] =
static_cast<float>(rect.
y);
1983 rd.
texel[0] = st[0];
1984 rd.
texel[1] = st[1];
1990 rd.
color[3] = alpha;
1993 rd.
vertex[0] =
static_cast<float>(rect.
x);
1994 rd.
vertex[1] =
static_cast<float>(rect.
y+rect.
h);
1995 rd.
texel[1] = st[3];
1999 rd.
vertex[0] =
static_cast<float>(rect.
x+rect.
w);
2000 rd.
vertex[1] =
static_cast<float>(rect.
y+rect.
h);
2001 rd.
texel[0] = st[2];
2005 rd.
vertex[0] =
static_cast<float>(rect.
x+rect.
w);
2006 rd.
vertex[1] =
static_cast<float>(rect.
y);
2007 rd.
texel[1] = st[1];
2013 ro.
rgba[0] = rgba[0];
2014 ro.
rgba[1] = rgba[1];
2015 ro.
rgba[2] = rgba[2];
2016 ro.
rgba[3] = rgba[3];
2019 uint32_t indices[] = { index, index + 1, index + 2, index, index + 2, index + 3 };
2024 rd.
vertex[0] =
static_cast<float>(rect.
x);
2025 rd.
vertex[1] =
static_cast<float>(rect.
y);
2026 rd.
texel[0] = st[0];
2027 rd.
texel[1] = st[1];
2031 rd.
color[3] = alpha;
2034 rd.
vertex[0] =
static_cast<float>(rect.
x);
2035 rd.
vertex[1] =
static_cast<float>(rect.
y+rect.
h);
2036 rd.
texel[1] = st[3];
2039 rd.
vertex[0] =
static_cast<float>(rect.
x+rect.
w);
2040 rd.
vertex[1] =
static_cast<float>(rect.
y+rect.
h);
2041 rd.
texel[0] = st[2];
2044 rd.
vertex[0] =
static_cast<float>(rect.
x+rect.
w);
2045 rd.
vertex[1] =
static_cast<float>(rect.
y);
2046 rd.
texel[1] = st[1];
2052 uint32_t indices[] = { index, index + 1, index + 2, index, index + 2, index + 3 };
2062 rd.
vertex[0] =
static_cast<float>(rect.
x);
2063 rd.
vertex[1] =
static_cast<float>(rect.
y);
2064 rd.
texel[0] = st1[0];
2065 rd.
texel[1] = st1[1];
2071 rd.
color[3] = alpha;
2074 rd.
vertex[0] =
static_cast<float>(rect.
x);
2075 rd.
vertex[1] =
static_cast<float>(rect.
y+rect.
h);
2076 rd.
texel[1] = st1[3];
2080 rd.
vertex[0] =
static_cast<float>(rect.
x+rect.
w);
2081 rd.
vertex[1] =
static_cast<float>(rect.
y+rect.
h);
2082 rd.
texel[0] = st1[2];
2086 rd.
vertex[0] =
static_cast<float>(rect.
x+rect.
w);
2087 rd.
vertex[1] =
static_cast<float>(rect.
y);
2088 rd.
texel[1] = st1[1];
2093 uint32_t indices[] = { index, index + 1, index + 2, index, index + 2, index + 3 };
2098 ro.
rgba[0] = rgba[0];
2099 ro.
rgba[1] = rgba[1];
2100 ro.
rgba[2] = rgba[2];
2101 ro.
rgba[3] = rgba[3];
2108 if (it->texture_id == texture_id) {
2109 if (it->elements < it->max_size - 4) {
2114 int32_t max_quads_per_texbatch = 1000;
2124 obj.
max_size = max_quads_per_texbatch * 4;
2132 if (alpha == 255 && !rgba) {
2167 rd.
vertex[0] =
static_cast<float>(rect.
x);
2168 rd.
vertex[1] =
static_cast<float>(rect.
y);
2170 rd.
texel[0] = st[0];
2171 rd.
texel[1] = st[1];
2174 rd.
vertex[0] =
static_cast<float>(rect.
x);
2175 rd.
vertex[1] =
static_cast<float>(rect.
y+rect.
h);
2176 rd.
texel[1] = st[3];
2179 rd.
vertex[0] =
static_cast<float>(rect.
x+rect.
w);
2180 rd.
vertex[1] =
static_cast<float>(rect.
y+rect.
h);
2181 rd.
texel[0] = st[2];
2184 rd.
vertex[0] =
static_cast<float>(rect.
x+rect.
w);
2185 rd.
vertex[1] =
static_cast<float>(rect.
y);
2186 rd.
texel[1] = st[1];
2196 rd.
vertex[0] =
static_cast<float>(rect.
x);
2197 rd.
vertex[1] =
static_cast<float>(rect.
y);
2199 rd.
texel[0] = st[0];
2200 rd.
texel[1] = st[1];
2206 rd.
color[3] = alpha;
2209 rd.
vertex[0] =
static_cast<float>(rect.
x);
2210 rd.
vertex[1] =
static_cast<float>(rect.
y+rect.
h);
2211 rd.
texel[1] = st[3];
2215 rd.
vertex[0] =
static_cast<float>(rect.
x+rect.
w);
2216 rd.
vertex[1] =
static_cast<float>(rect.
y+rect.
h);
2217 rd.
texel[0] = st[2];
2221 rd.
vertex[0] =
static_cast<float>(rect.
x+rect.
w);
2222 rd.
vertex[1] =
static_cast<float>(rect.
y);
2223 rd.
texel[1] = st[1];
2230 ro.
rgba[0] = rgba[0];
2231 ro.
rgba[1] = rgba[1];
2232 ro.
rgba[2] = rgba[2];
2233 ro.
rgba[3] = rgba[3];
2238 rd.
vertex[0] =
static_cast<float>(rect.
x);
2239 rd.
vertex[1] =
static_cast<float>(rect.
y);
2241 rd.
texel[0] = st[0];
2242 rd.
texel[1] = st[1];
2246 rd.
color[3] = alpha;
2249 rd.
vertex[0] =
static_cast<float>(rect.
x);
2250 rd.
vertex[1] =
static_cast<float>(rect.
y+rect.
h);
2251 rd.
texel[1] = st[3];
2254 rd.
vertex[0] =
static_cast<float>(rect.
x+rect.
w);
2255 rd.
vertex[1] =
static_cast<float>(rect.
y+rect.
h);
2256 rd.
texel[0] = st[2];
2259 rd.
vertex[0] =
static_cast<float>(rect.
x+rect.
w);
2260 rd.
vertex[1] =
static_cast<float>(rect.
y);
2261 rd.
texel[1] = st[1];
2274 rd.
vertex[0] =
static_cast<float>(rect.
x);
2275 rd.
vertex[1] =
static_cast<float>(rect.
y);
2277 rd.
texel[0] = st1[0];
2278 rd.
texel[1] = st1[1];
2284 rd.
color[3] = alpha;
2287 rd.
vertex[0] =
static_cast<float>(rect.
x);
2288 rd.
vertex[1] =
static_cast<float>(rect.
y+rect.
h);
2289 rd.
texel[1] = st1[3];
2293 rd.
vertex[0] =
static_cast<float>(rect.
x+rect.
w);
2294 rd.
vertex[1] =
static_cast<float>(rect.
y+rect.
h);
2295 rd.
texel[0] = st1[2];
2299 rd.
vertex[0] =
static_cast<float>(rect.
x+rect.
w);
2300 rd.
vertex[1] =
static_cast<float>(rect.
y);
2301 rd.
texel[1] = st1[1];
2307 ro.
rgba[0] = rgba[0];
2308 ro.
rgba[1] = rgba[1];
2309 ro.
rgba[2] = rgba[2];
2310 ro.
rgba[3] = rgba[3];
2316 glActiveTexture(GL_TEXTURE1);
2317 glEnable(GL_TEXTURE_2D);
2323 uint8_t dummydata[3] = {127, 127, 127};
2325 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2326 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2327 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
2328 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
2329 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0,
2330 GL_RGB, GL_UNSIGNED_BYTE, dummydata);
2338 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
2339 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE);
2340 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE);
2343 glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE0);
2344 glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_TEXTURE0);
2345 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
2346 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
2353 glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_CONSTANT);
2354 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
2358 glTexEnvi(GL_TEXTURE_ENV, GL_SRC2_RGB, GL_CONSTANT);
2359 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_ALPHA);
2361 glDisable(GL_TEXTURE_2D);
2364 glClientActiveTexture(GL_TEXTURE2);
2365 glActiveTexture(GL_TEXTURE2);
2366 glEnable(GL_TEXTURE_2D);
2368 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
2369 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE);
2370 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE);
2373 glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE0);
2374 glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_TEXTURE2);
2375 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
2376 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
2383 glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_CONSTANT);
2384 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
2388 glTexEnvi(GL_TEXTURE_ENV, GL_SRC2_RGB, GL_CONSTANT);
2389 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_ALPHA);
2391 glDisable(GL_TEXTURE_2D);
2394 glClientActiveTexture(GL_TEXTURE3);
2395 glActiveTexture(GL_TEXTURE3);
2396 glEnable(GL_TEXTURE_2D);
2398 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
2399 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE);
2400 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE);
2403 glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE0);
2404 glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_TEXTURE3);
2405 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
2406 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
2413 glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_TEXTURE3);
2414 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
2418 glTexEnvi(GL_TEXTURE_ENV, GL_SRC2_RGB, GL_CONSTANT);
2419 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_ALPHA);
2422 glDisable(GL_TEXTURE_2D);
2423 glActiveTexture(GL_TEXTURE0);
2425 glClientActiveTexture(GL_TEXTURE0);
2437 SDL_Surface *surface = SDL_CreateRGBSurface(0, swidth, sheight, 24,
2444 SDL_LockSurface(surface);
2445 pixels =
new uint8_t[swidth * sheight * 3];
2446 glReadPixels(0, 0, swidth, sheight, GL_RGB, GL_UNSIGNED_BYTE, reinterpret_cast<GLvoid*>(pixels));
2447 uint8_t *imagepixels =
reinterpret_cast<uint8_t*
>(surface->pixels);
2449 for (int32_t y = (sheight - 1); y >= 0; --y) {
2450 uint8_t *rowbegin = pixels + y * swidth * 3;
2451 uint8_t *rowend = rowbegin + swidth * 3;
2453 std::copy(rowbegin, rowend, imagepixels);
2456 imagepixels += surface->pitch;
2459 SDL_UnlockSurface(surface);
2462 SDL_FreeSurface(surface);
2469 const bool same_size = (width == swidth && height == sheight);
2471 if (width < 1 || height < 1) {
2482 SDL_Surface* src = SDL_CreateRGBSurface(0, swidth, sheight, 32,
2489 if (SDL_MUSTLOCK(src)) {
2490 SDL_LockSurface(src);
2492 pixels =
new uint8_t[swidth * sheight * 4];
2493 glReadPixels(0, 0, swidth, sheight, GL_RGBA, GL_UNSIGNED_BYTE, reinterpret_cast<GLvoid*>(pixels));
2497 for (int32_t y = (sheight - 1); y >= 0; --y) {
2498 uint8_t *rowbegin = pixels + y * swidth * 4;
2499 uint8_t *rowend = rowbegin + swidth * 4;
2501 std::copy(rowbegin, rowend, imagepixels);
2504 imagepixels += src->pitch;
2508 SDL_Surface* dst = SDL_CreateRGBSurface(0, width, height, 32,
2512 uint32_t* src_help_pointer = src_pointer;
2515 int32_t x, y, *sx_ca, *sy_ca;
2516 int32_t sx =
static_cast<int32_t
>(0xffff * src->w / dst->w);
2517 int32_t sy =
static_cast<int32_t
>(0xffff * src->h / dst->h);
2522 int32_t* sx_a =
new int32_t[dst->w + 1];
2524 for (x = 0; x <= dst->w; x++) {
2531 int32_t* sy_a =
new int32_t[dst->h + 1];
2533 for (y = 0; y <= dst->h; y++) {
2543 if (SDL_MUSTLOCK(dst)) {
2544 SDL_LockSurface(dst);
2547 for (y = 0; y < dst->h; y++) {
2548 src_pointer = src_help_pointer;
2550 for (x = 0; x < dst->w; x++) {
2551 *dst_pointer = *src_pointer;
2553 src_pointer += (*sx_ca >> 16);
2557 src_help_pointer = (
uint32_t*)((
uint8_t*)src_help_pointer + (*sy_ca >> 16) * src->pitch);
2560 if (SDL_MUSTLOCK(dst)) {
2561 SDL_UnlockSurface(dst);
2563 if (SDL_MUSTLOCK(src)) {
2564 SDL_UnlockSurface(src);
2570 SDL_FreeSurface(src);
2571 SDL_FreeSurface(dst);
2578 glScissor(cliparea.
x,
getHeight() - cliparea.
y - cliparea.
h, cliparea.
w, cliparea.
h);
2584 glClearColor(red, green, blue, 0.0);
2587 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
2604 GLuint targetid = glimage->
getTexId();
2611 GLubyte* pixels =
new GLubyte[w*h*4];
2613 glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
2614 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
2621 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,
m_fbo_id);
2622 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
2623 GL_TEXTURE_2D, targetid, 0);
2632 glViewport(0, 0, w, h);
2633 glMatrixMode(GL_PROJECTION);
2636 glOrtho(0, w, 0, h, -100, 100);
2637 glMatrixMode(GL_MODELVIEW);
2639 glCullFace(GL_FRONT);
2642 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
2657 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
2660 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 0, 0,
2666 glMatrixMode(GL_PROJECTION);
2669 glMatrixMode(GL_MODELVIEW);
2670 glCullFace(GL_BACK);
2676 glTranslatef(translation.
x, translation.
y, 0);
2678 glVertexPointer(2, GL_DOUBLE,
sizeof(
GuiVertex), &vertices[0].position);
2679 glColorPointer(4, GL_UNSIGNED_BYTE,
sizeof(
GuiVertex), &vertices[0].color);
2690 glDisable(GL_TEXTURE_2D);
2691 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
2693 glEnable(GL_TEXTURE_2D);
2694 glBindTexture(GL_TEXTURE_2D, texId);
2695 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
2696 glTexCoordPointer(2, GL_DOUBLE,
sizeof(
GuiVertex), &vertices[0].texCoords);
2699 glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_INT, &indices[0]);
uint8_t getDisplay() const
Returns the display index.
uint16_t getHeight() const
Returns the height of the screen mode.
static T ATan2(T _x, T _y)
Abstract interface for all the renderbackends.
uint32_t getSDLFlags() const
Returns the SDL flags used when testing this mode.
virtual void setScreenMode(const ScreenMode &mode)
Sets the mainscreen display mode.
uint32_t getHeight() const
std::vector< RenderZObjectTest > m_renderZ_objects
void renderWithMultitextureAndZ()
virtual void setLighting(float red, float green, float blue)
Set colors for lighting.
virtual void drawFillCircleSegment(const Point &p, uint32_t radius, int32_t sangle, int32_t eangle, uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
Draws a filled circle segment.
virtual void fillRectangle(const Point &p, uint16_t w, uint16_t h, uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
Draws a filled axis parallel rectangle.
T h
Height of the rectangle.
Helper class to create log strings out from separate parts Usage: LMsg("some text") << variable << "...
uint32_t next(octet_iterator &it, octet_iterator end)
SDL_PixelFormat m_rgba_format
GLint vertex_pointer_size
virtual void renderGuiGeometry(const std::vector< GuiVertex > &vertices, const std::vector< int > &indices, const DoublePoint &translation, ImagePtr texture)
Renders geometry required by gui.
uint8_t getStencilRef() const
void setCompressed(bool compressed)
virtual void drawFillCircle(const Point &p, uint32_t radius, uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
Draws a filled circle.
std::vector< renderDataP > m_renderPrimitiveDatas
virtual void renderVertexArrays()
Render the Vertex Arrays, only for primitives (points, lines,...)
std::vector< RenderObject > m_renderMultitextureObjectsZ
std::vector< renderDataColorZ > m_renderTextureColorDatasZ
void disableTextures(uint32_t texUnit)
static void saveAsPng(const std::string &filename, const SDL_Surface &surface)
Saves the SDL_Surface to png format.
virtual const std::string & getName() const
The name of the renderbackend.
virtual void init(const std::string &driver)
Initializes the backend.
virtual bool putPixel(int32_t x, int32_t y, uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
Writes pixel to given position.
std::vector< renderData2TC > m_renderMultitextureDatas
uint32_t getFormat() const
Returns the pixel format enum.
virtual void drawQuad(const Point &p1, const Point &p2, const Point &p3, const Point &p4, uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
Draws quad between given points with given RGBA.
std::vector< uint32_t > m_tc2Indices
virtual void drawTriangle(const Point &p1, const Point &p2, const Point &p3, uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
Draws triangle between given points with given RGBA.
static Logger _log(LM_AUDIO)
void prepareForOverlays()
virtual void drawLine(const Point &p1, const Point &p2, uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
Draws line between given points with given RGBA.
virtual void setClipArea(const Rect &cliparea, bool clear)
Sets given clip area into image.
virtual void drawVertex(const Point &p, const uint8_t size, uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
Draws a quad that represents a vertex with given RGBA.
RenderObject(GLenum m, uint16_t s, uint32_t t1=0, uint32_t t2=0)
void setStencilTest(uint8_t stencil_ref, GLenum stencil_op, GLenum stencil_func)
void enableTextures(uint32_t texUnit)
std::vector< uint32_t > m_indices
static indices for vertex data with z
virtual void addImageToArray(uint32_t id, const Rect &rec, float const *st, uint8_t alpha, uint8_t const *rgba)
Add the Image data to the array.
void setVertexPointer(GLint size, GLsizei stride, const GLvoid *ptr)
virtual void drawCircleSegment(const Point &p, uint32_t radius, int32_t sangle, int32_t eangle, uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
Draws a circle segment.
virtual void setLightingModel(uint32_t lighting)
Initializes the light.
virtual Image * createImage(IResourceLoader *loader=0)
bool isCompressed() const
std::vector< uint32_t > m_pIndices
virtual void resetLighting()
Reset lighting with default values.
virtual void disableScissorTest()
Disables scissor test on the render backend.
virtual void drawCircle(const Point &p, uint32_t radius, uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
Draws a circle.
virtual void captureScreen(const std::string &filename)
Creates a Screenshot and saves it to a file.
SDL_Surface * getSurface()
uint32_t getHeight() const
static bool Equal(T _val1, T _val2)
std::vector< renderDataT > m_renderTextureDatas
virtual void startFrame()
Called when a new frame starts.
virtual uint32_t getLightingModel() const
Gets the current light model.
virtual void drawThickLine(const Point &p1, const Point &p2, uint8_t width, uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
Draws line between given points with given RGBA and width.
uint16_t getBPP() const
Returns the number of bits per pixel this mode uses.
virtual void clearBackBuffer()
Forces a clear of the backbuffer.
virtual ~RenderBackendOpenGL()
virtual void changeBlending(int32_t scr, int32_t dst)
Change the Blendingmodel.
virtual void drawBezier(const std::vector< Point > &points, int32_t steps, uint8_t width, uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
Draws bezier curve between given points with given RGBA and width.
struct FIFE::RenderBackendOpenGL::currentState m_state
uint32_t active_client_tex
virtual void changeRenderInfos(RenderDataType type, uint16_t elements, int32_t src, int32_t dst, bool light, bool stentest, uint8_t stenref, GLConstants stenop, GLConstants stenfunc, OverlayType otype=OVERLAY_TYPE_NONE)
Dirty helper function to change the render infos.
virtual void drawPolyLine(const std::vector< Point > &points, uint8_t width, uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
Draws lines between given points with given RGBA and width.
virtual void detachRenderTarget()
Detaches current render surface.
SDL_Color m_backgroundcolor
#define FL_LOG(logger, msg)
void setTexCoordPointer(uint32_t texUnit, GLsizei stride, const GLvoid *ptr)
std::vector< renderDataZ > m_renderZ_datas
virtual void endFrame()
Called when a frame is finished and ready to be displayed.
virtual void forceLoadInternal()
Forces to load the image into internal memory of GPU.
const void * vertex_pointer
std::vector< renderDataTC > m_renderTextureColorDatas
const void * color_pointer
void renderWithColorAndZ()
std::vector< renderData2TCZ > m_renderMultitextureDatasZ
TextureFiltering m_textureFilter
void setAlphaTest(float ref_alpha)
virtual void createMainScreen(const ScreenMode &mode, const std::string &title, const std::string &icon)
Creates the mainscreen (the display window).
std::vector< renderDataZ > m_renderTextureDatasZ
virtual void forceLoadInternal()=0
Forces to load the image into internal memory of GPU.
std::vector< RenderObject > m_renderObjects
Implements an Image using OpenGL.
RenderZObjectTest * getRenderBufferObject(GLuint texture_id)
Point getBezierPoint(const std::vector< Point > &points, int32_t elements, float t)
Helper that returns an interpolated Point.
void disableStencilTest()
RenderBackendOpenGL(const SDL_Color &colorkey)
void setEnvironmentalColor(uint32_t texUnit, const uint8_t *rgba)
uint32_t getWidth() const
T * get() const
allows direct access to underlying pointer
void setColorPointer(GLsizei stride, const GLvoid *ptr)
virtual void drawRectangle(const Point &p, uint16_t w, uint16_t h, uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
Draws an axis parallel rectangle.
std::vector< RenderZObject > m_renderTextureColorObjectsZ
virtual void drawLightPrimitive(const Point &p, uint8_t intensity, float radius, int32_t subdivisions, float xstretch, float ystretch, uint8_t red, uint8_t green, uint8_t blue)
Draws a light primitive that based on a triangle fan.
virtual void addImageToArrayZ(uint32_t id, const Rect &rect, float vertexZ, float const *st, uint8_t alpha, uint8_t const *rgba)
virtual void attachRenderTarget(ImagePtr &img, bool discard)
Attaches given image as a new render surface.
void deinit()
Performs cleanup actions.
std::vector< RenderZObject > m_renderTextureObjectsZ
virtual void startFrame()
Called when a new frame starts.
uint16_t getWidth() const
Returns the width of the screen mode.
uint16_t getRefreshRate() const
Returns the refresh rate in Hz of this mode.
std::vector< uint32_t > m_tcIndices
T w
Width of the rectangle.
std::vector< uint32_t > m_tIndices
virtual void enableScissorTest()
Enables scissor test on the render backend.
void bindTexture(uint32_t texUnit, GLuint texId)
virtual void endFrame()
Called when a frame is finished and ready to be displayed.
virtual void resetStencilBuffer(uint8_t buffer)
Reset stencil buffer with given value.
uint32_t getWidth() const
const void * tex_pointer[4]
bool isFullScreen() const
True if this is a fullscreen mode.