Jump to content
  • Advertisement
Sign in to follow this  
Zmurf

Ortho Sprite Strips [Resolved]

This topic is 4615 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to make my sprites in tga strips so that they can be animated, if all my sprite sub images will be squares (say 64 x 64) how can I automatically break up the image into its sub images. Because I don't want 10,000 external recourses for each frame of every sprite. Is there an example of this that includes transparencies as well, because thats bugging me too :P. I don't really want to use sdl, cus' I prefer to just use pure OPGL, not it's sub libraries. [Edited by - Zmurf on November 6, 2005 4:28:24 AM]

Share this post


Link to post
Share on other sites
Advertisement
I can't get it to work, and that tutorial is confusing, it doesn't really explain what everything does.

Heres the code i'm using:

#ifdef _WINDOWS
#include <windows.h>
#endif

#include <gl/gl.h>
#include <gl/glu.h>
#include <math.h>

#include "Game.h"

// disable implicit float-double casting
#pragma warning(disable:4305)

CGame::CGame(){
}

CGame::~CGame(){
}

bool CGame::Init(){
// clear to black background
glClearColor(0.0, 0.6, 0.0, 1.0);

m_Uncompressed = new CTargaImage;

if (!m_Uncompressed->Load("Test.tga"))
return false;

glGenTextures(1, &m_Sprite);

return true;
}

bool CGame::Shutdown(){
glDeleteTextures(1, &m_Sprite);
m_Uncompressed->Release();
delete m_Uncompressed;

return true;
}

void CGame::GameLoop(){
glColor4f(1.0f,1.0f,1.0f,1.0f);
glEnable(GL_TEXTURE_2D);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glAlphaFunc(GL_GREATER,0.1f);

// clear screen and depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

glEnable(GL_BLEND);
glEnable(GL_ALPHA_TEST);

glBindTexture(GL_TEXTURE_2D, m_Sprite); // Select The Correct Texture
glBegin(GL_QUADS); // Start Drawing A Quad
glTexCoord2f(0.0f,0.0f); glVertex2i( 20, 148); // Bottom Left
glTexCoord2f(1.0f,0.0f); glVertex2i(276, 148); // Bottom Right
glTexCoord2f(1.0f,1.0f); glVertex2i(276, 20); // Top Right
glTexCoord2f(0.0f,1.0f); glVertex2i( 20, 20); // Top Left
glEnd(); // Done Drawing Quad
}

Share this post


Link to post
Share on other sites
You could hae a 256x256 image and break it up into 16 64x64 sprites. Store them as sprite[0] to sprite[15]. In an index file store the anmiation keyframes, like 'jump' could be: 0 12 4 2 0, so that sprite[0], sprite[12], sprite[4], sprite[2], sprite[0] when shown one after the other make a jump.

How to do transparency is mentioned well in the wiki article- enable alpha testing, set the glAlphaFunc to GREATER than a small value such as 0.1, enable blending with BlendFunc (SRC_ALPHA, ONE_MINUS_SRC_ALPHA), and draw your half transparent sprite.

Share this post


Link to post
Share on other sites
thats what i do in my code, but it still shows up with a white background, i just want the image without the white background.

It's also not showing the image anymore. ><

Share this post


Link to post
Share on other sites
In glTexImage2D. Also make sure you've enabled alpha testing.

edit: also, make sure the image you're loading has the alpha channel. Since your code says tga, I don't think anyone clarified that point. Leaving portions 'white' or any other color won't make them transparent - there is no automatic colorkeying in OpenGL. You need to have the alpha channel, and set source format and internal format as GL_RGBA in glTexImage2D. (This is assuming you don't have the alpha channel, of course, if you have, then you're already laughing [smile]).

Share this post


Link to post
Share on other sites
how do i add alpha channels to my image? is it something that must be done in my photoshop program, or does ogl handle it?

in the tga loader class theres an rgbtorgba function, but it takes 'unsigned char alphaValue' as an argument, shoudl i use this? and what should the agument value be?

[Edit]:

ok i've changed my code to this:

#ifdef _WINDOWS
#include <windows.h>
#endif

#include <gl/gl.h>
#include <gl/glu.h>
#include <math.h>

#include "Game.h"

// disable implicit float-double casting
#pragma warning(disable:4305)

CGame::CGame(){
}

CGame::~CGame(){
}

bool CGame::Init(){
// clear to black background
glClearColor(0.0, 0.0, 0.0, 1.0);

m_Uncompressed = new CTargaImage;

if (!m_Uncompressed->Load("Test.tga"))
return false;

glGenTextures(1, &m_Sprite);

glBindTexture(GL_TEXTURE_2D, m_Sprite); // Select The Correct Texture

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_Uncompressed->GetWidth(), m_Uncompressed->GetHeight(),
0, GL_RGBA, GL_UNSIGNED_BYTE, m_Uncompressed->GetImage());

return true;
}

bool CGame::Shutdown(){
glDeleteTextures(1, &m_Sprite);
m_Uncompressed->Release();
delete m_Uncompressed;

return true;
}

void CGame::GameLoop(){
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glEnable(GL_TEXTURE_2D);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glAlphaFunc(GL_GREATER,0.1f);

// clear screen and depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

glEnable(GL_BLEND);
glEnable(GL_ALPHA_TEST);

glBegin(GL_QUADS); // Start Drawing A Quad
glTexCoord2f(0.0f,0.0f); glVertex2i( 20, 20); // Bottom Left
glTexCoord2f(1.0f,0.0f); glVertex2i(276, 20); // Bottom Right
glTexCoord2f(1.0f,1.0f); glVertex2i(276, 148); // Top Right
glTexCoord2f(0.0f,1.0f); glVertex2i( 20, 148); // Top Left
glEnd(); // Done Drawing Quad
}


I've added the glTexImage2D(); and the image shows p[roperly, but when i change the GL_RGB -> GL_RGBA it causes the following runtime error:

Quote:
Unhandled exception at 0x0885ff61 in Game.exe: 0xC0000005: Access violation reading location 0x08c4a000.


[Edited by - Zmurf on November 5, 2005 10:36:23 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!