Problem with IVideoDriver::draw2DImage

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
seno
Posts: 34
Joined: Thu Nov 17, 2005 2:50 am
Location: Seoul Korea

Problem with IVideoDriver::draw2DImage

Post by seno »

Hi.

First of all, please understanding my short english writing.

i am new here, but i must be the one of the exciting

programmers because of Irrlicht Engine.

Recently, i started developing 2D Game API with Irrlicht

Engine and soon i encountered with this problem.

When i use IVideoDriver::draw2DImage by loading this image

Image

i got a result like this.

Image

as u can see i gave the red color as the colorkey of the first

bmp file image and the problem is broken image. i used exactly

actual size of the image, which means no magnification.

The bmp file image is set as 24bits color and i used a

IrrlichtDevice with setting of 24bits color.


There are not much code to show, casue it's pretty much same

with tutorial's 2D Game Sample.


Does anyone has clue for this broken image?


thanx for your attention~
Let's Take Over the World ~!!
AticAtac
Posts: 29
Joined: Mon Mar 22, 2004 2:46 pm
Location: Germany

Post by AticAtac »

Please provide the code-parts concerning the imageloading and imagedrawing so we can better help you.
seno
Posts: 34
Joined: Thu Nov 17, 2005 2:50 am
Location: Seoul Korea

Post by seno »

The code is almost same with tutorial's 2D graphics.

I coded like..

Code: Select all

IrrlichtDevice *device = createDevice(driverType,
         core::dimension2d<s32>(512, 384));

video::IVideoDriver* driver = device->getVideoDriver();

video::ITexture* background = driver->getTexture("bg_01.bmp");
video::ITexture* interface = driver->getTexture("interface.bmp");
driver->makeColorKeyTexture(interface, core::position2d<s32>(200,200));

while(device->run() && driver)
{
	if (device->isWindowActive())
	{
		driver->beginScene(true, true, video::SColor(255, 0, 255, 255));
                
                driver->draw2DImage(background,      
                                               core::position2d<s32>(0,0),
	                                       core::rect<s32>(0,0,800,600), 0, 
	                                       video::SColor(255,255,255,255), true);
                driver->draw2DImage(interface,      
                                               core::position2d<s32>(0,0),
	                                       core::rect<s32>(0,0,800,600), 0, 
	                                       video::SColor(255,255,255,255), true);
                driver->endScene();
        }
}

....
Too simple... actually, after i failed with my 2D Game API, i put the test

code like above in the 2D grapphic tutorial code. No change for creation

of IrrlichtDevice(defaultly 24bits and resolution is 800x600) and..

i got same result with my 2D Game API.


You might test below code with the jpg file that i posted which will provide

same result..

Code: Select all

#include <irrlicht.h>
#include <iostream>

using namespace irr;

#pragma comment(lib, "Irrlicht.lib")
               
int main()
{
  // let user select driver type
  video::E_DRIVER_TYPE driverType;

  printf("Please select the driver you want for this example:\n"\
         " (a) Direct3D 9.0c\n (b) Direct3D 8.1\n (c) OpenGL 1.2\n"\
         " (d) Software Renderer\n (e) NullDevice\n (otherKey) exit\n\n");

   char i;
   std::cin >> i;

   switch(i)
   {
   case 'a': driverType = video::EDT_DIRECTX9;	break;
   case 'b': driverType = video::EDT_DIRECTX8;	break;
   case 'c': driverType = video::EDT_OPENGL;   break;
   case 'd': driverType = video::EDT_SOFTWARE; break;
   case 'e': driverType = video::EDT_NULL;     break;
   default: return 0;
   }	

   // create device

  IrrlichtDevice *device = createDevice(driverType,
           core::dimension2d<s32>(512, 384));

  if (device == 0)
      return 1;
 
  device->setWindowCaption(L"Irrlicht Engine - 2D Graphics Demo");

  video::IVideoDriver* driver = device->getVideoDriver();

  video::ITexture* background = driver->getTexture("bg_01.bmp");
  video::ITexture* interface = driver->getTexture("interface.bmp");
  driver->makeColorKeyTexture(interface,   
                core::position2d<s32>(200,200));

  while(device->run() && driver)
  {
	  if (device->isWindowActive())
	 {
		  driver->beginScene(true, true, 
                                 video::SColor(255, 0, 255, 255));
                
                  driver->draw2DImage(background,      
                                               core::position2d<s32>(0,0),
	                                       core::rect<s32>(0,0,800,600), 0, 
	                                       video::SColor(255,255,255,255), true);
                  driver->draw2DImage(interface,      
                                               core::position2d<s32>(0,0),
	                                       core::rect<s32>(0,0,800,600), 0, 
	                                       video::SColor(255,255,255,255), true);
                  driver->endScene();
          }
  }

   device->drop();
   return 0;
}
[\code]

  
Let's Take Over the World ~!!
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

try this :

Code: Select all

driver->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, true);
driver->setTextureCreationFlag( video::ETCF_CREATE_MIP_MAPS, false );
video::ITexture* background = driver->getTexture("bg_01.bmp"); 
video::ITexture* interface = driver->getTexture("interface.bmp"); 
driver->makeColorKeyTexture(interface, core::position2d<s32>(200,200)); 
driver->setTextureCreationFlag( video::ETCF_CREATE_MIP_MAPS, true );
Image
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

Also, make sure the texture dimension is a power of 2.
Image
seno
Posts: 34
Joined: Thu Nov 17, 2005 2:50 am
Location: Seoul Korea

Post by seno »

First, Sorry about my late response.

I live the oposite side of the earth from where you live.


Thank you, Spintz!

U saved me~

It was about setting the source picture file resolution to be related with

the power of 2.

I read something about the info, but i misunderstood that as setting the

window size or something like that.

I guess since this problem is solved, i only need to build custom event

handler for my own controls.


Thanks to you all~
Let's Take Over the World ~!!
Post Reply