# UWP Rendering problem

**URL:** <https://discourse.libsdl.org/t/uwp-rendering-problem/22802>\
**Category:** SDL Development\
**Created:** [July 14, 2017, 1:07pm UTC](https://discourse.libsdl.org/t/uwp-rendering-problem/22802 "2017-07-14T13:07:11Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![maartenengels](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/m/f0a364/32.png) [@maartenengels](https://discourse.libsdl.org/u/maartenengels)\
**Post date:** [July 14, 2017, 1:07pm UTC](https://discourse.libsdl.org/t/uwp-rendering-problem/22802/1 "2017-07-14T13:07:11Z")

</div>

Hello everyone,

I am trying to figure out a problem that I am having with porting my app to UWP.

The application is working fine expect with the rendering part. While on my development system it looks fine, once I install it on an other system it looks rubbish. I found out that if I set the flag to sdl\_renderer\_software when I create the renderer then I can reproduce the rubbish rendering on my development system as well. I have tried every combination and it doesn’t work.

Using the default renderer driver - direct3d11 with SDL\_RENDERER\_SOFTWARE SDL\_RENDERER\_ACCELERATED SDL\_RENDERER\_PRESENTVSYNC SDL\_RENDERER\_TARGETTEXTURE

Using the render driver opengles2 with SDL\_RENDERER\_SOFTWARE SDL\_RENDERER\_ACCELERATED SDL\_RENDERER\_PRESENTVSYNC SDL\_RENDERER\_TARGETTEXTURE. That doest even let me create a renderer it fails with invalid window. I’ve set the window flag when I create it to SDL\_WINDOW\_OPENGL but that didn’t change anything.

Last, using renderer driver software wit SDL\_RENDERER\_SOFTWARE SDL\_RENDERER\_ACCELERATED SDL\_RENDERER\_PRESENTVSYNC SDL\_RENDERER\_TARGETTEXTURE. Again nothing changed rubbish rendering.

What can I do? what am I missing?

 ![](https://discourse.libsdl.org/uploads/default/original/2X/a/afecdb40ac2f1a2874e53ffb6ca0c0fafdcb880b.jpg)

\*Here is a screenshot for a reference to what I mean with rubbish.

Thank you

---

<div class="post-metadata">

**Author:** ![ChliHug](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/chlihug/32/2863_2.png) [@ChliHug](https://discourse.libsdl.org/u/ChliHug)\
**Post date:** [July 14, 2017, 11:24pm UTC](https://discourse.libsdl.org/t/uwp-rendering-problem/22802/2 "2017-07-14T23:24:03Z")

</div>

We need to test how the software renderer decides to put this mess into the buffer.

Is it possible for you to write a small program that draws the UI elements of your application in a similar way so that the same issues are visible? This would make it much easier for us to diagnose the issue.

If not, describing what libraries, renderer settings (blend modes, scaling quality, …), and asset formats the application uses may give us at least a hint in what direction we could begin looking.

There was talk of pixel formats in the other thread, specifically `SDL_PIXELFORMAT_ABGR8888`. You may want to target `SDL_PIXELFORMAT_ARGB8888` instead if possible. It’s better supported by the renderers.

Also make sure you got the pixel format you requested. Use `SDL_QueryTexture` like suggested.

```auto
surface = SDL_CreateRGBSurfaceWithFormat(0, 512, 512, 32, SDL_PIXELFORMAT_RGBA8888);

texture1 = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STATIC, 512, 512);
texture2 = SDL_CreateTextureFromSurface(renderer, surface);

if (texture1) {
	Uint32 format;
	int access, w, h;
	SDL_QueryTexture(texture1, &format, &access, &w, &h);
	if (format != SDL_PIXELFORMAT_ARGB8888) {
		SDL_Log("Format of texture 1 is not ARGB888 but %s.", SDL_GetPixelFormatName(format));
	} else {
		SDL_Log("Format of texture 1 is ARGB888 as expected.");
	}
}

if (texture2) {
	Uint32 format;
	int access, w, h;
	SDL_QueryTexture(texture2, &format, &access, &w, &h);
	if (format != SDL_PIXELFORMAT_RGBA8888) {
		SDL_Log("Format of texture 2 is not RGBA8888 but %s.", SDL_GetPixelFormatName(format));
	} else {
		SDL_Log("Format of texture 2 is RGBA8888 as expected.");
	}
}

```

---

<div class="post-metadata">

**Author:** ![rtrussell](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/rtrussell/32/4768_2.png) [@rtrussell](https://discourse.libsdl.org/u/rtrussell)\
**Post date:** [July 15, 2017, 9:22am UTC](https://discourse.libsdl.org/t/uwp-rendering-problem/22802/3 "2017-07-15T09:22:45Z")

</div>

> [@ChliHug](#):
>
> There was talk of pixel formats in the other thread, specifically SDL\_PIXELFORMAT\_ABGR8888. You may want to target SDL\_PIXELFORMAT\_ARGB8888 instead if possible. It’s better supported by the renderers.

Sorry to intrude on this thread, but I’m interested in this comment. Are you referring specifically to UWP apps here, or to SDL2 more generally? Whilst I’m aware that ARGB8888 is the usual ‘native’ pixel format in Windows and Linux, ABGR8888 is standard on Android. So because performance is generally more critical on Android, I’ve tended to choose the latter format for my apps, on the basis that it should give a better balance of speed between the various platforms. Am I wrong?

---

<div class="post-metadata">

**Author:** ![ChliHug](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/chlihug/32/2863_2.png) [@ChliHug](https://discourse.libsdl.org/u/ChliHug)\
**Post date:** [July 15, 2017, 1:01pm UTC](https://discourse.libsdl.org/t/uwp-rendering-problem/22802/4 "2017-07-15T13:01:04Z")

</div>

> [@rtrussell](#):
>
> Are you referring specifically to UWP apps here, or to SDL2 more generally?

This was a comment on what the SDL2 renderers accept without doing surface conversions. The exception would be the opengles renderer which only does `ABGR8888`. The opengles2 renderer, which I assume is used on all android devices, is currently always uploading with `GL_RGBA` and `GL_UNSIGNED_BYTE` and then swizzles in the shader, if necessary.

If OpenGL is used directly, one would choose the optimal path for that platform of course. You’re not wrong if that works for you. 😉

---

<div class="post-metadata">

**Author:** ![rtrussell](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/rtrussell/32/4768_2.png) [@rtrussell](https://discourse.libsdl.org/u/rtrussell)\
**Post date:** [July 15, 2017, 8:35pm UTC](https://discourse.libsdl.org/t/uwp-rendering-problem/22802/5 "2017-07-15T20:35:20Z")

</div>

> [@ChliHug](#):
>
> The opengles2 renderer, which I assume is used on all android devices…

I cannot use OpenGLES2, because it does not support ‘logical’ plotting (AND, OR, XOR) which my app relies on. So I use OpenGL on Windows/Linux/MacOs and OpenGLES on Android. Fortunately OpenGLES remains fully supported by SDL2 and by Android.

---

<div class="post-metadata">

**Author:** ![David\_Ludwig](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/david_ludwig/32/4016_2.png) [@David\_Ludwig](https://discourse.libsdl.org/u/David_Ludwig)\
**Post date:** [July 15, 2017, 9:07pm UTC](https://discourse.libsdl.org/t/uwp-rendering-problem/22802/6 "2017-07-15T21:07:28Z")

</div>

One tip: if you ever do get things working in OpenGLES 2, there is an open-source library, ANGLE, which does work with SDL2 on UWP (or at least, did at one point!), and which can emulate GLES2, at least, on top of Direct3D 11+.

---

<div class="post-metadata">

**Author:** ![maartenengels](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/m/f0a364/32.png) [@maartenengels](https://discourse.libsdl.org/u/maartenengels)\
**Post date:** [July 17, 2017, 7:55am UTC](https://discourse.libsdl.org/t/uwp-rendering-problem/22802/7 "2017-07-17T07:55:37Z")

</div>

Hello @ChliHug,

Unfortunately I cannot post the code, being production code and all. But I can post parts:

**For example this is how I create my window and renderer:**

```
void CreateWindowAndRender(int w, int h, int flag)
{
    int x{SDL_WINDOWPOS_UNDEFINED};
    int y{SDL_WINDOWPOS_UNDEFINED};

    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);

    window = SDL_CreateWindow(NULL, x, y, w, h, flag);
    SDL_SetWindowTitle("Title");
    renderer = SDL_CreateRenderer(i_window, -1, SDL_RENDERER_ACCELERATED);
    if(renderer == nullptr)
    {
        renderer = SDL_CreateRenderer(i_window, -1, SDL_RENDERER_SOFTWARE);
    }
    SDL_SetWindowMinimumSize(i_window, 320, 480);
}

```

**Here is how I handle the texture:**

```
void Txtr::Resize(int _w, int _h) {
    bool create_texture(texture==nullptr);
    int w{0};
    int h{0};

    if( texture != nullptr ) {
        SDL_QueryTexture(texture, NULL, NULL, &w, &h);
        if( w != _w || h != _h ) {
            create_texture = true;
        }
    }
    if( create_texture ) {
        if( texture != nullptr ) {
            SDL_DestroyTexture(texture);
    }
    if( _w>0 && _h>0 ) {
        auto width=_w;
#if defined( __WINRT__ )
        width=a_width*2;
#endif      
    texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ABGR8888, SDL_TEXTUREACCESS_STREAMING, width, _h);
    SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
    }
}

```

}

Notes: Please don’t focus to much on the other stuff, I am copying and pasting pieces to show you what I am doing, there are checks and stuff missing this is the minimal version of whats happening.

---

<div class="post-metadata">

**Author:** ![maartenengels](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/m/f0a364/32.png) [@maartenengels](https://discourse.libsdl.org/u/maartenengels)\
**Post date:** [July 19, 2017, 7:20am UTC](https://discourse.libsdl.org/t/uwp-rendering-problem/22802/8 "2017-07-19T07:20:49Z")

</div>

Hello @ChliHug,

I have some more info if this is of any help. Apparently the rendering issues only happen if the graphics card is Nvidia.  
It works fine for Intel, or AMD graphic cards. Is this a known issue?

Greetings.

---

<div class="post-metadata">

**Author:** ![ChliHug](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/chlihug/32/2863_2.png) [@ChliHug](https://discourse.libsdl.org/u/ChliHug)\
**Post date:** [July 19, 2017, 8:32pm UTC](https://discourse.libsdl.org/t/uwp-rendering-problem/22802/9 "2017-07-19T20:32:23Z")

</div>

> [@maartenengels](#):
>
> Is this a known issue?

It’s new to me. I’ll try to do some tests later this week, but I’m not sure if I can find anything.

Oh, can you also tell us how you update the texture data?

---

<div class="post-metadata">

**Author:** ![maartenengels](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/m/f0a364/32.png) [@maartenengels](https://discourse.libsdl.org/u/maartenengels)\
**Post date:** [July 20, 2017, 7:20am UTC](https://discourse.libsdl.org/t/uwp-rendering-problem/22802/10 "2017-07-20T07:20:29Z")

</div>

Hello ChilHug,

Thank you for the quick reply. I have class that represents a Pixel with RGBA value, I iterate through the date and set value. is that helpful?

On another note, the “Pixel” is short of designed with ABGR as pixel format target which we have been using so far with no problem. But now I see that ABGR on Nvidia graphics its not one of the supported pixel formats and when I try to set it to this one it becomes SDL\_PIXELFORMAT\_UKNOWN. But never the less shouldn’t software renderer work instead? that one does support the ABGR.

Greetings.

---

<div class="post-metadata">

**Author:** ![ChliHug](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/chlihug/32/2863_2.png) [@ChliHug](https://discourse.libsdl.org/u/ChliHug)\
**Post date:** [July 22, 2017, 12:25am UTC](https://discourse.libsdl.org/t/uwp-rendering-problem/22802/11 "2017-07-22T00:25:47Z")

</div>

I was more curious how you use `SDL_UpdateTexture`.

Managed to do some testing (Windows 7, NVIDIA card, renderers: direct3d, direct3d11, opengl, opengles2, and software), but didn’t find any issues with the pixel formats.

Where and how did you get a `SDL_PIXELFORMAT_UNKNOWN`? I don’t think the renderers throw this at you without some critical error. Or maybe some garbage value was passed to `SDL_GetPixelFormatName`?

---

<div class="post-metadata">

**Author:** ![maartenengels](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/m/f0a364/32.png) [@maartenengels](https://discourse.libsdl.org/u/maartenengels)\
**Post date:** [July 24, 2017, 6:48am UTC](https://discourse.libsdl.org/t/uwp-rendering-problem/22802/12 "2017-07-24T06:48:12Z")

</div>

> [@ChliHug](#):
>
> SDL\_UpdateTexture

Hello,

And thanks for your quick reply. I do not use SDL\_UpdateTexture I am destroying the texture and create a new one if the width or hight changes. I changes my Colour class to support the ARGB8888 instead of the ABGR8888 that I was using, but it didn’t change anything same result.

You said windows 7, I have not problem with building for normal windows, all my other projects are ported to windows using the same rendering system because its shared code, and they work fine. The problem first appeared on UWP.

And at this point I don’t know if I am chasing a bug on my side, or its a UWP issue.

Greetings.

---

<div class="post-metadata">

**Author:** ![ChliHug](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/chlihug/32/2863_2.png) [@ChliHug](https://discourse.libsdl.org/u/ChliHug)\
**Post date:** [July 24, 2017, 10:28am UTC](https://discourse.libsdl.org/t/uwp-rendering-problem/22802/13 "2017-07-24T10:28:13Z")

</div>

> [@maartenengels](#):
>
> I do not use SDL\_UpdateTexture

`SDL_LockTexture` then? Can’t be `SDL_CreateTextureFromSurface` according to your sample code.

> [@maartenengels](#):
>
> You said windows 7, I have not problem with building for normal windows

Oh, I somehow thought, since you got it on the development machine, that the issue was outside of UWP. So maybe it’s in the winrt video driver, but that doesn’t seem to be able to create a window surface for the software renderer.

I only have Windows 8.1 with an Intel card lying around. Not sure if I can get my hands on Windows 10 to do further tests at this time.

---

<div class="post-metadata">

**Author:** ![maartenengels](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/m/f0a364/32.png) [@maartenengels](https://discourse.libsdl.org/u/maartenengels)\
**Post date:** [July 24, 2017, 11:42am UTC](https://discourse.libsdl.org/t/uwp-rendering-problem/22802/14 "2017-07-24T11:42:01Z")

</div>

Hello ChilHug,

I am using SDL\_LockTexture, its a streaming texture.

```
SDL_LockTexture(texture, 0, (void **)(&pixels), &pitch);
//pixels is a class that that has the RGBA value, and pitch is just an int.

```

Furthermore here, (thats only happening on UWP) if lets say when I create the texture I give the width of 600 and the hight of 400, when I am locking the texture I am expecting to get back 240.000 pixels right? I only get 120.000 pixels half.

My problems also accuses if I am using software renderer that how I reproduced it the first time. If I use software renderer instead of direct3d11 I get the same results as on Nvidia.

---

<div class="post-metadata">

**Author:** ![ChliHug](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/chlihug/32/2863_2.png) [@ChliHug](https://discourse.libsdl.org/u/ChliHug)\
**Post date:** [July 24, 2017, 1:18pm UTC](https://discourse.libsdl.org/t/uwp-rendering-problem/22802/15 "2017-07-24T13:18:55Z")

</div>

> [@maartenengels](#):
>
> Furthermore here, (thats only happening on UWP) if lets say when I create the texture I give the width of 600 and the hight of 400, when I am locking the texture I am expecting to get back 240.000 pixels right? I only get 120.000 pixels half.

How are you determining that you only get that? If `SDL_LockTexture` succeeds, you get a pointer to some memory of the appropriate size. In your example that should be `400 * pitch` bytes. Are you saying it only updates half when you unlock or you get an access violation halfway through?

---

<div class="post-metadata">

**Author:** ![maartenengels](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/m/f0a364/32.png) [@maartenengels](https://discourse.libsdl.org/u/maartenengels)\
**Post date:** [July 24, 2017, 1:47pm UTC](https://discourse.libsdl.org/t/uwp-rendering-problem/22802/16 "2017-07-24T13:47:51Z")

</div>

Ok.

So after I get my pixels and I start to populate them with colour I do something like that:

```
for(auto j=0; j<height; j++)
{
    auto pixel_row(get_pixel_row(j);
    for(auto i=0; i<width; i++)
    {
        pixel_row[i] = colour;
    }
}

```

So I grab each row and populate it, In the beginning half way through that I was getting an access violation. Now if when I am creating the texture give the width\*2 only for that part, then I get the right amount of pixels.

And again that is the case only for UWP, the shame rendering systems is being used through a couple other apps through multiple os’s and they work absolutely fine. This is the first time I see that.

---

<div class="post-metadata">

**Author:** ![ChliHug](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/chlihug/32/2863_2.png) [@ChliHug](https://discourse.libsdl.org/u/ChliHug)\
**Post date:** [July 24, 2017, 1:55pm UTC](https://discourse.libsdl.org/t/uwp-rendering-problem/22802/17 "2017-07-24T13:55:46Z")

</div>

Oh, wow. If the pixel format of the texture says it has 4 bytes per pixel and it only allocates for 2, then there’s obviously something wrong. Not sure where, though.

---

<div class="post-metadata">

**Author:** ![maartenengels](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/m/f0a364/32.png) [@maartenengels](https://discourse.libsdl.org/u/maartenengels)\
**Post date:** [July 24, 2017, 1:58pm UTC](https://discourse.libsdl.org/t/uwp-rendering-problem/22802/18 "2017-07-24T13:58:11Z")

</div>

I know, thank you.

Can that be a bug in the library?

---

<div class="post-metadata">

**Author:** ![ChliHug](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/chlihug/32/2863_2.png) [@ChliHug](https://discourse.libsdl.org/u/ChliHug)\
**Post date:** [July 24, 2017, 3:39pm UTC](https://discourse.libsdl.org/t/uwp-rendering-problem/22802/19 "2017-07-24T15:39:49Z")

</div>

It’s possible, yes. We need to track down where it exactly fails.

I managed to get Windows 10 running on a machine. Now I have to convince it to compile SDL with the winrt driver for me. This may take a while.

---

<div class="post-metadata">

**Author:** ![maartenengels](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/m/f0a364/32.png) [@maartenengels](https://discourse.libsdl.org/u/maartenengels)\
**Post date:** [July 25, 2017, 6:42am UTC](https://discourse.libsdl.org/t/uwp-rendering-problem/22802/20 "2017-07-25T06:42:13Z")

</div>

Hello again,

and thank you very much for the help so far, its very much appreciated.

Greetings.

[Next page](https://discourse.libsdl.org/t/uwp-rendering-problem/22802.md?page=2)
