Skip to main content
gamedev.net
🔒 Locked

Texture Mapping

Started by Leng 3 replies 800+ views
Original Post
Leng
Leng
Dear All, I am using VB and new to OpenGL, I have tried lesson 6.The width image=256 and heigh=256. Could anyone help if I want to use image which is bigger or smaller than the size. For example 210 * 78 or 3520 * 1400. Thanks
Nemesis2k2
Nemesis2k2
Which tutorials are you learning from? There are quite a few out there. Lesson 6 isn't enough info.

Anyway, if you're trying to texture something, the image you're using must have dimensions that are powers of 2.
128 * 128 is fine
64 * 64 works too
32 * 512 will work
32 * 31 will not
Leng
Leng
Anyway to sort out when the image is not power by 2?

Auron
Auron
Do you mean how to tell if the image has a power-of-two size? Then you'd just find log(dimension)/log(2) and then if that's an integer value, it's a power of two. There are likely better ways to do this though.

Do you mean fixing an image if it's not power-of-two? Without a lot of code or an image library, no. It's easier to just open the image in an editor and resize it to a proper size. You can either resize the whole image (which can make it look really ugly depending on the image) or just pad the image with black on one side to be the appropriate width/height. Then you'd just adjust your texture coordinates appropriately. For example, if the image was originally 230 pixels wide and you padded 26 pixels onto the right, you would just change the texture coordinates referring to the right side of the image from 1.0 to (230.0/256.0).

-Auron
vincoof
vincoof
In real-time computer gaphics, all textures should be in power-of-two. If the texture you got was made for computer graphics, it's a bad source of textures. Anyway you can resize the texture thanks to gluScaleImage2D. It's a pretty slow function, yet it's a good start.

Topic Locked

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

Sign in to reply to this topic.