Sign in to follow this  
cyotek

OpenGL White textures on Windows XP VM using OpenTK / C#

Recommended Posts

Hello,

While testing a build of my game on an XP machine some weeks back, I found that some of the textures, even those not using alpha blending, were being rendered as white rectangles on the VM. On the physical Windows 7 machine, they displayed perfectly.

From doing various google searches, I am led to believe that white textures are pretty much an error state and therefore I'm doing something wrong. (Which I then further clarified with glGetError)

The game used to work on the XP VM so I'm at a loss what I did to cause it - after I originally got textures working way back when I haven't really touched the code as it hasn't been nessecary and as I'm still pretty much a beginner at OpenGL I don't want to break things by mistake.

Part of the problem is that I'm not even sure if I really have broken the game, or if it's the VM itself - while testing I noted that if I changed the color depth of the VM from 32bit to lower, then the game window always displayed a solid red color, nothing else. Of course, that could still be a fault with my code ;)

Here's examples of what the game looks like running on Windows 7:

[attachment=11290:good1.png][attachment=11291:good2.png]

And this is what happens on the XP VM:

[attachment=11288:bad1.png][attachment=11289:bad2.png]

What is truly frustrating about this whole issue is it only affects some graphics, and it's always the same ones.

I added a call to glGetError after calling glTexImage2D and this is returning InvalidValue. But that doesn't make sense to me - why it would it return fine on one machine and not another, and why wouldn't it affect all graphics instead of just some? This is the output of a debug log I added:

[CODE]15/09/2012 20:04:45: Debug: Assigning texture 1 (splash) [Hint: Linear, Flags: None]
15/09/2012 20:04:45: Debug: InvalidValue
15/09/2012 20:04:45: Debug: Activated Scene:
15/09/2012 20:04:45: Debug: Assigning texture 2 (gamebackground) [Hint: Nearest, Flags: None]
15/09/2012 20:04:45: Debug: InvalidValue
15/09/2012 20:04:45: Debug: Assigning texture 3 (bonusbackground) [Hint: Nearest, Flags: None]
15/09/2012 20:04:45: Debug: InvalidValue
15/09/2012 20:04:45: Debug: Assigning texture 4 (exitbackground) [Hint: Nearest, Flags: None]
15/09/2012 20:04:45: Debug: InvalidValue
15/09/2012 20:04:45: Debug: Assigning texture 5 (statusbanner) [Hint: Nearest, Flags: None]
15/09/2012 20:04:45: Debug: InvalidValue
15/09/2012 20:04:45: Debug: Assigning texture 6 (maintitle) [Hint: Linear, Flags: None]
15/09/2012 20:04:45: Debug: InvalidValue
15/09/2012 20:04:45: Debug: Assigning texture 7 (optionstitle) [Hint: Linear, Flags: Alpha]
15/09/2012 20:04:45: Debug: InvalidValue
15/09/2012 20:04:45: Debug: Assigning texture 8 (howtotitle) [Hint: Linear, Flags: Alpha]
15/09/2012 20:04:45: Debug: InvalidValue
15/09/2012 20:04:45: Debug: Assigning texture 9 (creditstitle) [Hint: Linear, Flags: Alpha]
15/09/2012 20:04:45: Debug: InvalidValue
15/09/2012 20:04:45: Debug: Assigning texture 10 (pausedtitle) [Hint: Linear, Flags: Alpha]
15/09/2012 20:04:45: Debug: InvalidValue
15/09/2012 20:04:45: Debug: Assigning texture 11 (debug) [Hint: Linear, Flags: Alpha]
15/09/2012 20:04:45: Debug: NoError
15/09/2012 20:04:45: Debug: Assigning texture 12 (rock-72_0) [Hint: Nearest, Flags: Alpha]
15/09/2012 20:04:45: Debug: NoError
15/09/2012 20:04:45: Debug: Assigning texture 13 (rock-32s_0) [Hint: Nearest, Flags: Alpha]
15/09/2012 20:04:45: Debug: NoError
15/09/2012 20:04:45: Debug: Assigning texture 14 (rock-36s_0) [Hint: Nearest, Flags: Alpha]
15/09/2012 20:04:45: Debug: NoError
15/09/2012 20:04:45: Debug: Assigning texture 15 (uni564-12s_0) [Hint: Nearest, Flags: Alpha]
15/09/2012 20:04:45: Debug: NoError
15/09/2012 20:04:45: Debug: Assigning texture 16 (JewelRush) [Hint: Nearest, Flags: Alpha]
15/09/2012 20:04:45: Debug: NoError[/CODE]

