Skip to content

Commit

Permalink
Fixes sprites with 2**n+1 px width (different pieces of code compensa…
Browse files Browse the repository at this point in the history
…ted for serp's nightmare function differently). Greatly optimizes sprites and other graphical resources. Fixes most z buffer issues; extreme ugliness may instead ensue.

git-svn-id: https://enigma-dev.svn.sourceforge.net/svnroot/enigma-dev/trunk@948 726d713c-bd1a-46cb-9ef0-1b6e075168bb
  • Loading branch information
JoshDreamland authored and JoshDreamland committed Nov 21, 2011
1 parent dcbf8b6 commit a5bcd1b
Show file tree
Hide file tree
Showing 20 changed files with 141 additions and 310 deletions.
80 changes: 13 additions & 67 deletions ENIGMAsystem/SHELL/Graphics_Systems/OpenGL/GSbackground.cpp
Expand Up @@ -28,7 +28,6 @@

extern int room_width, room_height;
namespace enigma {
extern unsigned bound_texture;
extern size_t background_idmax;
}

Expand Down Expand Up @@ -56,15 +55,12 @@ namespace enigma {
const enigma::background *const bck2d = enigma::backgroundstructarray[back];
#endif

#include "binding.h"

void draw_background(int back, double x, double y)
{
get_background(bck2d,back);

if (enigma::bound_texture != bck2d->texture)
{
glBindTexture(GL_TEXTURE_2D,bck2d->texture);
enigma::bound_texture = bck2d->texture;
}
bind_texture(bck2d->texture);

glPushAttrib(GL_CURRENT_BIT);
glColor4f(1,1,1,1);
Expand All @@ -87,12 +83,7 @@ void draw_background(int back, double x, double y)
void draw_background_stretched(int back, double x, double y, double w, double h)
{
get_background(bck2d,back);

if (enigma::bound_texture != bck2d->texture)
{
glBindTexture(GL_TEXTURE_2D,bck2d->texture);
enigma::bound_texture = bck2d->texture;
}
bind_texture(bck2d->texture);

glPushAttrib(GL_CURRENT_BIT);
glColor4f(1,1,1,1);
Expand All @@ -115,12 +106,7 @@ void draw_background_stretched(int back, double x, double y, double w, double h)
void draw_background_part(int back,double left,double top,double width,double height,double x,double y)
{
get_background(bck2d,back);

if (enigma::bound_texture != bck2d->texture)
{
glBindTexture(GL_TEXTURE_2D,bck2d->texture);
enigma::bound_texture = bck2d->texture;
}
bind_texture(bck2d->texture);

glPushAttrib(GL_CURRENT_BIT);
glColor4f(1,1,1,1);
Expand All @@ -144,12 +130,7 @@ void draw_background_part(int back,double left,double top,double width,double he
void draw_background_tiled(int back,double x,double y)
{
get_background(bck2d,back);

if (enigma::bound_texture != bck2d->texture)
{
glBindTexture(GL_TEXTURE_2D,bck2d->texture);
enigma::bound_texture = bck2d->texture;
}
bind_texture(bck2d->texture);

glPushAttrib(GL_CURRENT_BIT);
glColor4f(1,1,1,1);
Expand Down Expand Up @@ -181,12 +162,7 @@ void draw_background_tiled(int back,double x,double y)
void draw_background_tiled_area(int back,double x,double y,double x1,double y1,double x2,double y2)
{
get_background(bck2d,back);

if (enigma::bound_texture != bck2d->texture)
{
glBindTexture(GL_TEXTURE_2D,bck2d->texture);
enigma::bound_texture = bck2d->texture;
}
bind_texture(bck2d->texture);

glPushAttrib(GL_CURRENT_BIT);
glColor4f(1,1,1,1);
Expand Down Expand Up @@ -237,12 +213,7 @@ void draw_background_tiled_area(int back,double x,double y,double x1,double y1,d
void draw_background_ext(int back,double x,double y,double xscale,double yscale,double rot,int color,double alpha)
{
get_background(bck2d,back);

if (enigma::bound_texture != bck2d->texture)
{
glBindTexture(GL_TEXTURE_2D,bck2d->texture);
enigma::bound_texture = bck2d->texture;
}
bind_texture(bck2d->texture);

glPushAttrib(GL_CURRENT_BIT);
glColor4ub(__GETR(color),__GETG(color),__GETB(color),char(alpha*255));
Expand Down Expand Up @@ -271,12 +242,7 @@ void draw_background_ext(int back,double x,double y,double xscale,double yscale,
void draw_background_stretched_ext(int back,double x,double y,double w,double h,int color,double alpha)
{
get_background(bck2d,back);

if (enigma::bound_texture != bck2d->texture)
{
glBindTexture(GL_TEXTURE_2D,bck2d->texture);
enigma::bound_texture = bck2d->texture;
}
bind_texture(bck2d->texture);

glPushAttrib(GL_CURRENT_BIT);
glColor4ub(__GETR(color),__GETG(color),__GETB(color),char(alpha*255));
Expand All @@ -299,12 +265,7 @@ void draw_background_stretched_ext(int back,double x,double y,double w,double h,
void draw_background_part_ext(int back,double left,double top,double width,double height,double x,double y,double xscale,double yscale,int color,double alpha)
{
get_background(bck2d,back);

if (enigma::bound_texture != bck2d->texture)
{
glBindTexture(GL_TEXTURE_2D,bck2d->texture);
enigma::bound_texture = bck2d->texture;
}
bind_texture(bck2d->texture);

glPushAttrib(GL_CURRENT_BIT);
glColor4ub(__GETR(color),__GETG(color),__GETB(color),char(alpha*255));
Expand All @@ -330,12 +291,7 @@ void draw_background_part_ext(int back,double left,double top,double width,doubl
void draw_background_tiled_ext(int back,double x,double y,double xscale,double yscale,int color,double alpha)
{
get_background(bck2d,back);

if (enigma::bound_texture != bck2d->texture)
{
glBindTexture(GL_TEXTURE_2D,bck2d->texture);
enigma::bound_texture = bck2d->texture;
}
bind_texture(bck2d->texture);

glPushAttrib(GL_CURRENT_BIT);
glColor4ub(__GETR(color),__GETG(color),__GETB(color),char(alpha*255));
Expand Down Expand Up @@ -366,12 +322,7 @@ void draw_background_tiled_ext(int back,double x,double y,double xscale,double y
void draw_background_tiled_area_ext(int back,double x,double y,double x1,double y1,double x2,double y2, double xscale, double yscale, int color, double alpha)
{
get_background(bck2d,back);

if (enigma::bound_texture != bck2d->texture)
{
glBindTexture(GL_TEXTURE_2D,bck2d->texture);
enigma::bound_texture = bck2d->texture;
}
bind_texture(bck2d->texture);

glPushAttrib(GL_CURRENT_BIT);
glColor4ub(__GETR(color),__GETG(color),__GETB(color),char(alpha*255));
Expand Down Expand Up @@ -422,12 +373,7 @@ void draw_background_tiled_area_ext(int back,double x,double y,double x1,double
void draw_background_general(int back,double left,double top,double width,double height,double x,double y,double xscale,double yscale,double rot,int c1,int c2,int c3,int c4,double a1,double a2,double a3,double a4)
{
get_background(bck2d,back);

if (enigma::bound_texture != bck2d->texture)
{
glBindTexture(GL_TEXTURE_2D,bck2d->texture);
enigma::bound_texture = bck2d->texture;
}
bind_texture(bck2d->texture);

glPushAttrib(GL_CURRENT_BIT);
const float
Expand Down
9 changes: 6 additions & 3 deletions ENIGMAsystem/SHELL/Graphics_Systems/OpenGL/GScurves.cpp
Expand Up @@ -29,10 +29,13 @@


namespace enigma{
extern unsigned bound_texture;
extern unsigned char currentcolor[4];
}
#define untexture() if(enigma::bound_texture) glBindTexture(GL_TEXTURE_2D,enigma::bound_texture=0);
}
#ifdef use_bound_texture_global
#define untexture() if(enigma::bound_texture) glBindTexture(GL_TEXTURE_2D,enigma::bound_texture=0);
#else
#define untexture() glBindTexture(GL_TEXTURE_2D, 0);
#endif

int pr_curve_detail = 20;
int pr_curve_mode = GL_LINE_STRIP;
Expand Down
18 changes: 4 additions & 14 deletions ENIGMAsystem/SHELL/Graphics_Systems/OpenGL/GSd3d.cpp
Expand Up @@ -24,24 +24,14 @@ using namespace std;
#include "../../Universal_System/var4.h"
#include "../../Universal_System/roomsystem.h"
#include <math.h>
#include "binding.h"

bool d3dMode = false;

namespace enigma {
extern unsigned bound_texture;
}

#define retexture(texid) if (enigma::bound_texture != unsigned(texid)) { \
glBindTexture(GL_TEXTURE_2D,texid); \
enigma::bound_texture = texid; \
}

void d3d_start()
{
// Enable depth buffering
glDisable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glDepthRange(.1,640);
glEnable(GL_DEPTH_TEST);

// Set up projection matrix
glMatrixMode(GL_PROJECTION);
Expand Down Expand Up @@ -139,7 +129,7 @@ void d3d_set_projection_ortho(int x, int y, int width, int height, int angle)

void d3d_draw_wall(double x1, double y1, double z1, double x2, double y2, double z2, int texId, int hrep, int vrep)
{
retexture(texId);
bind_texture(texId);
glBegin(GL_QUADS);
glTexCoord2d(0,1);
glVertex3f(x1, y1, z1);
Expand All @@ -154,7 +144,7 @@ void d3d_draw_wall(double x1, double y1, double z1, double x2, double y2, double

void d3d_draw_floor(double x1, double y1, double z1, double x2, double y2, double z2, int texId, int hrep, int vrep)
{
retexture(texId);
bind_texture(texId);
glBegin(GL_QUADS);
glTexCoord2d(0, vrep);
glVertex3f(x1, y1, z1);
Expand Down
47 changes: 16 additions & 31 deletions ENIGMAsystem/SHELL/Graphics_Systems/OpenGL/GSfont.cpp
Expand Up @@ -21,7 +21,8 @@
#include "../../Universal_System/var4.h"
#include "../../libEGMstd.h"
#include "GScolors.h"
#include "GSfont.h"
#include "GSfont.h"
#include "binding.h"

using namespace std;
#include "../../Universal_System/fontstruct.h"
Expand All @@ -31,8 +32,7 @@ using namespace std;
#define __GETB(x) ((x & 0xFF0000) >> 16)

namespace enigma {
static int currentfont = -1;
extern unsigned bound_texture;
static int currentfont = -1;
extern size_t font_idmax;
}

Expand Down Expand Up @@ -257,10 +257,9 @@ unsigned int string_height_ext(variant vstr, int sep, int w)
void draw_text(int x,int y,variant vstr)
{
string str = toString(vstr);
get_fontv(fnt,currentfont);

if (bound_texture != fnt->texture)
glBindTexture(GL_TEXTURE_2D, bound_texture = fnt->texture);
get_fontv(fnt,currentfont);
bind_texture(fnt->texture);

int yy = valign == fa_top ? y+fnt->yoffset : valign == fa_middle ? y +fnt->yoffset - string_height(str)/2 : y + fnt->yoffset - string_height(str);
if (halign == fa_left){
int xx = x;
Expand Down Expand Up @@ -322,10 +321,8 @@ void draw_text(int x,int y,variant vstr)
void draw_text_ext(int x,int y,variant vstr, int sep, int w)
{
string str = toString(vstr);
get_fontv(fnt,currentfont);

if (bound_texture != fnt->texture)
glBindTexture(GL_TEXTURE_2D, bound_texture = fnt->texture);
get_fontv(fnt,currentfont);
bind_texture(fnt->texture);

int yy = valign == fa_top ? y+fnt->yoffset : valign == fa_middle ? y + fnt->yoffset - string_height_ext(str,sep,w)/2 : y + fnt->yoffset - string_height_ext(str,sep,w);

Expand Down Expand Up @@ -408,9 +405,7 @@ void draw_text_transformed(double x,double y,variant vstr,double xscale,double y
{
string str = toString(vstr);
get_fontv(fnt,currentfont);

if (bound_texture != fnt->texture)
glBindTexture(GL_TEXTURE_2D, bound_texture = fnt->texture);
bind_texture(fnt->texture);

rot *= M_PI/180;

Expand Down Expand Up @@ -516,9 +511,7 @@ void draw_text_ext_transformed(double x,double y,variant vstr,int sep, int w, do
{
string str = toString(vstr);
get_fontv(fnt,currentfont);

if (bound_texture != fnt->texture)
glBindTexture(GL_TEXTURE_2D, bound_texture = fnt->texture);
bind_texture(fnt->texture);

rot *= M_PI/180;

Expand Down Expand Up @@ -657,9 +650,7 @@ void draw_text_transformed_color(double x,double y,variant vstr,double xscale,do
{
string str = toString(vstr);
get_fontv(fnt,currentfont);

if (bound_texture != fnt->texture)
glBindTexture(GL_TEXTURE_2D, bound_texture = fnt->texture);
bind_texture(fnt->texture);

rot *= M_PI/180;

Expand Down Expand Up @@ -784,9 +775,7 @@ void draw_text_ext_transformed_color(double x,double y,variant vstr,int sep,int
{
string str = toString(vstr);
get_fontv(fnt,currentfont);

if (bound_texture != fnt->texture)
glBindTexture(GL_TEXTURE_2D, bound_texture = fnt->texture);
bind_texture(fnt->texture);

rot *= M_PI/180;

Expand Down Expand Up @@ -936,10 +925,8 @@ void draw_text_ext_transformed_color(double x,double y,variant vstr,int sep,int
void draw_text_color(int x,int y,variant vstr,int c1,int c2,int c3,int c4,double a)
{
string str = toString(vstr);
get_fontv(fnt,currentfont);

if (bound_texture != fnt->texture)
glBindTexture(GL_TEXTURE_2D, bound_texture = fnt->texture);
get_fontv(fnt,currentfont);
bind_texture(fnt->texture);


glPushAttrib(GL_CURRENT_BIT);
Expand Down Expand Up @@ -1034,10 +1021,8 @@ void draw_text_color(int x,int y,variant vstr,int c1,int c2,int c3,int c4,double
void draw_text_ext_color(int x,int y,variant vstr,int sep, int w, int c1,int c2,int c3,int c4,double a)
{
string str = toString(vstr);
get_fontv(fnt,currentfont);

if (bound_texture != fnt->texture)
glBindTexture(GL_TEXTURE_2D, bound_texture = fnt->texture);
get_fontv(fnt,currentfont);
bind_texture(fnt->texture);

glPushAttrib(GL_CURRENT_BIT);
int yy = valign == fa_top ? y+fnt->yoffset : valign == fa_middle ? y + fnt->yoffset - string_height_ext(str,sep,w)/2 : y + fnt->yoffset - string_height_ext(str,sep,w);
Expand Down
8 changes: 2 additions & 6 deletions ENIGMAsystem/SHELL/Graphics_Systems/OpenGL/GSprmtvs.cpp
Expand Up @@ -17,6 +17,7 @@

#include "OpenGLHeaders.h"
#include "GSprmtvs.h"
#include "binding.h"

#include <string>
#include "../../Widget_Systems/widgets_mandatory.h"
Expand All @@ -30,10 +31,6 @@ int __currentpcount[PRIMDEPTH2];
int __currentpdepth;
#endif

//namespace enigma{extern void untexture();}
namespace enigma{extern unsigned bound_texture;}
#define untexture() if(enigma::bound_texture) glBindTexture(GL_TEXTURE_2D,enigma::bound_texture = 0);

GLenum ptypes_by_id[16] = {
GL_POINTS, GL_POINTS, GL_LINES, GL_LINE_STRIP, GL_TRIANGLES,
GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_LINE_LOOP, GL_QUADS,
Expand Down Expand Up @@ -73,8 +70,7 @@ int draw_primitive_begin(int dink)

int draw_primitive_begin_texture(int dink,unsigned tex)
{
if (enigma::bound_texture != tex)
glBindTexture(GL_TEXTURE_2D, enigma::bound_texture = tex);
bind_texture(tex);
GLenum kind = ptypes_by_id[ dink & 15 ];
glBegin(kind);
return 0;
Expand Down

0 comments on commit a5bcd1b

Please sign in to comment.