Poor Quality Pics and Non working buttons

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
Xenocide

Poor Quality Pics and Non working buttons

Post by Xenocide »

Ok...I just got this engine a day or two ago, and I've been experimenting with it. Today, I finally decided to make a small game that will

A. Display a Menu screen
B. Act accordingly to the button you press.

I've gotten the menu screen to show up, but nothing happens when I click the button, and the background image is extremely poor quality. (I've tried adjusting the size, changing the file format, etc).

Code: Select all

IrrlichtDevice *device = 0;
s32 cnt = 0;

class MyEventReceiver : public IEventReceiver
{
public:
	virtual bool OnEvent(SEvent event)
	{
		if (event.EventType == EET_GUI_EVENT)
		{
			s32 id = event.GUIEvent.Caller->getID();
			gui::IGUIEnvironment* env = device->getGUIEnvironment();

			switch(event.GUIEvent.EventType)
			{
			/*
			If a button was clicked, it could be one of 'our'
			three buttons. If it is the first, we shut down the engine.
			If it is the second, we create a little window with some 
			text on it. We also add a string to the list box to log
			what happened. And if it is the third button, we create
			a file open dialog, and add also this as string to the list box.
			That's all for the event receiver.
			*/
			case EGET_BUTTON_CLICKED:

				if (id == 103)
				{
					device->closeDevice();
					return true;
				}

				if (id == 102)
				{
					cnt += 30;
					if (cnt > 200) 
						cnt = 0;

					gui::IGUIWindow* window = env->addWindow(
						rect<s32>(100 + cnt, 100 + cnt, 300 + cnt, 200 + cnt), 
						false, // modal?
						L"Create-A-Thug");

					env->addStaticText(L"Coming Soon",  
						rect<s32>(35,35,140,50),
						true, // border?
						false, // wordwrap?
						window);

					return true;
				}

				if (id == 101)
				{
					Render();
					return true;
				}

				break;
			}
		}

		return false;
	}
};


void Menu()
{
	MyEventReceiver receiver;
	IrrlichtDevice *device = createDevice(video::EDT_DIRECTX8,
     core::dimension2d<s32>(640, 480),false,false,&receiver);

	video::IVideoDriver* driver = device->getVideoDriver();
	scene::ISceneManager* smgr = device->getSceneManager();
	gui::IGUIEnvironment* env = device->getGUIEnvironment();
	gui::ICursorControl* cursor = device->getCursorControl();
	IGUIImage* img = env->addImage(rect<int>(0,0,640,480));
	img->setImage(driver->getTexture("../../../media/Background.jpg"));
//  video::ITexture* images = driver->getTexture("../../../media/Background.jpg");
//	video::IImageLoader* image = driver->getTexture("../../../media/Background.jpg");
	env->addButton(rect<s32>(260,140,360,180), 0, 101, L"Play");
	env->addButton(rect<s32>(260,190,360,230), 0, 102, L"Build a Thug");
	env->addButton(rect<s32>(260,240,360,280), 0, 103, L"Quit");

	while(device->run())
	{
		u32 time = device->getTimer()->getTime();
		driver->beginScene(true, true, video::SColor(0,0,0,0));
		env->drawAll();
		//driver->draw2DImage(images, core::position2d<s32>(0,0),
		//core::rect<s32>(0,0,640,480), 0, 
		//video::SColor(0,255,255,255), true);
		driver->endScene();
	}
}
Any help would be greatly appreciated! :D
Xenocide

Buttons

Post by Xenocide »

I got the buttons to work so when you press "Play", it'll start Render() and begin the game, however, when I press the ESC key to exit out of Render, the buttons no longer work anymore.

Also, I have yet to figure out why the images are such low quality.

Newbie requesting help! :cry:
Guest

Post by Guest »

Make sure you use image sizes power of 2 (For example 256x256). You may also call IVideoDriver::setTextureCreationFlag(ETCF_OPTIMIZED_FOR_QUALITY, true);
dingo
Posts: 95
Joined: Tue Mar 09, 2004 5:02 am
Location: Brisbane, Australia
Contact:

Post by dingo »

A picture is worth a thousand words - post a screen shot of "bad quality pictures"
-= Want your C code to control real life robots? www.users.on.net/~symes =-
Acki

Post by Acki »

For quitting the game try to set a flag to true within the event receiver (for example progDeath = true;) and act on this flag in the main loop (if(progDeath) device->closeDevice();)

I had a similar problem with the event receiver and solved it in this way...

CU, Acki
Xenocide

Pic/NewError

Post by Xenocide »

Ok...I can't seem to get the texture optimizer working (as in, it didn't change anything), the progDeath trick doesnt fix the buttons when you exit out (perhaps because I have two different Event receivers?), and I discovered a new bug...when the mouse enters the red box boundary, the game crashes. (See image)
Image
Domarius
Posts: 178
Joined: Thu Mar 11, 2004 9:51 am
Location: Brisbane, QLD, Australia

Post by Domarius »

Anonymous wrote:Make sure you use image sizes power of 2 (For example 256x256). You may also call IVideoDriver::setTextureCreationFlag(ETCF_OPTIMIZED_FOR_QUALITY, true);
Exactly. If your picture dimensions aren't a power of 2, they get resized by the video card, and you get yucky pixels.

Open up the textures folder for any of your commercial video games, and you'll see all the textures are sizes like 64x64, 128x32, 128x128, etc.
Tyn
Posts: 932
Joined: Thu Nov 20, 2003 7:53 pm
Location: England
Contact:

Post by Tyn »

Also, smaller textures have better resolution. This is a limit by the video cards IIRC, I found that anything about 512x512 looks real crappy. I try not to have anything above 256x256. I suggest you split that picture up into several different sections and load them that way, it gets a much better result.
Post Reply