Clearly it's not liking a lot of graphics independent of settings.

The code is scatted about in different classes, hopefully I've gathered up all the relevant bits here. As mentioned I'm still a noob when it comes to OpenGL, so I'm currently doing all texture rendering via glDrawArrays.

Initializing texture support:
[source lang="csharp"]GL.Disable(EnableCap.CullFace);
GL.Enable(EnableCap.Texture2D);
GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
[/source]

Binding a System.Drawing.Bitmap to OpenGL:

[source lang="c#"] public override void Rebind()
{
BitmapData data;
Bitmap bitmap;
int magnificationFilter;
int minificationFilter;

bitmap = (Bitmap)this.Image;

if (this.TextureId == 0)
{
GL.GenTextures(1, out _textureId);
Log.WriteLog(LogLevel.Debug, "Assigning texture {0} ({1}) [Hint: {2}, Flags: {3}]", this.TextureId, this.Name, this.Hint, this.Flags);
}

OpenGL.BindTexture(this.TextureId);

data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

switch (this.Hint)
{
case TextureHintMode.Nearest:
magnificationFilter = (int)TextureMagFilter.Nearest;
minificationFilter = (int)TextureMinFilter.Nearest;
break;
default:
magnificationFilter = (int)TextureMagFilter.Linear;
minificationFilter = (int)TextureMinFilter.Linear;
break;
}

GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, minificationFilter);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, magnificationFilter);
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, data.Width, data.Height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0);

Log.WriteLog(LogLevel.Debug, GL.GetError().ToString());

bitmap.UnlockBits(data);
}[/source]
Although not shown in the above code, I experimented by creating a new bitmap object with an explicit RGBA pixel type and then drew the original image onto this prior to calling LockBits etc, this had no effect.

Part of my SpriteBatch class that handles drawing with as few calls to glBindTexture as possible:
[source lang="csharp"]public override void Draw()
{
if (this.Size != 0)
{
if (_requiresBlend)
GL.Enable(EnableCap.Blend);

OpenGL.BindTexture(_textureId);
this.SetupPointers();
GL.DrawArrays(BeginMode.Triangles, 0, this.Size);
this.Size = 0;

if (!_requiresBlend)
{
GL.Disable(EnableCap.Blend);
_requiresBlend = false;
}
}
}

private void SetupPointers()
{
GL.EnableClientState(ArrayCap.ColorArray);
GL.EnableClientState(ArrayCap.VertexArray);
GL.EnableClientState(ArrayCap.TextureCoordArray);

GL.VertexPointer(VertexDimensions, VertexPointerType.Double, 0, _vertexPositions);
GL.ColorPointer<BrColor>(ColorDimensions, ColorPointerType.Float, 0, _vertexColors);
GL.TexCoordPointer<Point>(UVDimensions, TexCoordPointerType.Float, 0, _vertexUVs);
}[/source]

Apologies for the somewhat rambling post, if anyone has any suggestions as to where I'm going wrong I'd be grateful.

Thanks;
Richard Moss

Share this post


