Jump to content
  • Advertisement
Sign in to follow this  
pex22

OpenGL using glTexSubImage2D

This topic is 5065 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

hi, im very new in opengl and i need to take a rect from a texture so i tried this:
void CSprite::setFrame(COORD cPos,int iWidth,int iHeight)
	{
	  m_iFrame = m_iSprite; // i dont want to lose m_iSprite
	  unsigned char* pData[32][32][4];
	  glBindTexture(GL_TEXTURE_2D,m_iFrame);
	  glTexSubImage2D(GL_TEXTURE_2D,0,cPos.X,cPos.Y,iWidth,iHeight,GL_RGBA,
GL_UNSIGNED_BYTE,pData); // will it work with the pData? or not?
	  free(pData);
	};
m_iFrame and m_iSprite are UINT. i didnt made my testing program (to test the engine features) yet, but its a simple question (for opengl programmers) so i prefer asking it in a forum instead of creating the testing program for finishing the CSprite class. (im saying this if i used the glTexSubImage2D right) so, back to my question: will it work? in the create texture function i free the pData in the end of the function. : pex.

Share this post


Link to post
Share on other sites
Advertisement
glTexSubImage2D is used to copy data in system memory to a texture, NOT to copy texture data to system memory. Your program will work as far as I can see, but it will copy the (undefined) buffer pData to the rectangular area (cPos.X,...,cPos.X+iWidth-1) x (cPos.Y,...,cPos.Y+iHeight-1) to the texture m_iSprite. And be careful, pData has to be of size iWidth x iHeight x 4 (instead of 32x32x4).

If you want to copy data from a texture to system memory, then, I'm afraid, you have to draw the texture to the frame buffer first and then read it with glReadPixels (attention: slow).

Anyone plz. correct me if I'm taking rubbish.

Share this post


Link to post
Share on other sites
oops, i chose the wrong function!
oh well, thanks
but how slow is it? (if you know)
can i do sidescrolling games using it for the sprites animations? (glReadPixels for every frame? or i'll have to call glReadPixels for all the frames and put them in an array and in the RenderScene() i'll just draw each frame from the array?)

thanks again, pex. (i really need a forum signature)

Share this post


Link to post
Share on other sites
as i said before, to implement sprite animations (without using .gif, i dont know how to use it anyway)

Share this post


Link to post
Share on other sites
yeah, thats what confuses me, why do you need to read them back? surely just rendering the right texture to a quad on the screen would be slightly more... well.. sane.
As it is it seems you want to give openGL the textures, then read them back and then draw with them...

or is this for an editor so you can change the animation? in which case while you could do it like this but keeping the data in system memory and playing with it would be ALOT more sane again...

edit: missed a word out, hehe

[Edited by - _the_phantom_ on September 1, 2004 2:33:14 PM]

Share this post


Link to post
Share on other sites
That still doesn't explain why you would want to copy a texture into system memory. A typical sprite animation system would only require you to upload new texture data to the texture object each frame (assuming that the animation isn't based on a bunch of tiles inside a single image).

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!