The issue in 1.3/OpenGL/texture

Greetings.
I work on small engine common for both Windows/MacOS X/iPhone.
I think I found issue in latest SDL from SVN.
The test application does not render window to green color as expected -
it remains the black.

But if I will comment out SDL_CreateTextureFromSurface - rendering work
as expected.

I compiled it with the latest SDL & SDL_image on VS2008 SP1.
I updated SDL from SVN today.

My system is E5200 + Nvidia 8400GS with the latest stable Nvidia drivers.

May anyone to give me advice?

Test.png is the png file with alpha channel.

Thank you :slight_smile:

#include “SDL.h”
#include “SDL_image.h”
#include <string.h>

int main(int argc, char** argv)
{

if (SDL_Init(SDL_INIT_EVERYTHING))
abort();

SDL_WindowID mWindowID = SDL_CreateWindow(“Test application”,
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
480, 320, SDL_WINDOW_SHOWN | SDL_OPENGL);

if (!mWindowID)
abort();

int opengl_index = -1;
//create OpenGL renderer
int driver_count = SDL_GetNumRenderDrivers();

for (int i=0; i<driver_count && opengl_index == -1; ++i)
{
SDL_RendererInfo info;
SDL_GetRenderDriverInfo(i, &info);
if (strcmp(info.name, “opengl”) == 0)
opengl_index = i;
}

if (opengl_index == -1)
abort();

if (SDL_CreateRenderer(mWindowID, opengl_index, 0))
abort();

//load the texture
SDL_Surface* texture_surface = IMG_Load(“test.png”);
if (!texture_surface)
abort();

//comment it out to let the render happen
SDL_TextureID texture = SDL_CreateTextureFromSurface(0, texture_surface);
if (!texture)
abort();

while (true)
{
SDL_Event _event;
while(SDL_PollEvent(&_event)) {

   switch (_event.type)
   {
   case SDL_QUIT:
     return 0;

   case SDL_MOUSEMOTION:
     break;

   case SDL_MOUSEBUTTONDOWN:
   case SDL_MOUSEBUTTONUP:
     break;

   case SDL_MOUSEWHEEL:
     break;

   case SDL_KEYDOWN:
     break;

   case SDL_KEYUP:
     break;

   case SDL_TEXTINPUT:
     break;
   }



   SDL_Rect rect;
   rect.x = 0; rect.y = 0; rect.w = 480; rect.h = 320;
   SDL_SetRenderDrawBlendMode(0);
   SDL_SetRenderDrawColor(0,0,0,0xff);
   SDL_RenderFill(&rect);

   SDL_SetRenderDrawBlendMode(2);
   SDL_SetRenderDrawColor(0,0xFF,0, 0x55);
   SDL_RenderFill(&rect);

   SDL_RenderPresent();
   SDL_Delay(1);
 }

}

return 0;
}
-------------- next part --------------
A non-text attachment was scrubbed…
Name: test.png
Type: image/png
Size: 8268 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20090113/46d1ba45/attachment.png

Greetings.
I work on small engine common for both Windows/MacOS X/iPhone.
I think I found issue in latest SDL from SVN.
The test application does not render window to green color as expected -
it remains the black.

But if I will comment out SDL_CreateTextureFromSurface - rendering work
as expected.

I can reproduce this with Mac OS X too. Ryan, any ideas? I’m sure it’s
an OpenGL state issue.

See ya!
-Sam Lantinga, Founder and President, Galaxy Gameworks LLC

Greetings.
I work on small engine common for both Windows/MacOS X/iPhone.
I think I found issue in latest SDL from SVN.
The test application does not render window to green color as expected -
it remains the black.

But if I will comment out SDL_CreateTextureFromSurface - rendering work
as expected.

This is fixed in revision 4400, thanks!

See ya,
-Sam Lantinga, Founder and President, Galaxy Gameworks LLC

Sam Lantinga wrote:

Greetings.
I work on small engine common for both Windows/MacOS X/iPhone.
I think I found issue in latest SDL from SVN.
The test application does not render window to green color as expected -
it remains the black.

But if I will comment out SDL_CreateTextureFromSurface - rendering work
as expected.

This is fixed in revision 4400, thanks!

Great :slight_smile:

So I made next step. I add the texture with transparent area and tried
to render it too. But it does not render as expected - the transparent
area is black.

The test.png is attached.

The modified source is here:

#include “SDL.h”
#include “SDL_image.h”
#include <string.h>

