[Change] Some openGL cleanup.
This commit is contained in:
parent
8f7ec2fa09
commit
6552fc2cf2
53
src/opengl.c
53
src/opengl.c
@ -355,17 +355,18 @@ void gl_getSpriteFromDir(int* x, int* y, const glTexture* t, const double dir) {
|
||||
// Blit the sprite at given position.
|
||||
void gl_blitSprite(const glTexture* sprite, const double bx, const double by,
|
||||
const int sx, const int sy, const glColour* c) {
|
||||
|
||||
// Don't bother drawing if offscreen -- waste of cycles.
|
||||
if(fabs(bx-VX(*gl_camera)+gui_xoff) > gl_screen.w / 2 + sprite->sw / 2 ||
|
||||
fabs(by-VY(*gl_camera)+gui_yoff) > gl_screen.h / 2 + sprite->sh / 2)
|
||||
if(fabs(bx-VX(*gl_camera)+gui_xoff) > SCREEN_W / 2 + sprite->sw / 2 ||
|
||||
fabs(by-VY(*gl_camera)+gui_yoff) > SCREEN_H / 2 + sprite->sh / 2)
|
||||
return;
|
||||
|
||||
double x, y, tx, ty;
|
||||
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
x = bx - VX(*gl_camera) - sprite->sw/2. + gui_xoff;
|
||||
y = by - VY(*gl_camera) - sprite->sh/2. + gui_yoff;
|
||||
x = bx - (double)SCREEN_W/2.;
|
||||
y = by - (double)SCREEN_H/2.;
|
||||
|
||||
tx = sprite->sw * (double)(sx)/sprite->rw;
|
||||
ty = sprite->sh * (sprite->sy-(double)sy-1)/sprite->rh;
|
||||
@ -578,8 +579,8 @@ static GLboolean gl_hasExt(char* name) {
|
||||
}
|
||||
|
||||
// Check and report if there's been an error.
|
||||
#ifndef gl_checkErr // I know, I know, it's a little hackish.
|
||||
void gl_checkErr(void) {
|
||||
#ifdef DEBUG
|
||||
GLenum err;
|
||||
char* errstr;
|
||||
|
||||
@ -614,8 +615,8 @@ void gl_checkErr(void) {
|
||||
break;
|
||||
}
|
||||
WARN("OpenGL error: %s", errstr);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
// Initialize SDL/OpenGL etc.
|
||||
int gl_init(void) {
|
||||
@ -648,8 +649,8 @@ int gl_init(void) {
|
||||
DEBUG("Available fullscreen modes:");
|
||||
for(i = 0; modes[i]; i++) {
|
||||
DEBUG("\t%dx%d", modes[i]->w, modes[i]->h);
|
||||
if((flags & SDL_FULLSCREEN) && (modes[i]->w == gl_screen.w) &&
|
||||
(modes[i]->h == gl_screen.h))
|
||||
if((flags & SDL_FULLSCREEN) && (modes[i]->w == SCREEN_W) &&
|
||||
(modes[i]->h == SCREEN_H))
|
||||
supported = 1; // Mode we asked for is supported.
|
||||
}
|
||||
}
|
||||
@ -660,14 +661,15 @@ int gl_init(void) {
|
||||
off = -1;
|
||||
j = 0;
|
||||
for(i = 0; modes[i]; i++) {
|
||||
toff = ABS(gl_screen.w-modes[i]->w) + ABS(gl_screen.h-modes[i]->h);
|
||||
toff = ABS(SCREEN_W-modes[i]->w) + ABS(SCREEN_H-modes[i]->h);
|
||||
if((off == -1) || (toff < off)) {
|
||||
j = i;
|
||||
off = toff;
|
||||
}
|
||||
}
|
||||
WARN("Fullscreen mode %dx%d is not supported by your setup\n"
|
||||
" Switching to %dx%d", gl_screen.w, gl_screen.h,
|
||||
" Switching to %dx%d",
|
||||
SCREEN_W, SCREEN_H,
|
||||
modes[j]->w, modes[j]->h);
|
||||
|
||||
gl_screen.w = modes[j]->w;
|
||||
@ -676,18 +678,18 @@ int gl_init(void) {
|
||||
}
|
||||
|
||||
// Test the setup - aim for 32.
|
||||
depth = SDL_VideoModeOK(gl_screen.w, gl_screen.h, gl_screen.depth, flags);
|
||||
depth = SDL_VideoModeOK(SCREEN_W, SCREEN_H, gl_screen.depth, flags);
|
||||
if(depth == 0)
|
||||
WARN("Video mode %dx%d @ %d bpp not supported"
|
||||
" going to try to create it anyway...",
|
||||
gl_screen.w, gl_screen.h, gl_screen.depth);
|
||||
SCREEN_W, SCREEN_H, gl_screen.depth);
|
||||
if(depth != gl_screen.depth)
|
||||
LOG("Depth: %d bpp unavailable, will use %d bpp", gl_screen.depth, depth);
|
||||
|
||||
gl_screen.depth = depth;
|
||||
|
||||
// Actually creating the screen.
|
||||
if(SDL_SetVideoMode(gl_screen.w, gl_screen.h, gl_screen.depth, flags) == NULL) {
|
||||
if(SDL_SetVideoMode(SCREEN_W, SCREEN_H, gl_screen.depth, flags) == NULL) {
|
||||
ERR("Unable to create OpenGL window: %s", SDL_GetError());
|
||||
return -1;
|
||||
}
|
||||
@ -707,24 +709,31 @@ int gl_init(void) {
|
||||
if(gl_hasExt("GL_ARB_fragment_shader")==GL_TRUE)
|
||||
gl_screen.flags |= OPENGL_FRAG_SHADER;
|
||||
|
||||
// Max texture size.
|
||||
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &gl_screen.tex_max);
|
||||
|
||||
// Debug heaven.
|
||||
DEBUG("OpenGL Window Created: %dx%d@%dbpp %s", gl_screen.w, gl_screen.h,
|
||||
DEBUG("OpenGL Window Created: %dx%d@%dbpp %s", SCREEN_W, SCREEN_H,
|
||||
gl_screen.depth, (gl_has(OPENGL_FULLSCREEN)) ? "fullscreen" : "window");
|
||||
|
||||
DEBUG("r: %d, g: %d, b: %d, a: %d, doublebuffer: %s",
|
||||
DEBUG("r: %d, g: %d, b: %d, a: %d, db: %s, tex: %d",
|
||||
gl_screen.r, gl_screen.g, gl_screen.b, gl_screen.a,
|
||||
(gl_has(OPENGL_DOUBLEBUF)) ? "yes" : "no");
|
||||
gl_has(OPENGL_DOUBLEBUF) ? "yes" : "no",
|
||||
gl_screen.tex_max);
|
||||
|
||||
DEBUG("Renderer: %s", glGetString(GL_RENDERER));
|
||||
if(!gl_has(OPENGL_FRAG_SHADER))
|
||||
DEBUG("No fragment shader extension detected");
|
||||
DEBUG("");
|
||||
|
||||
// Some openGL options.
|
||||
glClearColor(0., 0., 0., 1.);
|
||||
glDisable(GL_DEPTH_TEST); // Set for doing 2D shidazles.
|
||||
//glEnable(GL_TEXTURE_2D); // Don't enable globally, it will break non-texture blits.
|
||||
glDisable(GL_LIGHTING); // No lighting, it is done when rendered.
|
||||
glEnable(GL_BLEND);
|
||||
glShadeModel(GL_FLAT); // Default shade model. Functions should keep this when done..
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glDisable(GL_DEPTH_TEST); // Set for doing 2D shidazles.
|
||||
//glEnable(GL_TEXTURE_2D); // Don't enable globally, it will break non-texture blits.
|
||||
glDisable(GL_LIGHTING); // No lighting, it is done when rendered.
|
||||
glEnable(GL_BLEND); // Alpha blending ftw.
|
||||
glShadeModel(GL_FLAT); // Default shade model. Functions should keep this when done..
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Good blend model.
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glOrtho(-SCREEN_W /2, // Left edge.
|
||||
|
@ -32,6 +32,7 @@ typedef struct glInfo_ {
|
||||
int depth; // Depth in bpp.
|
||||
int r, g, b, a; // Framebuffer values in bits.
|
||||
int flags; // Store different properties.
|
||||
int tex_max; // Max texture size.
|
||||
} glInfo;
|
||||
extern glInfo gl_screen; // Local structure set with gl_init etc.
|
||||
|
||||
@ -79,5 +80,9 @@ void gl_exit(void);
|
||||
int gl_isTrans(const glTexture* t, const int x, const int y);
|
||||
void gl_getSpriteFromDir(int* x, int* y, const glTexture* t, const double dir);
|
||||
void gl_screenshot(const char* filename);
|
||||
#if DEBUG == 1
|
||||
void gl_checkErr(void);
|
||||
#else
|
||||
#define gl_checkErr()
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user