36 #include "SDL_image.h"
129 static std::string backend_name =
"OpenGL";
135 Uint32 flags = SDL_INIT_VIDEO;
136 if (SDL_InitSubSystem(flags) < 0)
137 throw SDLException(SDL_GetError());
139 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
140 SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
141 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
142 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
143 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
144 SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
145 SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
147 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
152 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
158 SDL_Surface *img = IMG_Load(icon.c_str());
160 SDL_WM_SetIcon(img, 0);
161 SDL_FreeSurface(img);
165 SDL_WM_SetCaption(title.c_str(), 0);
175 if (bitsPerPixel != 0) {
176 uint16_t bpp = SDL_VideoModeOK(width, height, bitsPerPixel, flags);
178 throw SDLException(
"Selected video mode not supported!");
185 m_screen = SDL_SetVideoMode(width, height, bitsPerPixel, flags);
187 throw SDLException(
"Unable to set video mode selected!");
192 <<
"Videomode " << width <<
"x" << height
193 <<
" at " << int32_t(bitsPerPixel) <<
" bpp");
208 throw SDLException(SDL_GetError());
211 glViewport(0, 0, width, height);
212 glMatrixMode(GL_PROJECTION);
214 glOrtho(0, width, height, 0, -100, 100);
215 glMatrixMode(GL_MODELVIEW);
218 glEnable(GL_CULL_FACE);
222 glPixelStorei(GL_PACK_ALIGNMENT, 1);
223 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
225 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
230 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
234 glEnable(GL_DEPTH_TEST);
235 glDepthFunc(GL_LEQUAL);
237 glEnable(GL_SCISSOR_TEST);
239 glEnableClientState(GL_COLOR_ARRAY);
240 glEnableClientState(GL_VERTEX_ARRAY);
252 if (GLEE_EXT_texture_filter_anisotropic) {
254 glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &largest);
271 SDL_GL_SwapBuffers();
280 return new GLImage(name, loader);
290 if (32 == surface->format->BitsPerPixel
303 && surface->flags & SDL_SRCALPHA ) {
310 SDL_Surface* conv = SDL_ConvertSurface(surface, &
m_rgba_format, SDL_SWSURFACE | SDL_SRCALPHA);
314 SDL_FreeSurface(surface);
325 if (32 == surface->format->BitsPerPixel
338 && surface->flags & SDL_SRCALPHA ) {
340 return new GLImage(name, surface);
345 SDL_Surface* conv = SDL_ConvertSurface(surface, &
m_rgba_format, SDL_SWSURFACE | SDL_SRCALPHA);
349 SDL_FreeSurface(surface);
354 return new GLImage(data, width, height);
358 return new GLImage(name, data, width, height);
365 glDisable(GL_COLOR_MATERIAL);
366 }
else if (lighting != 0) {
369 glColorMaterial(GL_FRONT, GL_DIFFUSE);
370 glEnable(GL_COLOR_MATERIAL);
384 glActiveTexture(GL_TEXTURE0 + texUnit);
388 glClientActiveTexture(GL_TEXTURE0 + texUnit);
392 glEnable(GL_TEXTURE_2D);
393 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
401 glActiveTexture(GL_TEXTURE0 + texUnit);
405 glClientActiveTexture(GL_TEXTURE0 + texUnit);
409 glDisable(GL_TEXTURE_2D);
410 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
420 glActiveTexture(GL_TEXTURE0 + texUnit);
424 glClientActiveTexture(GL_TEXTURE0 + texUnit);
427 glBindTexture(GL_TEXTURE_2D, texId);
434 glBindTexture(GL_TEXTURE_2D, texId);
440 glEnable(GL_LIGHTING);
447 glDisable(GL_LIGHTING);
454 GLfloat lightDiffuse[] = {red, green, blue, 1.0f};
455 glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse);
467 glEnable(GL_STENCIL_TEST);
474 glDisable(GL_STENCIL_TEST);
496 glClearStencil(buffer);
499 glClear(GL_STENCIL_BUFFER_BIT);
509 glEnable(GL_ALPHA_TEST);
516 glDisable(GL_ALPHA_TEST);
525 glAlphaFunc(GL_GREATER, ref_alpha);
531 glEnable(GL_DEPTH_TEST);
538 glDisable(GL_DEPTH_TEST);
545 glEnableClientState(GL_COLOR_ARRAY);
552 glDisableClientState(GL_COLOR_ARRAY);
553 glColor4ub(255,255,255,255);
570 glActiveTexture(GL_TEXTURE0 + texUnit);
572 glClientActiveTexture(GL_TEXTURE0 + texUnit);
575 glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, rgbaf);
583 glVertexPointer(size, GL_FLOAT, stride, ptr);
590 glColorPointer(4, GL_UNSIGNED_BYTE, stride, ptr);
598 glActiveTexture(GL_TEXTURE0 + texUnit);
602 glClientActiveTexture(GL_TEXTURE0 + texUnit);
605 glTexCoordPointer(2, GL_FLOAT, stride, ptr);
612 glEnable(GL_SCISSOR_TEST);
619 glDisable(GL_SCISSOR_TEST);
628 case 0 : src_fact = GL_ZERO;
break;
629 case 1 : src_fact = GL_ONE;
break;
630 case 2 : src_fact = GL_DST_COLOR;
break;
631 case 3 : src_fact = GL_ONE_MINUS_DST_COLOR;
break;
632 case 4 : src_fact = GL_SRC_ALPHA;
break;
633 case 5 : src_fact = GL_ONE_MINUS_SRC_ALPHA;
break;
634 case 6 : src_fact = GL_DST_ALPHA;
break;
635 case 7 : src_fact = GL_ONE_MINUS_DST_ALPHA;
break;
637 default : src_fact = GL_DST_COLOR;
break;
641 case 0 : dst_fact = GL_ZERO;
break;
642 case 1 : dst_fact = GL_ONE;
break;
643 case 2 : dst_fact = GL_SRC_COLOR;
break;
644 case 3 : dst_fact = GL_ONE_MINUS_SRC_COLOR;
break;
645 case 4 : dst_fact = GL_SRC_ALPHA;
break;
646 case 5 : dst_fact = GL_ONE_MINUS_SRC_ALPHA;
break;
647 case 6 : dst_fact = GL_DST_ALPHA;
break;
648 case 7 : dst_fact = GL_ONE_MINUS_DST_ALPHA;
break;
650 default : dst_fact = GL_SRC_ALPHA;
break;
656 glBlendFunc(src_fact, dst_fact);
667 while (count != elements) {
691 while (count != elements) {
716 bool texture =
false;
717 bool blending =
false;
719 bool stencil =
false;
725 GLenum mode = GL_QUADS;
742 int32_t index2TC = 0;
749 int32_t* currentIndex = 0;
769 currentIndex = &indexT;
770 currentElements = &elementsT;
778 currentIndex = &indexTC;
779 currentElements = &elementsTC;
786 currentIndex = &indexP;
787 currentElements = &elementsP;
795 currentIndex = &index2TC;
796 currentElements = &elements2TC;
803 if (ro.
mode != mode) {
821 if (ro.
src != src || ro.
dst != dst) {
844 if (*currentElements > 0) {
846 glDrawArrays(mode, *currentIndex, *currentElements);
847 *currentIndex += *currentElements;
863 currentElements = &elementsTC;
864 currentIndex = &indexTC;
868 currentElements = &elementsP;
869 currentIndex = &indexP;
877 currentElements = &elementsT;
878 currentIndex = &indexT;
897 currentElements = &elementsTC;
898 currentIndex = &indexTC;
902 currentIndex = &indexT;
903 currentElements = &elementsT;
908 currentElements = &elementsP;
909 currentIndex = &indexP;
927 currentElements = &elements2TC;
928 currentIndex = &index2TC;
944 currentElements = &elements2TC;
945 currentIndex = &index2TC;
961 currentElements = &elements2TC;
962 currentIndex = &index2TC;
979 currentElements = &elementsTC;
980 currentIndex = &indexTC;
984 currentElements = &elementsT;
985 currentIndex = &indexT;
994 currentElements = &elementsP;
995 currentIndex = &indexP;
1002 *currentElements = ro.
size;
1038 *currentElements += ro.
size;
1042 glDrawArrays(mode, *currentIndex, *currentElements);
1082 int32_t* currentIndex = &index;
1083 uint32_t* currentElements = &elements;
1095 if (*currentElements > 0) {
1097 glDrawArrays(GL_QUADS, *currentIndex, *currentElements);
1098 *currentIndex += *currentElements;
1110 *currentElements = 4;
1113 *currentElements += 4;
1118 glDrawArrays(GL_QUADS, *currentIndex, *currentElements);
1148 glDrawArrays(GL_QUADS, iter->index, iter->elements);
1176 int32_t* currentIndex = &index;
1177 uint32_t* currentElements = &elements;
1189 if (*currentElements > 0) {
1191 glDrawArrays(GL_QUADS, *currentIndex, *currentElements);
1192 *currentIndex += *currentElements;
1204 *currentElements = 4;
1207 *currentElements += 4;
1212 glDrawArrays(GL_QUADS, *currentIndex, *currentElements);
1227 bool texture =
false;
1228 bool render =
false;
1254 int32_t* currentIndex = &index;
1255 uint32_t* currentElements = &elements;
1278 if (*currentElements > 0) {
1280 glDrawArrays(GL_QUADS, *currentIndex, *currentElements);
1281 *currentIndex += *currentElements;
1340 *currentElements = ro.
size;
1344 *currentElements += ro.
size;
1348 glDrawArrays(GL_QUADS, *currentIndex, *currentElements);
1387 if ((x < 0) || (x >= (int32_t)
m_target->w) ||
1388 (y < 0) || (y >= (int32_t)
m_target->h)) {
1392 rd.
vertex[0] =
static_cast<float>(x)+0.375;
1393 rd.
vertex[1] =
static_cast<float>(y)+0.375;
1408 rd.
vertex[0] =
static_cast<float>(p1.
x)-0.375;
1409 rd.
vertex[1] =
static_cast<float>(p1.
y)-0.375;
1416 rd.
vertex[0] =
static_cast<float>(p2.
x)-0.375;
1417 rd.
vertex[1] =
static_cast<float>(p2.
y)-0.375;
1426 rd.
vertex[0] =
static_cast<float>(p1.
x);
1427 rd.
vertex[1] =
static_cast<float>(p1.
y);
1434 rd.
vertex[0] =
static_cast<float>(p2.
x);
1435 rd.
vertex[1] =
static_cast<float>(p2.
y);
1438 rd.
vertex[0] =
static_cast<float>(p3.
x);
1439 rd.
vertex[1] =
static_cast<float>(p3.
y);
1448 rd.
vertex[0] =
static_cast<float>(p.
x);
1449 rd.
vertex[1] =
static_cast<float>(p.
y);
1456 rd.
vertex[0] =
static_cast<float>(p.
x+w);
1459 rd.
vertex[1] =
static_cast<float>(p.
y+h);
1462 rd.
vertex[0] =
static_cast<float>(p.
x);
1471 rd.
vertex[0] =
static_cast<float>(p.
x);
1472 rd.
vertex[1] =
static_cast<float>(p.
y);
1479 rd.
vertex[1] =
static_cast<float>(p.
y+h);
1482 rd.
vertex[0] =
static_cast<float>(p.
x+w);
1485 rd.
vertex[1] =
static_cast<float>(p.
y);
1494 rd.
vertex[0] =
static_cast<float>(p1.
x);
1495 rd.
vertex[1] =
static_cast<float>(p1.
y);
1502 rd.
vertex[0] =
static_cast<float>(p2.
x);
1503 rd.
vertex[1] =
static_cast<float>(p2.
y);
1506 rd.
vertex[0] =
static_cast<float>(p3.
x);
1507 rd.
vertex[1] =
static_cast<float>(p3.
y);
1510 rd.
vertex[0] =
static_cast<float>(p4.
x);
1511 rd.
vertex[1] =
static_cast<float>(p4.
y);
1520 rd.
vertex[0] =
static_cast<float>(p.
x-size);
1521 rd.
vertex[1] =
static_cast<float>(p.
y+size);
1528 rd.
vertex[0] =
static_cast<float>(p.
x+size);
1531 rd.
vertex[1] =
static_cast<float>(p.
y-size);
1534 rd.
vertex[0] =
static_cast<float>(p.
x-size);
1545 for(
float angle=0; angle<=
Mathf::twoPi(); angle+=step){
1546 rd.
vertex[0] =
static_cast<float>(p.
x);
1547 rd.
vertex[1] =
static_cast<float>(p.
y);
1549 rd.
color[1] = green;
1551 rd.
color[3] = intensity;
1574 if (alpha == 255 && !rgba) {
1576 rd.
vertex[0] =
static_cast<float>(rect.
x);
1577 rd.
vertex[1] =
static_cast<float>(rect.
y);
1578 rd.
texel[0] = st[0];
1579 rd.
texel[1] = st[1];
1582 rd.
vertex[0] =
static_cast<float>(rect.
x);
1583 rd.
vertex[1] =
static_cast<float>(rect.
y+rect.
h);
1584 rd.
texel[1] = st[3];
1587 rd.
vertex[0] =
static_cast<float>(rect.
x+rect.
w);
1588 rd.
vertex[1] =
static_cast<float>(rect.
y+rect.
h);
1589 rd.
texel[0] = st[2];
1592 rd.
vertex[0] =
static_cast<float>(rect.
x+rect.
w);
1593 rd.
vertex[1] =
static_cast<float>(rect.
y);
1594 rd.
texel[1] = st[1];
1601 rd.
vertex[0] =
static_cast<float>(rect.
x);
1602 rd.
vertex[1] =
static_cast<float>(rect.
y);
1603 rd.
texel[0] = st[0];
1604 rd.
texel[1] = st[1];
1610 rd.
color[3] = alpha;
1613 rd.
vertex[0] =
static_cast<float>(rect.
x);
1614 rd.
vertex[1] =
static_cast<float>(rect.
y+rect.
h);
1615 rd.
texel[1] = st[3];
1619 rd.
vertex[0] =
static_cast<float>(rect.
x+rect.
w);
1620 rd.
vertex[1] =
static_cast<float>(rect.
y+rect.
h);
1621 rd.
texel[0] = st[2];
1625 rd.
vertex[0] =
static_cast<float>(rect.
x+rect.
w);
1626 rd.
vertex[1] =
static_cast<float>(rect.
y);
1627 rd.
texel[1] = st[1];
1633 ro.
rgba[0] = rgba[0];
1634 ro.
rgba[1] = rgba[1];
1635 ro.
rgba[2] = rgba[2];
1636 ro.
rgba[3] = rgba[3];
1640 rd.
vertex[0] =
static_cast<float>(rect.
x);
1641 rd.
vertex[1] =
static_cast<float>(rect.
y);
1642 rd.
texel[0] = st[0];
1643 rd.
texel[1] = st[1];
1647 rd.
color[3] = alpha;
1650 rd.
vertex[0] =
static_cast<float>(rect.
x);
1651 rd.
vertex[1] =
static_cast<float>(rect.
y+rect.
h);
1652 rd.
texel[1] = st[3];
1655 rd.
vertex[0] =
static_cast<float>(rect.
x+rect.
w);
1656 rd.
vertex[1] =
static_cast<float>(rect.
y+rect.
h);
1657 rd.
texel[0] = st[2];
1660 rd.
vertex[0] =
static_cast<float>(rect.
x+rect.
w);
1661 rd.
vertex[1] =
static_cast<float>(rect.
y);
1662 rd.
texel[1] = st[1];
1674 rd.
vertex[0] =
static_cast<float>(rect.
x);
1675 rd.
vertex[1] =
static_cast<float>(rect.
y);
1676 rd.
texel[0] = st1[0];
1677 rd.
texel[1] = st1[1];
1683 rd.
color[3] = alpha;
1686 rd.
vertex[0] =
static_cast<float>(rect.
x);
1687 rd.
vertex[1] =
static_cast<float>(rect.
y+rect.
h);
1688 rd.
texel[1] = st1[3];
1692 rd.
vertex[0] =
static_cast<float>(rect.
x+rect.
w);
1693 rd.
vertex[1] =
static_cast<float>(rect.
y+rect.
h);
1694 rd.
texel[0] = st1[2];
1698 rd.
vertex[0] =
static_cast<float>(rect.
x+rect.
w);
1699 rd.
vertex[1] =
static_cast<float>(rect.
y);
1700 rd.
texel[1] = st1[1];
1706 ro.
rgba[0] = rgba[0];
1707 ro.
rgba[1] = rgba[1];
1708 ro.
rgba[2] = rgba[2];
1709 ro.
rgba[3] = rgba[3];
1716 if (it->texture_id == texture_id) {
1717 if (it->elements < it->max_size - 4) {
1722 int32_t max_quads_per_texbatch = 1000;
1732 obj.
max_size = max_quads_per_texbatch * 4;
1740 if (alpha == 255 && !rgba) {
1775 rd.
vertex[0] =
static_cast<float>(rect.
x);
1776 rd.
vertex[1] =
static_cast<float>(rect.
y);
1778 rd.
texel[0] = st[0];
1779 rd.
texel[1] = st[1];
1782 rd.
vertex[0] =
static_cast<float>(rect.
x);
1783 rd.
vertex[1] =
static_cast<float>(rect.
y+rect.
h);
1784 rd.
texel[1] = st[3];
1787 rd.
vertex[0] =
static_cast<float>(rect.
x+rect.
w);
1788 rd.
vertex[1] =
static_cast<float>(rect.
y+rect.
h);
1789 rd.
texel[0] = st[2];
1792 rd.
vertex[0] =
static_cast<float>(rect.
x+rect.
w);
1793 rd.
vertex[1] =
static_cast<float>(rect.
y);
1794 rd.
texel[1] = st[1];
1804 rd.
vertex[0] =
static_cast<float>(rect.
x);
1805 rd.
vertex[1] =
static_cast<float>(rect.
y);
1807 rd.
texel[0] = st[0];
1808 rd.
texel[1] = st[1];
1814 rd.
color[3] = alpha;
1817 rd.
vertex[0] =
static_cast<float>(rect.
x);
1818 rd.
vertex[1] =
static_cast<float>(rect.
y+rect.
h);
1819 rd.
texel[1] = st[3];
1823 rd.
vertex[0] =
static_cast<float>(rect.
x+rect.
w);
1824 rd.
vertex[1] =
static_cast<float>(rect.
y+rect.
h);
1825 rd.
texel[0] = st[2];
1829 rd.
vertex[0] =
static_cast<float>(rect.
x+rect.
w);
1830 rd.
vertex[1] =
static_cast<float>(rect.
y);
1831 rd.
texel[1] = st[1];
1838 ro.
rgba[0] = rgba[0];
1839 ro.
rgba[1] = rgba[1];
1840 ro.
rgba[2] = rgba[2];
1841 ro.
rgba[3] = rgba[3];
1846 rd.
vertex[0] =
static_cast<float>(rect.
x);
1847 rd.
vertex[1] =
static_cast<float>(rect.
y);
1849 rd.
texel[0] = st[0];
1850 rd.
texel[1] = st[1];
1854 rd.
color[3] = alpha;
1857 rd.
vertex[0] =
static_cast<float>(rect.
x);
1858 rd.
vertex[1] =
static_cast<float>(rect.
y+rect.
h);
1859 rd.
texel[1] = st[3];
1862 rd.
vertex[0] =
static_cast<float>(rect.
x+rect.
w);
1863 rd.
vertex[1] =
static_cast<float>(rect.
y+rect.
h);
1864 rd.
texel[0] = st[2];
1867 rd.
vertex[0] =
static_cast<float>(rect.
x+rect.
w);
1868 rd.
vertex[1] =
static_cast<float>(rect.
y);
1869 rd.
texel[1] = st[1];
1882 rd.
vertex[0] =
static_cast<float>(rect.
x);
1883 rd.
vertex[1] =
static_cast<float>(rect.
y);
1885 rd.
texel[0] = st1[0];
1886 rd.
texel[1] = st1[1];
1892 rd.
color[3] = alpha;
1895 rd.
vertex[0] =
static_cast<float>(rect.
x);
1896 rd.
vertex[1] =
static_cast<float>(rect.
y+rect.
h);
1897 rd.
texel[1] = st1[3];
1901 rd.
vertex[0] =
static_cast<float>(rect.
x+rect.
w);
1902 rd.
vertex[1] =
static_cast<float>(rect.
y+rect.
h);
1903 rd.
texel[0] = st1[2];
1907 rd.
vertex[0] =
static_cast<float>(rect.
x+rect.
w);
1908 rd.
vertex[1] =
static_cast<float>(rect.
y);
1909 rd.
texel[1] = st1[1];
1916 ro.
rgba[0] = rgba[0];
1917 ro.
rgba[1] = rgba[1];
1918 ro.
rgba[2] = rgba[2];
1919 ro.
rgba[3] = rgba[3];
1925 glActiveTexture(GL_TEXTURE1);
1926 glEnable(GL_TEXTURE_2D);
1932 uint8_t dummydata[3] = {127, 127, 127};
1934 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1935 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1936 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1937 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1938 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0,
1939 GL_RGB, GL_UNSIGNED_BYTE, dummydata);
1947 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
1948 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE);
1949 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE);
1952 glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE0);
1953 glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_TEXTURE0);
1954 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
1955 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
1962 glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_CONSTANT);
1963 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
1967 glTexEnvi(GL_TEXTURE_ENV, GL_SRC2_RGB, GL_CONSTANT);
1968 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_ALPHA);
1970 glDisable(GL_TEXTURE_2D);
1973 glClientActiveTexture(GL_TEXTURE2);
1974 glActiveTexture(GL_TEXTURE2);
1975 glEnable(GL_TEXTURE_2D);
1977 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
1978 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE);
1979 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE);
1982 glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE0);
1983 glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_TEXTURE2);
1984 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
1985 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
1992 glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_CONSTANT);
1993 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
1997 glTexEnvi(GL_TEXTURE_ENV, GL_SRC2_RGB, GL_CONSTANT);
1998 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_ALPHA);
2000 glDisable(GL_TEXTURE_2D);
2003 glClientActiveTexture(GL_TEXTURE3);
2004 glActiveTexture(GL_TEXTURE3);
2005 glEnable(GL_TEXTURE_2D);
2007 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
2008 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE);
2009 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE);
2012 glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE0);
2013 glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_TEXTURE3);
2014 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
2015 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
2022 glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_TEXTURE3);
2023 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
2027 glTexEnvi(GL_TEXTURE_ENV, GL_SRC2_RGB, GL_CONSTANT);
2028 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_ALPHA);
2031 glDisable(GL_TEXTURE_2D);
2032 glActiveTexture(GL_TEXTURE0);
2034 glClientActiveTexture(GL_TEXTURE0);
2046 SDL_Surface *surface = SDL_CreateRGBSurface(SDL_SWSURFACE, swidth, sheight, 24,
2053 SDL_LockSurface(surface);
2054 pixels =
new uint8_t[swidth * sheight * 3];
2055 glReadPixels(0, 0, swidth, sheight, GL_RGB, GL_UNSIGNED_BYTE, reinterpret_cast<GLvoid*>(pixels));
2056 uint8_t *imagepixels =
reinterpret_cast<uint8_t*
>(surface->pixels);
2058 for (int32_t y = (sheight - 1); y >= 0; --y) {
2059 uint8_t *rowbegin = pixels + y * swidth * 3;
2060 uint8_t *rowend = rowbegin + swidth * 3;
2062 std::copy(rowbegin, rowend, imagepixels);
2065 imagepixels += surface->pitch;
2068 SDL_UnlockSurface(surface);
2071 SDL_FreeSurface(surface);
2078 const bool same_size = (width == swidth && height == sheight);
2080 if (width < 1 || height < 1) {
2091 SDL_Surface* src = SDL_CreateRGBSurface(SDL_SWSURFACE, swidth, sheight, 32,
2098 if (SDL_MUSTLOCK(src)) {
2099 SDL_LockSurface(src);
2101 pixels =
new uint8_t[swidth * sheight * 4];
2102 glReadPixels(0, 0, swidth, sheight, GL_RGBA, GL_UNSIGNED_BYTE, reinterpret_cast<GLvoid*>(pixels));
2106 for (int32_t y = (sheight - 1); y >= 0; --y) {
2107 uint8_t *rowbegin = pixels + y * swidth * 4;
2108 uint8_t *rowend = rowbegin + swidth * 4;
2110 std::copy(rowbegin, rowend, imagepixels);
2113 imagepixels += src->pitch;
2117 SDL_Surface* dst = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32,
2121 uint32_t* src_help_pointer = src_pointer;
2124 int32_t x, y, *sx_ca, *sy_ca;
2125 int32_t sx =
static_cast<int32_t
>(0xffff * src->w / dst->w);
2126 int32_t sy =
static_cast<int32_t
>(0xffff * src->h / dst->h);
2131 int32_t* sx_a =
new int32_t[dst->w + 1];
2133 for (x = 0; x <= dst->w; x++) {
2140 int32_t* sy_a =
new int32_t[dst->h + 1];
2142 for (y = 0; y <= dst->h; y++) {
2152 if (SDL_MUSTLOCK(dst)) {
2153 SDL_LockSurface(dst);
2156 for (y = 0; y < dst->h; y++) {
2157 src_pointer = src_help_pointer;
2159 for (x = 0; x < dst->w; x++) {
2160 *dst_pointer = *src_pointer;
2162 src_pointer += (*sx_ca >> 16);
2166 src_help_pointer = (
uint32_t*)((
uint8_t*)src_help_pointer + (*sy_ca >> 16) * src->pitch);
2169 if (SDL_MUSTLOCK(dst)) {
2170 SDL_UnlockSurface(dst);
2172 if (SDL_MUSTLOCK(src)) {
2173 SDL_UnlockSurface(src);
2179 SDL_FreeSurface(src);
2180 SDL_FreeSurface(dst);
2187 glScissor(cliparea.
x,
getHeight() - cliparea.
y - cliparea.
h, cliparea.
w, cliparea.
h);
2193 glClearColor(red, green, blue, 0.0);
2196 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
2213 GLuint targetid = glimage->
getTexId();
2220 GLubyte* pixels =
new GLubyte[w*h*4];
2222 glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
2223 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
2230 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,
m_fbo_id);
2231 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
2232 GL_TEXTURE_2D, targetid, 0);
2241 glViewport(0, 0, w, h);
2242 glMatrixMode(GL_PROJECTION);
2245 glOrtho(0, w, 0, h, -100, 100);
2246 glMatrixMode(GL_MODELVIEW);
2248 glCullFace(GL_FRONT);
2251 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
2266 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
2269 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 0, 0,
2275 glMatrixMode(GL_PROJECTION);
2278 glMatrixMode(GL_MODELVIEW);
2279 glCullFace(GL_BACK);
2285 glTranslatef(translation.
x, translation.
y, 0);
2287 glVertexPointer(2, GL_DOUBLE,
sizeof(
GuiVertex), &vertices[0].position);
2288 glColorPointer(4, GL_UNSIGNED_BYTE,
sizeof(
GuiVertex), &vertices[0].color);
2299 glDisable(GL_TEXTURE_2D);
2300 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
2302 glEnable(GL_TEXTURE_2D);
2303 glBindTexture(GL_TEXTURE_2D, texId);
2304 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
2305 glTexCoordPointer(2, GL_DOUBLE,
sizeof(
GuiVertex), &vertices[0].texCoords);
2308 glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_INT, &indices[0]);
Abstract interface for all the renderbackends.
T * get() const
allows direct access to underlying pointer
virtual void setScreenMode(const ScreenMode &mode)
Sets the mainscreen display mode.
std::vector< RenderZObjectTest > m_renderZ_objects
void renderWithMultitextureAndZ()
virtual void setLighting(float red, float green, float blue)
Set colors for lighting.
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.
virtual uint32_t getLightingModel() const
Gets the current light model.
T h
Height of the rectangle.
Helper class to create log strings out from separate parts Usage: LMsg("some text") << variable << "...
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.
uint32_t getHeight() const
void setCompressed(bool compressed)
uint32_t getSDLFlags() const
Returns the SDL flags used when testing this mode.
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 void init(const std::string &driver)
Initializes the backend.
uint16_t getBPP() const
Returns the number of bits per pixel this mode uses.
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
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.
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.
uint8_t getStencilRef() const
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)
const Rect & getArea() const
void enableTextures(uint32_t texUnit)
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 setLightingModel(uint32_t lighting)
Initializes the light.
virtual Image * createImage(IResourceLoader *loader=0)
uint32_t getHeight() const
virtual void resetLighting()
Reset lighting with default values.
virtual void disableScissorTest()
Disables scissor test on the render backend.
virtual void captureScreen(const std::string &filename)
Creates a Screenshot and saves it to a file.
SDL_Surface * getSurface()
static bool Equal(T _val1, T _val2)
std::vector< renderDataT > m_renderTextureDatas
virtual void startFrame()
Called when a new frame starts.
virtual void clearBackBuffer()
Forces a clear of the backbuffer.
virtual ~RenderBackendOpenGL()
virtual void changeBlending(int32_t scr, int32_t dst)
Change the Blendingmodel.
bool isCompressed() const
uint16_t getHeight() const
Returns the height of the screen mode.
struct FIFE::RenderBackendOpenGL::currentState m_state
uint32_t getWidth() const
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.
uint16_t getWidth() const
Returns the width of the screen mode.
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)
uint32_t getWidth() const
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)
void disableStencilTest()
RenderBackendOpenGL(const SDL_Color &colorkey)
void setEnvironmentalColor(uint32_t texUnit, const uint8_t *rgba)
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.
T w
Width of the rectangle.
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.
const void * tex_pointer[4]
virtual const std::string & getName() const
The name of the renderbackend.