int main(int argc, char** argv)
{

if (SDL_Init(SDL_INIT_EVERYTHING))
abort();

SDL_WindowID mWindowID = SDL_CreateWindow(“Test application”,
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
480, 320, SDL_WINDOW_SHOWN | SDL_OPENGL);

if (!mWindowID)
abort();

int opengl_index = -1;
//create OpenGL renderer
int driver_count = SDL_GetNumRenderDrivers();

for (int i=0; i<driver_count && opengl_index == -1; ++i)
{
SDL_RendererInfo info;
SDL_GetRenderDriverInfo(i, &info);
if (strcmp(info.name, “opengl”) == 0)
opengl_index = i;
}

if (opengl_index == -1)
abort();

if (SDL_CreateRenderer(mWindowID, opengl_index, 0))
abort();

//load the texture
SDL_Surface* texture_surface = IMG_Load(“test.png”);
if (!texture_surface)
abort();

//comment it out to let the render happen
SDL_TextureID texture = SDL_CreateTextureFromSurface(0, texture_surface);
if (!texture)
abort();

while (true)
{
SDL_Event _event;
while(SDL_PollEvent(&_event)) {

   switch (_event.type)
   {
   case SDL_QUIT:
     return 0;

   case SDL_MOUSEMOTION:
     break;

   case SDL_MOUSEBUTTONDOWN:
   case SDL_MOUSEBUTTONUP:
     break;

   case SDL_MOUSEWHEEL:
     break;

   case SDL_KEYDOWN:
     break;

   case SDL_KEYUP:
     break;

   case SDL_TEXTINPUT:
     break;
   }



   SDL_Rect rect;
   rect.x = 0; rect.y = 0; rect.w = 480; rect.h = 320;
   SDL_SetRenderDrawBlendMode(0);
   SDL_SetRenderDrawColor(0,0,0,0xff);
   SDL_RenderFill(&rect);

   SDL_SetRenderDrawBlendMode(2);
   SDL_SetRenderDrawColor(0,0xFF,0, 0x55);
   SDL_RenderFill(&rect);

   rect.w = texture_surface->w;
   rect.h = texture_surface->h;

   SDL_SetRenderDrawBlendMode(2);
   SDL_RenderCopy(texture, NULL, &rect);

   SDL_RenderPresent();
   SDL_Delay(1);
 }

}

return 0;
}

Please correct me if I’m wrong.

Thank you!
-------------- next part --------------
A non-text attachment was scrubbed…
Name: test.png
Type: image/png
Size: 1539 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20090114/b4a750d4/attachment.png

Dmytro Bogovych wrote:

Sam Lantinga wrote:

Greetings.
I work on small engine common for both Windows/MacOS X/iPhone.
I think I found issue in latest SDL from SVN.
The test application does not render window to green color as
expected - it remains the black.

But if I will comment out SDL_CreateTextureFromSurface - rendering
work as expected.

This is fixed in revision 4400, thanks!

Great :slight_smile:

So I made next step. I add the texture with transparent area and tried
to render it too. But it does not render as expected - the transparent
area is black.

The test.png is attached.

Found - I need Set_TextureBlendMode instead of
Set_RenderDrawBlendMode

Now it works :slight_smile:

Found - I need Set_TextureBlendMode instead of
Set_RenderDrawBlendMode

Now it works :slight_smile:

Yay! :slight_smile:

See ya,
-Sam Lantinga, Founder and President, Galaxy Gameworks LLC

Found - I need Set_TextureBlendMode instead of
Set_RenderDrawBlendMode

I can see this might be confusing for other people. Are there any preferences
for maintaining global render state vs per-texture render state?

See ya,
-Sam Lantinga, Founder and President, Galaxy Gameworks LLC

Other libs have a “graphics context” abstraction. The user is then
free to what to associate them with, if anything.On Thu, Jan 15, 2009 at 10:24 AM, Sam Lantinga wrote:

I can see this might be confusing for other people. Are there any preferences
for maintaining global render state vs per-texture render state?


http://codebad.com/

I think good documentation is more important.

Sam Lantinga wrote:>> Found - I need Set_TextureBlendMode instead of

Set_RenderDrawBlendMode

I can see this might be confusing for other people. Are there any preferences
for maintaining global render state vs per-texture render state?

See ya,
-Sam Lantinga, Founder and President, Galaxy Gameworks LLC


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org