Skip to main content
gamedev.net
🔒 Locked

gltexsubimage2d() issues

Started by escudo825 Aug 28, 2006 at 10:26 PM 7 replies 2k views
Original Post
escudo825
escudo825
I am currently working on my own little 2d engine. the only problem I had was I had only glteximage2d to do all of my sprites, so I couldn't take frames from a sprite sheet. then I discovered gltexsubimage2d. the only problem I have is that the sprite displays as a white square. displaying it like a normal texture works fine, so I'm assuming that the rendering is fine, so here is what I have for the lines of code that seem important:

    glBindTexture(GL_TEXTURE_2D, tex);        
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
     glTexImage2D(GL_TEXTURE_2D, 0, 3, BMP.bmWidth, BMP.bmHeight, 0, GL_BGR, GL_UNSIGNED_BYTE, BMP.bmBits);//this line it loads and displays perfectly
    //glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 64, 64, GL_BGR, GL_UNSIGNED_BYTE, BMP.bmBits);//this line should in theory work perfect too, but it doesn't work at all


is there something I'm not doing right? or could something else be the problem. thanks to whoever helps, this has been annoying me for nearly a week.
Digitalfragment
Digitalfragment
glTexSubImage2D is used to write data into an texture that has already been created, it doesnt create the texture itself
escudo825
escudo825
ah, so I need to make another texture and copy it to that somehow? the redbook never explained that. I'll look into it alittle more and get back tommorow, since I'll need to get off soon.
Digitalfragment
Digitalfragment
The Redbook actually explains that it quite well. You supply a small set of data that is to go into a smaller area of the original image. It sounds like this isnt actually what you want to do. You want to either, crop the incoming image and write each sprite into its own texture (you have to do that manually) or, load the sprite sheet in as a single texture, and then manipulate your texture coordinates so that you only use a fraction of the texture for each sprite.
escudo825
escudo825
oh, darn, so I will have to do it the hard way? because I think I remember DX having something like what I thought texsub... was, so I assumed OpenGL would have something. does it not? if so I'll go back to plan a.
Digitalfragment
Digitalfragment
What is the actual effect of texsub in DirectX? (I dont know much DX) I may be able to point you to something similar.

But usually to use a sprite sheet you would just used cropped texture coordinates.
escudo825
escudo825
I'll have to track it down, may have been directdraw. in which case it no longer exists. and I don't know any D3D, so now that I think of it there may be no equivalent. I find the directdraw aquivalent and get back tommorow, I need to get to bed.
Digitalfragment
Digitalfragment
okay, PM me to remind me to reply. I need to get back to work, lol.
escudo825
escudo825
well actually I can't track it down, I guess I'll have to do it the hard way unless someone can come up with something that works. after I get it implemented right it shouldn't get in the was anyhow :).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.