openGL and ofTexture Sizing

Hi,

First my following questions are based on my not being familiar with openGL.

Reading the oF doc, there is the following description of ofTexture:

oftexture is a wrapper for opengl’s texture support. Specifically, it allows to use non power of 2 textures in opengl, and to upload and draw graphical data.

The associated description of allocate() says “The width (w) and height (h) do not necessarily need to be powers of 2”

First I assume the word texture is used here as just another way of saying the area of your image - is this correct?

Second, the description implies that to size a picture in openGL, the width and height of that image literally must be numbers that are a power of two - making 1024 ok but not allowing 1000 - and that ofTexture eliminates this restriction. Am I interpreting this correctly?

Lastly I assume that the openGL restriction was put in place for performance reasons, correct?

Thanks.

Jim

Hi, to answer your questions:

First I assume the word texture is used here as just another way of saying the area of your image - is this correct?

Not just area of image, but the whole image. The word texture is used to point out that this is an opengl texture, i.e. it lives in your graphics card memory and is handled by GPU (as opposed to images which live in main memory, and handled by CPU). An ofImage has an ofTexture. So when you load an image off your harddisk with ofImage, the CPU loads it into RAM, then creates an ofTexture with it which sends it to the VRAM, and then the GPU can render it.

Second, the description implies that to size a picture in openGL, the width and height of that image literally must be numbers that are a power of two - making 1024 ok but not allowing 1000 - and that ofTexture eliminates this restriction. Am I interpreting this correctly?

Initially opengl only allowed Powers Of Two Sized (POTS) textures (referred to as GL_TEXTURE_2D), then in 2004 an extension to opengl got approved to allow Non Power Of Two sized (NPOTS) textures (GL_TEXTURE_RECTANGLE_ARB). ofTexture supports both of these texture types, and defaults to GL_TEXTURE_RECTANGLE_ARB.

Lastly I assume that the openGL restriction was put in place for performance reasons, correct?

I think it was more of a technical limitation, which theyve now got around. I think on a high desktop system it shouldn’t make much difference, but on embedded systems like iphone it might and they stilli recommend using POTS. If I’m making large textures to be used as a background for my app I use NPOTS and just make it the same resolution as my output (e.g. 1920x1080, non power or two), but then if I have a particle system with a texture I will make that POTS (E.g. 256x256, or 512x512, or 128x128 etc).

Hi Memo,

Thanks for that brilliant answer! Your answer makes me more convinced that maybe my openGL/graphics card combo is the source of the problems I’ve been having - since those problems involve ofImage and ofTexture. ofImage and ofTexture seem to work haphazardly - some things work but others fail.

My laptop uses the GeForce Go 6800 graphics card (introduced in 2004 and having 256Mb memory) and version 2 of OpenGL. Given that a couple of my programs ran fine on a netbook I bought last year made me wonder if openGL wasn’t the source of my problem - hence a post yesterday in the beginners section about what version of openGL was needed to be successful with oF. But your comment about the use of GPU memory makes me wonder if that is in part responsible for my problems.

I will say that I ran glview using the openGL testing option and all tests performed fine - though it only tested through version 2 of openGL. I’ll have to google and see what other openGL/video testing software is out there.

Again, many thanks for your answer.

Jim