Non power of two textures


Gerix

Active Member
Joined
Jan 25, 2010
Messages
767
Age
36
I am attempting to write a class that prints text to the screen using openGL. I was trying to follow NeHe's tutorial on outline fonts, but it seems he farms out the loading of the font to a wgl function. Since the tutorial didn't go into detail on what the function did, I looked at the SDL_ttf documentation to see if there was an comparable function. I couldn't find anything. I even read that it would be a bad idea to access the data directly, as it might change between versions. So I decided to implement it as textures instead of polygons.


Anyway, after writing the class, I was trying to debug it on my netbook, but something (I think mingw) is configured to send standard out straight to a file, and doesn't even write it if the program crashes. So I moved over to my Linux system and got most of it working (I still need to flesh out the print function so characters maintain the correct width/height). I was at my parents' this weekend, so I was back to working on the netbook. Anyway, the program kept crashing, and I narrowed it down to the line where I load the character as a texture. It took me a bit of searching to find something I should have already known: the character dimensions weren't power of two. When I draw my own textures, I make sure they are PoT, but there's no easy way to specify that every character should be (to my knowledge).


At first, I was looking at writing a shader, since I read somewhere it allows non power of two and it might be a good experience. But then I read shaders were first supported in OGL 2.1, where NPoT was supported in 2.0, so it seems I would be losing compatibility instead of gaining it. Now, I'm thinking I need to pad the texture up to the next power of two. I figured I would look to see if a tutorial covered what I was doing and discussed a workaround. However, the first one I found ignored the issue. So I'm wondering how much of a problem this is. My netbook can't handle my game anyway. I would hate to put effort into writing some clunky solution to find out it wasn't necessarily needed.


Also, if I need to rewrite the code, should I drop SDL_ttf and use something else? For example, I came across a suggestion to use freetype.
 
Last edited by a moderator:
Anyway, after writing the class, I was trying to debug it on my netbook, but something (I think mingw) is configured to send standard out straight to a file
Can't really help with the rest of your problem, but if you add the following snippet to the very start of your main():



Code:
	#ifdef WIN32

	freopen("CON", "w", stdout);

	freopen("CON", "w", stderr);

	#endif

you can make Windows redirect the output back to the console.
 
You load a single character as a texture?


I thought the usual approach was to create a texture atlas of all characters, then you only need the atlas to be POT.
 
^Yeah, after reading up on texture atlases, that seems to be the way to go. Thanks! It also makes me wonder if I should use texture atlases elsewhere.

Can't really help with the rest of your problem, but if you add the following snippet to the very start of your main():



Code:
	#ifdef WIN32

	freopen("CON", "w", stdout);

	freopen("CON", "w", stderr);

	#endif

you can make Windows redirect the output back to the console.
I don't know why, but that's causing conhost.exe to crash. It's weird, because a whole bunch of sources online say that's the way to do it. I appreciate the suggestion, though.
 
Last edited by a moderator:
Thanks, guys. I was able to get it working. (yay!)
 
Back
Top