Link to post
Share on other sites
Is GL_TEXTURE_2D enabled when you try to use it?
Some implementations might be super strict and I ___think___ you're supposed to have it enabled before you can use it with such, or any, operations
Other than that, I would personally look into all the glEnable bits that could potentially cause this error.. It doesn't look like you are doing something that is inherently illegal,
so that would be my first quest [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
I don't see anything wrong with the small code you've posted, and from all the errors it seems the error is indeed in the glTexImage2D

edit: it could also be that you aren't specifying the S,T of the texture coordinates, but.. i don't think you have to :) a wild shot!
such as setting them to CLAMP_TO_BORDER Edited by Kaptein

Share this post


Link to post
Share on other sites
Kaptein and mhagain,

Thanks for the responses. I am enabling 2D textures prior to bind anything, that's not the issue. However, mhagain has hit the nail on the head it seems. Originally I tried to keep all textures power of two, until I read somewhere it wasn't actually required - so I got lazy for textures I used as single images, rather than being part of a tilesheet. And this seems to be exactly what the problem is - I did a quick test on changing one of the text graphics to be power of two, and it's loaded fine in the VM. So I just need to update my tilesheet code (which splits up textures into grids with equally sized cells) in order to support different sized sub images, then I think I'm sorted.

Thanks very much, I've been trying to fix this for a while and the fact I'd lazily switched image sizes never occured to me!

Regards;
Richard Moss

Share this post


Link to post
Share on other sites
Any GL2.0 or better hardware [i]should[/i] have generalized support for non-power-of-two textures, but some older hardware may not be robust (e.g. the driver may advertise support for them but drop you back to software emulation if you actually try to use them - thanks a lot, ARB). GL3.0 or better hardware should be fully generalized and robust, on GL1.x hardware - don't even bother.

