Mercurial > sdl-ios-xcode
comparison src/video/SDL_renderer_gl.c @ 1922:4905cac7a4bd
Fixed OpenGL blend modes, added power of 2 texture code
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 22 Jul 2006 19:03:31 +0000 |
parents | f3399f779a1d |
children | d4572b97b08f |
comparison
equal
deleted
inserted
replaced
1921:f3399f779a1d | 1922:4905cac7a4bd |
---|---|
192 /* FIXME: Check for GL_ARB_texture_rectangle and GL_EXT_texture_rectangle */ | 192 /* FIXME: Check for GL_ARB_texture_rectangle and GL_EXT_texture_rectangle */ |
193 | 193 |
194 /* Set up parameters for rendering */ | 194 /* Set up parameters for rendering */ |
195 glDisable(GL_DEPTH_TEST); | 195 glDisable(GL_DEPTH_TEST); |
196 glDisable(GL_CULL_FACE); | 196 glDisable(GL_CULL_FACE); |
197 #ifdef USE_GL_TEXTURE_RECTANGLE | |
198 glEnable(GL_TEXTURE_RECTANGLE_ARB); | |
199 #else | |
197 glEnable(GL_TEXTURE_2D); | 200 glEnable(GL_TEXTURE_2D); |
198 glEnable(GL_TEXTURE_RECTANGLE_ARB); | 201 #endif |
199 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); | |
200 glMatrixMode(GL_PROJECTION); | 202 glMatrixMode(GL_PROJECTION); |
201 glLoadIdentity(); | 203 glLoadIdentity(); |
202 glMatrixMode(GL_MODELVIEW); | 204 glMatrixMode(GL_MODELVIEW); |
203 glLoadIdentity(); | 205 glLoadIdentity(); |
204 glViewport(0, 0, window->w, window->h); | 206 glViewport(0, 0, window->w, window->h); |
205 glOrtho(0.0, (GLdouble) window->w, (GLdouble) window->h, 0.0, 0.0, 1.0); | 207 glOrtho(0.0, (GLdouble) window->w, (GLdouble) window->h, 0.0, 0.0, 1.0); |
206 | 208 |
207 return renderer; | 209 return renderer; |
208 } | 210 } |
209 | 211 |
212 static __inline__ int | |
213 power_of_2(int input) | |
214 { | |
215 int value = 1; | |
216 | |
217 while (value < input) { | |
218 value <<= 1; | |
219 } | |
220 return value; | |
221 } | |
222 | |
210 static int | 223 static int |
211 GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) | 224 GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) |
212 { | 225 { |
213 GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata; | 226 GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata; |
214 SDL_Window *window = SDL_GetWindowFromID(renderer->window); | 227 SDL_Window *window = SDL_GetWindowFromID(renderer->window); |
215 GL_TextureData *data; | 228 GL_TextureData *data; |
216 GLint internalFormat; | 229 GLint internalFormat; |
217 GLenum format, type; | 230 GLenum format, type; |
231 int texture_w, texture_h; | |
218 | 232 |
219 switch (texture->format) { | 233 switch (texture->format) { |
220 case SDL_PixelFormat_Index1LSB: | 234 case SDL_PixelFormat_Index1LSB: |
221 case SDL_PixelFormat_Index1MSB: | 235 case SDL_PixelFormat_Index1MSB: |
222 internalFormat = GL_RGB; | 236 internalFormat = GL_RGB; |
316 | 330 |
317 texture->driverdata = data; | 331 texture->driverdata = data; |
318 | 332 |
319 /* FIXME: Check for GL_ARB_texture_rectangle and GL_EXT_texture_rectangle */ | 333 /* FIXME: Check for GL_ARB_texture_rectangle and GL_EXT_texture_rectangle */ |
320 glGenTextures(1, &data->texture); | 334 glGenTextures(1, &data->texture); |
335 #ifdef USE_GL_TEXTURE_RECTANGLE | |
321 data->type = GL_TEXTURE_RECTANGLE_ARB; | 336 data->type = GL_TEXTURE_RECTANGLE_ARB; |
337 texture_w = texture->w; | |
338 texture_h = texture->h; | |
322 data->texw = (GLfloat) texture->w; | 339 data->texw = (GLfloat) texture->w; |
323 data->texh = (GLfloat) texture->h; | 340 data->texh = (GLfloat) texture->h; |
341 #else | |
342 data->type = GL_TEXTURE_2D; | |
343 texture_w = power_of_2(texture->w); | |
344 texture_h = power_of_2(texture->h); | |
345 data->texw = (GLfloat) texture->w / texture_w; | |
346 data->texh = (GLfloat) texture->h / texture_h; | |
347 #endif | |
324 data->format = format; | 348 data->format = format; |
325 data->formattype = type; | 349 data->formattype = type; |
326 glBindTexture(data->type, data->texture); | 350 glBindTexture(data->type, data->texture); |
327 glTexImage2D(data->type, 0, internalFormat, texture->w, texture->h, 0, | 351 glTexImage2D(data->type, 0, internalFormat, texture_w, texture_h, 0, |
328 format, type, NULL); | 352 format, type, NULL); |
329 | 353 |
330 return 0; | 354 return 0; |
331 } | 355 } |
332 | 356 |
476 | 500 |
477 glBindTexture(texturedata->type, texturedata->texture); | 501 glBindTexture(texturedata->type, texturedata->texture); |
478 | 502 |
479 switch (blendMode) { | 503 switch (blendMode) { |
480 case SDL_TextureBlendMode_None: | 504 case SDL_TextureBlendMode_None: |
505 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); | |
481 glDisable(GL_BLEND); | 506 glDisable(GL_BLEND); |
482 break; | 507 break; |
483 case SDL_TextureBlendMode_Mask: | 508 case SDL_TextureBlendMode_Mask: |
484 case SDL_TextureBlendMode_Blend: | 509 case SDL_TextureBlendMode_Blend: |
510 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); | |
485 glEnable(GL_BLEND); | 511 glEnable(GL_BLEND); |
486 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | 512 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
487 break; | 513 break; |
488 case SDL_TextureBlendMode_Add: | 514 case SDL_TextureBlendMode_Add: |
515 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); | |
489 glEnable(GL_BLEND); | 516 glEnable(GL_BLEND); |
490 glBlendFunc(GL_SRC_ALPHA, GL_ONE); | 517 glBlendFunc(GL_SRC_ALPHA, GL_ONE); |
491 break; | 518 break; |
492 case SDL_TextureBlendMode_Mod: | 519 case SDL_TextureBlendMode_Mod: |
520 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); | |
493 glEnable(GL_BLEND); | 521 glEnable(GL_BLEND); |
494 glBlendFunc(GL_ZERO, GL_SRC_COLOR); | 522 glBlendFunc(GL_ZERO, GL_SRC_COLOR); |
495 break; | 523 break; |
496 } | 524 } |
497 | 525 |
500 case SDL_TextureScaleMode_Fast: | 528 case SDL_TextureScaleMode_Fast: |
501 glTexParameteri(texturedata->type, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 529 glTexParameteri(texturedata->type, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
502 glTexParameteri(texturedata->type, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 530 glTexParameteri(texturedata->type, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
503 break; | 531 break; |
504 case SDL_TextureScaleMode_Slow: | 532 case SDL_TextureScaleMode_Slow: |
533 case SDL_TextureScaleMode_Best: | |
505 glTexParameteri(texturedata->type, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 534 glTexParameteri(texturedata->type, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
506 glTexParameteri(texturedata->type, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 535 glTexParameteri(texturedata->type, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
507 break; | 536 break; |
508 } | 537 } |
509 | 538 |