Sign in to follow this  
iNsAn1tY

OpenGL Non-power-of-two textures point blank refusing to work

Recommended Posts

iNsAn1tY    476
I'm at a tear-your-hair-out stage with these goddamn texture rectangles. OpenGL absolutely refuses to use them. I specify a texture size like (512, 513) as a test, and bam, a nice helpful "invalid operation" error. Every time. With any combination of internal format, format and type supplied to glTexImage2D. I'm specifying GL_TEXTURE_RECTANGLE_ARB to glTexImage2D, and I'm running a GeForce 7800 GTX with the latest drivers. The most annoying thing of all is that I've found an NVIDIA demo which uses GL_TEXTURE_RECTANGLE_NV (which I know is an alias for the ARB extension, OpenGL Extension Viewer tells me). And it works. For no good reason. I even tried specifying the same parameters in my application, and it wasn't having any of it. Any idea at all what I'm doing wrong? Here's some code:
glBindTexture( meTarget, muID );

glTexImage2D( meTarget,             // GL_TEXTURE_BINDING_RECTANGLE_ARB
              0,
              lTD.meInternalFormat, // GL_RGBA8 (tried GL_RGB like NVIDIA example)
              lTD.mDimensions.x,    // 512
              lTD.mDimensions.y,    // 513
              0,
              lTD.meFormat,         // GL_RGBA (tried GL_RGB like NVIDIA example)
              lTD.meType,           // GL_UNSIGNED_BYTE (tried GL_FLOAT like NVIDIA example)
              0 );




All of this works fine when you specify GL_TEXTURE_2D and change 513 back to 512. I'm beginning to suspect problems with the driver. I also get the invalid operation error when I specify GL_TEXTURE_2D with a texture height of 513, even though my card supports the ARB non-power-of-two extension. It's ridiculous. Thanks in advance for any replies. [Edited by - iNsAn1tY on May 2, 2007 11:15:14 AM]

Share this post


Link to post
Share on other sites
Brother Bob    10344
If one works, and one doesn't, but the parameters are the same, then something else is wrong. How about the rendering context? It is activated at the time you upload the texture?

edit: Never mind. You said it worked for power of two regular texture, so can't be it...

Share this post


Link to post
Share on other sites
Richy2k    313
Never assume non power of two textures will work. Out of habit you should avoid using them, it is more optimal, and more supported to stick with power of two textures.

Share this post


Link to post
Share on other sites
gardin    122
This is mostly guessing, but it might work. I guess youre using windows, use some lib like glew to load all the extensions, so that the non_power_of_two extension is loaded, and try now, however, this shouldnt make any difference, because youre not using any new methods, but since windows is using a really old version of opengl (shouldnt make any difference either, since your driver is new) it might be causing the problem.

Even though this is a very rare reason, you never know :P

Share this post


Link to post
Share on other sites
Zipster    2365
I would expect this kind of ridiculousness from ATI's OpenGL drivers, but nVidia's? What is the world coming to? [headshake]

What I would do is grab a program like gDEBugger (free 30-day trial), GLExpert, GLIntercept, NVPerfKit, etc., and see if you can't get some more information on why the call is failing. There's absolutely nothing wrong with the code you posted, but it's possible that OpenGL might be in some crazy state. I feel your pain though, I just got down with a major OpenGL project and I don't have any hair left to pull!

Share this post


Link to post
Share on other sites
Yann L    1802
That's bizarre, I've never encountered any problems with NPT textures on nvidia hardware.

I find it interesting that it works with the NV demo, but not with your own code. There must be a difference somewhere, probably in the current OpenGL state, as others have mentioned.

Have you tried isolating the NPT texture creation call, maybe by placing it directly after the context creation ? If that works (and it should), then try moving it around, until it doesn't work anymore. Eventhough there shouldn't be any, there definitely are a few GL calls that can put OpenGL in an undefined state. Especially when working with GLSL.

And while this may sound silly, make 100% sure that the error state is clean before calling glTexImage, maybe by just calling glGetError prior to teximage. I've once tried to hunt down a 'driver bug', and finally realized (by using gDebugger) that the API call I thought would trigger the error wasn't actually the one...

Quote:

This is mostly guessing, but it might work. I guess youre using windows, use some lib like glew to load all the extensions, so that the non_power_of_two extension is loaded, and try now, however, this shouldnt make any difference, because youre not using any new methods, but since windows is using a really old version of opengl (shouldnt make any difference either, since your driver is new) it might be causing the problem.

