Using 2D functions to draw a scope on screen?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Spartacus
Posts: 70
Joined: Fri Nov 21, 2003 11:56 pm

Using 2D functions to draw a scope on screen?

Post by Spartacus »

I tried a few things like draw2dImage i cant seem to get this to work I want to draw like a scoipe so it zooms in but when it zooms in I only want like a circular area to be seen though as if you are looking through a scope. I tried using ITexture or something and drawing 2D above the 3d but nothing happend. Anyone have like a example of how this is done I tried a few things but yea nothing was working :/
rt
Posts: 150
Joined: Sun Nov 30, 2003 6:54 am
Location: canada
Contact:

alpha

Post by rt »

you need to create a bitmap of a circle. when you load up the texture set the color of the circle in the bitmap to be the colorkey so that it becomes transparent.

Code: Select all

	irr::video::ITexture* scope = grr.driver->getTexture("scope.bmp");
	grr.driver->makeColorKeyTexture(scope, irr::video::SColor(255,255,255,255)); //assuming the circle is white
then smgr->drawAll() your 3d world and then

Code: Select all

device->getVideoDriver()->draw2DImage(scope,irr::core::position2d<s32>(screenX/2,screenY/2),irr::core::rect<s32>(0,0,128,128),NULL,irr::video::SColor(255,255,255,255),true); 
the only problem is that you need to stretch the texture to fill the screen
Spartacus
Posts: 70
Joined: Fri Nov 21, 2003 11:56 pm

Post by Spartacus »

the scope image becomes inverted like about half way inbetween the image and the colors like swap or somthing... its just not right lol
rt
Posts: 150
Joined: Sun Nov 30, 2003 6:54 am
Location: canada
Contact:

Post by rt »

Spartacus wrote:the scope image becomes inverted like about half way inbetween the image and the colors like swap or somthing... its just not right lol
btw, using the code from this thread (http://irrlicht.sourceforge.net/phpBB2/ ... .php?t=633) you can stretch a 'scope' bitmap to fill the screen. i tried it out (using my derived camera class) and it seems to work well.
Spartacus
Posts: 70
Joined: Fri Nov 21, 2003 11:56 pm

Post by Spartacus »

So you didnt have a problem with the colors inverting half way in the image? Its like.... it worked with black color for like 65% of the image from the top going down but the rest inverted.. by inverted i mean like, It was showing the black color of the bitmap till it hit 65% of the height down and then it only showed the white part of the bitmap 0.o, and removed the black. Kinda werid... I also was wondering if you knew how I could apply more then 1 color to like make the scope somewhat fade to black rather then the instant change to black :P
rt
Posts: 150
Joined: Sun Nov 30, 2003 6:54 am
Location: canada
Contact:

Post by rt »

Spartacus wrote:So you didnt have a problem with the colors inverting half way in the image? Its like.... it worked with black color for like 65% of the image from the top going down but the rest inverted.. by inverted i mean like, It was showing the black color of the bitmap till it hit 65% of the height down and then it only showed the white part of the bitmap 0.o, and removed the black. Kinda werid... I also was wondering if you knew how I could apply more then 1 color to like make the scope somewhat fade to black rather then the instant change to black :P
the inverting could happen if you specify an incorrect size when displaying the graphic. try this code

Code: Select all

	irr::video::ITexture* scope = driver->addTexture(irr::core::dimension2d<s32>(800,600),"myScope"); //create empty texture which fits the screen (assume screen is 800x600)
	irr::video::ITexture* scope2 = driver->getTexture("scope.bmp"); //get the bitmap of the scope, assume it's 64x64
	grr.driver->makeColorKeyTexture(scope2, irr::video::SColor(255,255,255,255)); //make anything white into transparent
	StretchTextureFast(scope,scope2,irr::core::rect<irr::s32>(0,0,800,600),irr::core::rect<irr::s32>(0,0,64,64)); //scale texture
......
device->getVideoDriver()->draw2DImage(scope,irr::core::position2d<s32>(0,0),irr::core::rect<s32>(0,0,800,600),NULL,irr::video::SColor(255,255,255,255),true); //draw it
as for the blending of black to white, you'd need to add some alpha blending into your scope graphic. it's a shame that irrlicht doesn't support .png format which i think is the easiest to create alpha blended images with... you'll have to save it as a .tga or .psd
Post Reply