Jump to content
  • Advertisement

codemastermm

Member
  • Content Count

    69
  • Joined

  • Last visited

Community Reputation

148 Neutral

About codemastermm

  • Rank
    Member
  1. codemastermm

    [Solved] SDL Image Transparency Issues

    My apologies for double-posting, but I've managed to solve my issue! I did two things to fix my problem (1) I converted my SDL_Surface to the display format before applying the color key, etc. (2) I enabled GL_BLEND with the following: glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); Here's my revised transparency function: SDL_Surface* Texture::enableTransparency(SDL_Surface *surface) { if(!surface) return NULL; // Convert the surface to be formatted to our display format SDL_Surface *formatted_surface = SDL_DisplayFormat(surface); // We can remove the surface since it is no longer needed SDL_FreeSurface(surface); // Obtain the color we want to be transparent Uint32 colorKey = getPixel(formatted_surface, 0, 0); Uint32 rmask, gmask, bmask, amask; // Setup the RGBA mask depending on the system's endian #if SDL_BYTEORDER == SDL_BIG_ENDIAN rmask = 0xff000000; gmask = 0x00ff0000; bmask = 0x0000ff00; amask = 0x000000ff; #else rmask = 0x000000ff; gmask = 0x0000ff00; bmask = 0x00ff0000; amask = 0xff000000; #endif // Set the color to be transparent if(SDL_SetColorKey(formatted_surface, SDL_SRCCOLORKEY, colorKey) < 0) throw Exception(SDL_GetError()); // Create a new empty surface that will hold the blitted image // Use 32-bit bits per pixel to store alpha values SDL_Surface *temp = SDL_CreateRGBSurface(SDL_SWSURFACE, formatted_surface->w, formatted_surface->h, 32, rmask, gmask, bmask, amask); // Blit the actual image over! if(SDL_BlitSurface(formatted_surface, NULL, temp, NULL) < 0) throw Exception(SDL_GetError()); // We can free the original surface, since we no longer need it SDL_FreeSurface(formatted_surface); // Return the finalized surface return; temp; } I also think I will be rewriting these static functions to simply set the provided SDL_Surface pointer to the new finalized surface instead of having to return it, but that's pretty easy to do :)
  2. codemastermm

    [Solved] SDL Image Transparency Issues

    Wow, thank you rip-off! I had no idea that RLE encoding would possibly be decremental. I also had no idea that SDL_DisplayFormatAlpha would undo the work that my function was performing. As for the function itself, it is static (so it isn't modifying anything - it's just a helper function really :)) and the documentation stated that the input surface will be destroyed. However, with the changes you recommended, it seems that I won't have to destroy the surface - even better! Here's what I have now for that function, however it still outputs a black area when rendering. SDL_Surface* Texture::enableTransparency(SDL_Surface *surface) { if(!surface) return NULL; Uint32 rmask, gmask, bmask, amask; // Setup the RGBA mask depending on the system's endian #if SDL_BYTEORDER == SDL_BIG_ENDIAN rmask = 0xff000000; gmask = 0x00ff0000; bmask = 0x0000ff00; amask = 0x000000ff; #else rmask = 0x000000ff; gmask = 0x0000ff00; bmask = 0x00ff0000; amask = 0xff000000; #endif // Obtain the color we want to be transparent Uint32 colorKey = getPixel(surface, 0, 0); // Set the color to be transparent if(SDL_SetColorKey(surface, SDL_SRCCOLORKEY, colorKey) < 0) throw Exception(SDL_GetError()); // Create a new empty surface that will hold the blitted image // Use 32-bit bits per pixel to store alpha values SDL_Surface *temp = SDL_CreateRGBSurface(SDL_SWSURFACE, surface->w, surface->h, 32, rmask, gmask, bmask, amask); // Blit the actual image over! if(SDL_BlitSurface(surface, NULL, temp, NULL) < 0) throw Exception(SDL_GetError()); // We can free the original surface, since we no longer need it SDL_FreeSurface(surface); return temp; } [Edited by - codemastermm on June 6, 2009 10:50:58 PM]
  3. After scouring the GameDev forums (as well as other sources) for a few days, now, I've decided to post my issues to see if I can fix this odd thing. Nonetheless, my issue is that I am attempting to load an image (via the SDL_image library), remove the background (usually magenta or bright green), and render it out via OpenGL as a texture with transparency. It currently works without attempting transparency (so my SDL_Surface to OpenGL texture process works), but the issues begin when I try to have transparency. Using the following process, the texture returned is completely black, which I found very odd. SDL_Surface* Texture::enableTransparency(SDL_Surface *surface) { if(!surface) return NULL; Uint32 rmask, gmask, bmask, amask; // Setup the RGBA mask depending on the system's endian #if SDL_BYTEORDER == SDL_BIG_ENDIAN rmask = 0xff000000; gmask = 0x00ff0000; bmask = 0x0000ff00; amask = 0x000000ff; #else rmask = 0x000000ff; gmask = 0x0000ff00; bmask = 0x00ff0000; amask = 0xff000000; #endif // Obtain the color we want to be transparent Uint32 colorKey = getPixel(surface, 0, 0); // Set the color to be transparent if(SDL_SetColorKey(surface, SDL_SRCALPHA | SDL_RLEACCEL, colorKey) < 0) throw Exception(SDL_GetError()); // Set the alpha transparency to be completely transparent if(SDL_SetAlpha(surface, SDL_SRCALPHA | SDL_RLEACCEL, SDL_ALPHA_TRANSPARENT) < 0) throw Exception(SDL_GetError()); // Create a new empty surface that will hold the blitted image // Use 32-bit bits per pixel to store alpha values SDL_Surface *temp = SDL_CreateRGBSurface(SDL_SRCALPHA | SDL_RLEACCEL | surface->flags, surface->w, surface->h, 32, rmask, gmask, bmask, amask); // Blit the actual image over! if(SDL_BlitSurface(surface, NULL, temp, NULL) < 0) throw Exception(SDL_GetError()); // We can free the original surface, since we no longer need it SDL_FreeSurface(surface); // Return the final surface that will hold the transparent image surface SDL_Surface* ret = SDL_DisplayFormatAlpha(temp); return ret; } Uint32 Texture::getPixel(SDL_Surface* get_surface, int x, int y) { if(!get_surface) { throw Exception("Surface is NULL"); return 0; } if(x < 0 || x > get_surface->w || y < 0 || y > get_surface->h) { throw Exception("Invalid position"); return 0; } if(SDL_LockSurface(get_surface) < 0) throw Exception(SDL_GetError()); int bpp = get_surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)get_surface->pixels + y * get_surface->pitch + x * bpp; Uint32 ret = 0; switch(bpp) { case 1: ret = *p; break; case 2: ret = *(Uint16 *)p; break; case 3: if(SDL_BYTEORDER == SDL_BIG_ENDIAN) ret = (p[0] << 16 | p[1] << 8 | p[2]); else ret = (p[0] | p[1] << 8 | p[2] << 16); break; case 4: ret = *(Uint32 *)p; break; default: ret = 0; break; } SDL_UnlockSurface(get_surface); return ret; } I've also noted a few people discussing the various uses of GL_BLEND and the blending function to go along with it. I currently have GL_BLEND disabled (as I wasn't sure how to set it up). Should I have GL_BLEND enabled? (I am presuming yes) If so, what blending function should I use? It seems glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) is the most popular. Thanks for any help! Any posts will be a great help. [Edited by - codemastermm on June 6, 2009 11:39:25 PM]
  4. I'm attempting to generate a texture (for use in OpenGL fonts) holding all of the possible unicode letters in a certain language (for example, if the person is using a computer that is localized to Japanese, it will render all of the possible Japanese characters to this texture). My only problem is this: I am unsure how to (A) detect the user's localized language (I plan on making this cross-platform, so I have to get this working on Windows, Mac, and Linux) and (B) how to obtain all of the renderable characters of that certain language in unicode (for example, I don't want to render 'delete', of course). Any help in this is greatly appreciated.
  5. codemastermm

    [Solved] Z coordinate clipping?

    yep, TGA and jpetrie were correct; it was that I was using positive values instead of negative (since OpenGL uses right-handed coordinates, while I was thinking in left-handed coordinates). Thanks! I was feeling horrid because I was stuck on something so minor and easy.
  6. codemastermm

    [Solved] Z coordinate clipping?

    It seems that if I change the gluPerspective call's near parameter to something beyond 0.0f, the cube fails to render (if I place it as 0.0f, it renders exactly where I want it, but only if I set the Z coordinate to <= 0.75f) I tried setting it to 0.1f,1000.0f and it revealed no luck for me, so I am unsure if jouley's extra changes helped anything.
  7. codemastermm

    [Solved] Z coordinate clipping?

    I changed my gluPerspective to use 1.0f and 1000. and still had no luck :(
  8. I recently made this small function to create a basic Cube with only passing a few parameters. The odd problem is, though, that when I pass in anything from 0 ~ 0.75f for the Z parameter, it draws properly, but when I place 0.76f ~ 1 as the Z paramter, i am unable to see it (although it continues to go through the function). I tried already changing my gluPerspective() call to have a larger clipping area, but that did not provide any effect (as the clipping area passed to gluPerspective was from 0 to 100 anyway). Here's the code: // x, y, z are coordinates // size The length/size of each of the cube's edges // center is true if the coordinates are the center of the cube // ...and is false if the coordinates are the top-left front of the cube // fill is whether the cube is filled or an outline void drawCube(GLfloat x, GLfloat y, GLfloat z, GLfloat size, bool center, bool fill) { if(size == 0) return; float x_p, x_m, y_p, y_m, z_p, z_m; if(center == false) { x_p = x + size; x_m = x; y_p = y; y_m = y - size; z_p = z + size; z_m = z; } else { float half_size = (size / 2); x_p = x + half_size; x_m = x - half_size; y_p = y + half_size; y_m = y - half_size; z_p = z + half_size; z_m = z - half_size; } // Front glBegin((fill == true) ? GL_QUADS : GL_LINE_LOOP); glVertex3f(x_m, y_p, z_m); glVertex3f(x_p, y_p, z_m); glVertex3f(x_p, y_m, z_m); glVertex3f(x_m, y_m, z_m); glEnd(); // Right Side glBegin((fill == true) ? GL_QUADS : GL_LINE_LOOP); glVertex3f(x_p, y_p, z_m); glVertex3f(x_p, y_p, z_p); glVertex3f(x_p, y_m, z_p); glVertex3f(x_p, y_m, z_m); glEnd(); // Back glBegin((fill == true) ? GL_QUADS : GL_LINE_LOOP); glVertex3f(x_p, y_p, z_p); glVertex3f(x_m, y_p, z_p); glVertex3f(x_m, y_m, z_p); glVertex3f(x_p, y_m, z_p); glEnd(); // Left Side glBegin((fill == true) ? GL_QUADS : GL_LINE_LOOP); glVertex3f(x_m, y_p, z_p); glVertex3f(x_m, y_p, z_m); glVertex3f(x_m, y_m, z_m); glVertex3f(x_m, y_m, z_p); glEnd(); // Bottom glBegin((fill == true) ? GL_QUADS : GL_LINE_LOOP); glVertex3f(x_m, y_m, z_p); glVertex3f(x_p, y_m, z_p); glVertex3f(x_p, y_m, z_m); glVertex3f(x_m, y_m, z_m); glEnd(); // Top glBegin((fill == true) ? GL_QUADS : GL_LINE_LOOP); glVertex3f(x_m, y_p, z_p); glVertex3f(x_p, y_p, z_p); glVertex3f(x_p, y_p, z_m); glVertex3f(x_m, y_p, z_m); glEnd(); return; } Any help is appreciated; thanks! [Edited by - codemastermm on January 30, 2007 10:44:45 AM]
  9. I have recently read a few articles describing Procedural Generation of Textures and how the textures are stored in mathematical algorithms and generated for gameplay instead of being simply loaded from a flat image file. Has anyone ever actually used procedural generation? I'd like to learn a bit more about this, but there is a lack of documentation or tutorials on the subject. It seems that many games are heading towards this feature because not only does it decrease the filesize of the game, but it also makes the graphics and/or textures scalable (such as if I played it on an older system, the graphics would be less beautiful, but the game would run fine and if I played it on my brand new system, it will look gorgeous and run just the same). Thanks for any help on this subject!
  10. codemastermm

    Best texture type/size for OpenGL

    I tend to use PNGs (since they already have an alpha value for the texture) that have a power-of-two width and height, such as 256x512, 512x512 and such. I try to stay away from textures over 1024x1024, unless necessary.
  11. I've recently been reading into the 3D map files once more and I've noticed that the most popular file format currently is the BSP. I've also read a few posts in this forum whereas they have mentioned that Quadtrees and Octrees and Portals might be good ways of rendering and dealing with maps (also with collision). I feel that I should use Octress as I will be rendering a large amount of outside areas. With that aside, are there any examples of an octree map being loaded (perhaps from a .map or .bsp file or another form of standardized file format for maps) and then rendered in OpenGL? Thanks much for any help!
  12. codemastermm

    MD5 Model Loader

    Yep, I've been there and read up on them. The viewers they provide work quite well, I must say, but they are bloated with various other things... I'm currently attempting my best to tear apart one of their viewers and reassembling it.
  13. codemastermm

    MD5 Model Loader

    I've began rewriting my Game Engine recently and have successfully finished the 2D portion (hooray). Now the problem comes that I am going to work on the 3D portion. I have chosen to use the MD5 models since they are skeletal, thus have their animations separate, and look very nice. I have began looking all over for MD5 Model loaders and MD5 Model documentation (which I have found). The only problem is that the loaders that I have found either do not display enough (such as they only show to load them or only display wire frames) or are too robust (such as depending upon many extensions or using LEX or YACC, etc.). So, I am asking if there are any decent, pure MD5 Loaders out there that anyone has happened to bump into. If not, would someone be able to assist me in providing source code for such a sample? Thanks much!
  14. codemastermm

    can't open my .exes!

    Perhaps you can run Dependency Walker on it to see what DLL(s) you might be forgetting to include. Another problem might be that you did not compile the program in 'Release' and give it to him. (Normally, Debug is for you, the developer, and Release is for your end-users)
  15. codemastermm

    Making a sound engine

    I recently made my own sound engine, so I went through the same ordeals - what library to use, what format to use, and the such. I ended up using OpenAL as my sound library, for a variety of reasons. A few of them being that I was going to code my graphics engine in OpenGL, so the code similarity would be helpful; OpenAL is open-source, which is always good (thus, gratis as well); and finally, OpenAL does very well with 3D sounds, which can always be a great thing. I also ended up choosing the Ogg Vorbis format for my sound files, since WAV is too large of a filesize and MP3 required payments to use. Ogg compresses much better than MP3, is also open-source, has a community around itself if I ever needed help. Also, Ogg doesn't seem to come default on machines, so most people who used my sound engine wouldn't be able to play the sounds or music that I used in it in their media programs (unless they happened to have the Ogg codec installed and such). Good luck with your engine nonetheless though! :D Also, if you get any headway on that lip-syncing, let me know - it sounds interesting :)
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!