The NPT extensions don't have to be 'loaded', they don't expose new entry points. They're just a bunch of enumerants. The ARB_texture_non_power_of_two extension doesn't define anything at all, it's just a capability flag.

Share this post


Link to post
Share on other sites
gardin    122
Quote:
Original post by Yann L
Quote:

This is mostly guessing, but it might work. I guess youre using windows, use some lib like glew to load all the extensions, so that the non_power_of_two extension is loaded, and try now, however, this shouldnt make any difference, because youre not using any new methods, but since windows is using a really old version of opengl (shouldnt make any difference either, since your driver is new) it might be causing the problem.

The NPT extensions don't have to be 'loaded', they don't expose new entry points. They're just a bunch of enumerants. The ARB_texture_non_power_of_two extension doesn't define anything at all, it's just a capability flag.


Yeah, youre right, thats why i said i was only guessing :)

Share this post


Link to post
Share on other sites
PlayerX    279
Long shot, but what is the type of meTarget? GL_TEXTURE_RECTANGLE_ARB (which you should be using, not GL_TEXTURE_BINDING_RECTANGLE_ARB) has a value of 0x84F5 and GL_TEXTURE_2D has a value of 0xDE1. If you're using shorts then you won't be able to store the GL_TEXTURE_RECTANGLE_ARB value correctly. meTarget should ideally be GLuint.

Perhaps try replacing the glTexImage2D parameters with the actual values you want instead of the variables in case that is where the problem is coming from.

Share this post


Link to post
Share on other sites
iNsAn1tY    476
Hi guys, thanks for the replies. I've had no time to look into this matter further since I posted; I'm now doing final year exams, which means lots and lots of revision and learning and virtually nothing else.

The problem in this post is from my final year project, which has been handed in now (with plenty of hacks in place to sort out this and several other small/medium/potentially life-threatening bugs which were in it). We're open-sourcing my FYP soon though, and it's being developed further for a conference that's coming up, to add features I didn't have time to implement during the project itself (this is all once my finals are out of the way around May 19th and I've recovered from the week or so of alcohol-fuelled celebration I've promised myself and others [grin]).

I'll open a new thread to announce the project and give more details soon. Hopefully, it'll be something that will interest you all... [smile]

Share this post