If all that you're drawing is 2D sprites you can check for and use the [url="http://www.opengl.org/registry/specs/ARB/texture_rectangle.txt"]GL_ARB_texture_rectangle[/url] extension. There are a number of restrictions (no mipmaps, clamp modes only, no borders, must use integer texcoords) but it should be more widely available.

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  

  • Announcements

  • Forum Statistics

    • Total Topics
      628391
    • Total Posts
      2982419
  • Similar Content

    • By test opty
      Hi all,
       
      I'm starting OpenGL using a tut on the Web. But at this point I would like to know the primitives needed for creating a window using OpenGL. So on Windows and using MS VS 2017, what is the simplest code required to render a window with the title of "First Rectangle", please?
       
       
    • By DejayHextrix
      Hi, New here. 
      I need some help. My fiance and I like to play this mobile game online that goes by real time. Her and I are always working but when we have free time we like to play this game. We don't always got time throughout the day to Queue Buildings, troops, Upgrades....etc.... 
      I was told to look into DLL Injection and OpenGL/DirectX Hooking. Is this true? Is this what I need to learn? 
      How do I read the Android files, or modify the files, or get the in-game tags/variables for the game I want? 
      Any assistance on this would be most appreciated. I been everywhere and seems no one knows or is to lazy to help me out. It would be nice to have assistance for once. I don't know what I need to learn. 
      So links of topics I need to learn within the comment section would be SOOOOO.....Helpful. Anything to just get me started. 
      Thanks, 
      Dejay Hextrix 
    • By mellinoe
      Hi all,
      First time poster here, although I've been reading posts here for quite a while. This place has been invaluable for learning graphics programming -- thanks for a great resource!
      Right now, I'm working on a graphics abstraction layer for .NET which supports D3D11, Vulkan, and OpenGL at the moment. I have implemented most of my planned features already, and things are working well. Some remaining features that I am planning are Compute Shaders, and some flavor of read-write shader resources. At the moment, my shaders can just get simple read-only access to a uniform (or constant) buffer, a texture, or a sampler. Unfortunately, I'm having a tough time grasping the distinctions between all of the different kinds of read-write resources that are available. In D3D alone, there seem to be 5 or 6 different kinds of resources with similar but different characteristics. On top of that, I get the impression that some of them are more or less "obsoleted" by the newer kinds, and don't have much of a place in modern code. There seem to be a few pivots:
      The data source/destination (buffer or texture) Read-write or read-only Structured or unstructured (?) Ordered vs unordered (?) These are just my observations based on a lot of MSDN and OpenGL doc reading. For my library, I'm not interested in exposing every possibility to the user -- just trying to find a good "middle-ground" that can be represented cleanly across API's which is good enough for common scenarios.
      Can anyone give a sort of "overview" of the different options, and perhaps compare/contrast the concepts between Direct3D, OpenGL, and Vulkan? I'd also be very interested in hearing how other folks have abstracted these concepts in their libraries.
    • By aejt
      I recently started getting into graphics programming (2nd try, first try was many years ago) and I'm working on a 3d rendering engine which I hope to be able to make a 3D game with sooner or later. I have plenty of C++ experience, but not a lot when it comes to graphics, and while it's definitely going much better this time, I'm having trouble figuring out how assets are usually handled by engines.
      I'm not having trouble with handling the GPU resources, but more so with how the resources should be defined and used in the system (materials, models, etc).
      This is my plan now, I've implemented most of it except for the XML parts and factories and those are the ones I'm not sure of at all:
      I have these classes:
      For GPU resources:
      Geometry: holds and manages everything needed to render a geometry: VAO, VBO, EBO. Texture: holds and manages a texture which is loaded into the GPU. Shader: holds and manages a shader which is loaded into the GPU. For assets relying on GPU resources:
      Material: holds a shader resource, multiple texture resources, as well as uniform settings. Mesh: holds a geometry and a material. Model: holds multiple meshes, possibly in a tree structure to more easily support skinning later on? For handling GPU resources:
      ResourceCache<T>: T can be any resource loaded into the GPU. It owns these resources and only hands out handles to them on request (currently string identifiers are used when requesting handles, but all resources are stored in a vector and each handle only contains resource's index in that vector) Resource<T>: The handles given out from ResourceCache. The handles are reference counted and to get the underlying resource you simply deference like with pointers (*handle).  
      And my plan is to define everything into these XML documents to abstract away files:
      Resources.xml for ref-counted GPU resources (geometry, shaders, textures) Resources are assigned names/ids and resource files, and possibly some attributes (what vertex attributes does this geometry have? what vertex attributes does this shader expect? what uniforms does this shader use? and so on) Are reference counted using ResourceCache<T> Assets.xml for assets using the GPU resources (materials, meshes, models) Assets are not reference counted, but they hold handles to ref-counted resources. References the resources defined in Resources.xml by names/ids. The XMLs are loaded into some structure in memory which is then used for loading the resources/assets using factory classes:
      Factory classes for resources:
      For example, a texture factory could contain the texture definitions from the XML containing data about textures in the game, as well as a cache containing all loaded textures. This means it has mappings from each name/id to a file and when asked to load a texture with a name/id, it can look up its path and use a "BinaryLoader" to either load the file and create the resource directly, or asynchronously load the file's data into a queue which then can be read from later to create the resources synchronously in the GL context. These factories only return handles.
      Factory classes for assets:
      Much like for resources, these classes contain the definitions for the assets they can load. For example, with the definition the MaterialFactory will know which shader, textures and possibly uniform a certain material has, and with the help of TextureFactory and ShaderFactory, it can retrieve handles to the resources it needs (Shader + Textures), setup itself from XML data (uniform values), and return a created instance of requested material. These factories return actual instances, not handles (but the instances contain handles).
       
       
      Is this a good or commonly used approach? Is this going to bite me in the ass later on? Are there other more preferable approaches? Is this outside of the scope of a 3d renderer and should be on the engine side? I'd love to receive and kind of advice or suggestions!
      Thanks!
    • By nedondev
      I 'm learning how to create game by using opengl with c/c++ coding, so here is my fist game. In video description also have game contain in Dropbox. May be I will make it better in future.
      Thanks.
  • Popular Now