Link to post
Share on other sites
zedz    291
this is incorrect
glTexImage2D( meTarget, // GL_TEXTURE_BINDING_RECTANGLE_ARB

calling glGetError( ) will report this

alternatively use glIntercept which will tell you this as well

also from my testing power of 2 textures are ~10% quicker than nonpower of 2

NPOT + texture_rectangle_arb are about the same speed

Share this post


Link to post
Share on other sites
iNsAn1tY    476
Quote:
Original post by zedz
this is incorrect
glTexImage2D( meTarget, // GL_TEXTURE_BINDING_RECTANGLE_ARB

calling glGetError( ) will report this

alternatively use glIntercept which will tell you this as well

Tried GL_TEXTURE_BINDING_RECTANGLE_ARB and GL_TEXTURE_RECTANGLE_ARB, I get invalid operations from glGetError with both.

Quote:
Original post by MARS_999
NPOT have always worked for me on Nvidia hardware that supports it...

Yeah, that's the weird thing. As I mentioned, I have that NVIDIA demo which uses NPOT textures, and it works fine. It must be something I'm doing wrong, but I just can't find it...

[Edited by - iNsAn1tY on May 12, 2007 9:17:35 AM]

Share this post


Link to post
Share on other sites
Trurl    208
I hope I'm not stating the obvious here, but you should check glGetError before the call to glTexImage2D just to be sure that the error you're seeing isn't the result of some earlier problem that went unchecked.

Share this post


Link to post
Share on other sites
kRogue    100
one last silly obvious thing to check: check the GL string at load to make sure you are using nVidia's openGL library: a while back I was pounding my head to why things suddenly stopped working and it happened because I specified a greater depth than the current state and asked for a windowed mode so SDL decided to go through the Window's GDI openGL implementation (and this was revealed by looking at glString(GL_VENDOR) and glString(GL_VERSION)....

Share this post


Link to post
Share on other sites
MARS_999    1627
Try this code?


glGenTextures (1, &tex);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, tex);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8, texSize, texSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);

//0 if not uploading texture data...




Did you set the filtering code with the ARB extension? Are you using GLEE, GLEW, your own loader?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Similar Content

    • By Arulbabu Donbosco
      There are studios selling applications which is just copying any 3Dgraphic content and regenerating into another new window. especially for CAVE Virtual reality experience. so that the user opens REvite or CAD or any other 3D applications and opens a model. then when the user selects the rendered window the VR application copies the 3D model information from the OpenGL window. 
      I got the clue that the VR application replaces the windows opengl32.dll file. how this is possible ... how can we copy the 3d content from the current OpenGL window.
      anyone, please help me .. how to go further... to create an application like VR CAVE. 
       
      Thanks
    • By cebugdev
      hi all,

      i am trying to build an OpenGL 2D GUI system, (yeah yeah, i know i should not be re inventing the wheel, but this is for educational and some other purpose only),
      i have built GUI system before using 2D systems such as that of HTML/JS canvas, but in 2D system, i can directly match a mouse coordinates to the actual graphic coordinates with additional computation for screen size/ratio/scale ofcourse.
      now i want to port it to OpenGL, i know that to render a 2D object in OpenGL we specify coordiantes in Clip space or use the orthographic projection, now heres what i need help about.
      1. what is the right way of rendering the GUI? is it thru drawing in clip space or switching to ortho projection?
      2. from screen coordinates (top left is 0,0 nd bottom right is width height), how can i map the mouse coordinates to OpenGL 2D so that mouse events such as button click works? In consideration ofcourse to the current screen/size dimension.
      3. when let say if the screen size/dimension is different, how to handle this? in my previous javascript 2D engine using canvas, i just have my working coordinates and then just perform the bitblk or copying my working canvas to screen canvas and scale the mouse coordinates from there, in OpenGL how to work on a multiple screen sizes (more like an OpenGL ES question).
      lastly, if you guys know any books, resources, links or tutorials that handle or discuss this, i found one with marekknows opengl game engine website but its not free,
      Just let me know. Did not have any luck finding resource in google for writing our own OpenGL GUI framework.
      IF there are no any available online, just let me know, what things do i need to look into for OpenGL and i will study them one by one to make it work.
      thank you, and looking forward to positive replies.
    • By fllwr0491
      I have a few beginner questions about tesselation that I really have no clue.
      The opengl wiki doesn't seem to talk anything about the details.
       
      What is the relationship between TCS layout out and TES layout in?
      How does the tesselator know how control points are organized?
          e.g. If TES input requests triangles, but TCS can output N vertices.
             What happens in this case?
      In this article,
      http://www.informit.com/articles/article.aspx?p=2120983
      the isoline example TCS out=4, but TES in=isoline.
      And gl_TessCoord is only a single one.
      So which ones are the control points?
      How are tesselator building primitives?
    • By Orella
      I've been developing a 2D Engine using SFML + ImGui.
      Here you can see an image
      The editor is rendered using ImGui and the scene window is a sf::RenderTexture where I draw the GameObjects and then is converted to ImGui::Image to render it in the editor.
      Now I need to create a 3D Engine during this year in my Bachelor Degree but using SDL2 + ImGui and I want to recreate what I did with the 2D Engine. 
      I've managed to render the editor like I did in the 2D Engine using this example that comes with ImGui. 
      3D Editor preview
      But I don't know how to create an equivalent of sf::RenderTexture in SDL2, so I can draw the 3D scene there and convert it to ImGui::Image to show it in the editor.
      If you can provide code will be better. And if you want me to provide any specific code tell me.
      Thanks!
    • By Picpenguin
      Hi
      I'm new to learning OpenGL and still learning C. I'm using SDL2, glew, OpenGL 3.3, linmath and stb_image.
      I started following through learnopengl.com and got through it until I had to load models. The problem is, it uses Assimp for loading models. Assimp is C++ and uses things I don't want in my program (boost for example) and C support doesn't seem that good.
      Things like glVertexAttribPointer and shaders are still confusing to me, but I have to start somewhere right?
      I can't seem to find any good loading/rendering tutorials or source code that is simple to use and easy to understand.
      I have tried this for over a week by myself, searching for solutions but so far no luck. With tinyobjloader-c and project that uses it, FantasyGolfSimulator, I was able to actually load the model with plain color (always the same color no matter what I do) on screen and move it around, but cannot figure out how to use textures or use its multiple textures with it.
      I don't ask much: I just want to load models with textures in them, maybe have lights affect them (directional spotlight etc). Also, some models have multiple parts and multiple textures in them, how can I handle those?
      Are there solutions anywhere?
      Thank you for your time. Sorry if this is a bit confusing, English isn't my native language
  • Popular Now