PDA

View Full Version : Changing RGB



Jonne
03-02-2006, 05:17 PM
Hello. How im able to draw pictures with different rgb's?

Paulius
03-02-2006, 05:28 PM
You?_Tre question doesn?_Tt make much sense, do you mean using palettes or color modulation or something?

Robert Kosek
03-02-2006, 06:18 PM
I'm assuming that you are meaning draw a greyscale image using an RGB color?

LP
03-02-2006, 06:56 PM
Hello. How im able to draw pictures with different rgb's?
Turn off the grayscale mode (http://en.wikipedia.org/wiki/Grayscale) of your monitor. This will show color picture (http://en.wikipedia.org/wiki/Oil_painting) instead of black and white (http://en.wikipedia.org/wiki/Black-and-white_warbler). You may need to acquire a different monitor, if your current monitor does not have the mentioned feature.

AthenaOfDelphi
04-02-2006, 09:36 AM
Hello. How im able to draw pictures with different rgb's?

Hi Jonne,

You have numerous options available to you. The first and simplest way is to use the pixels property of the TDXDraw surface, like this:-


dxdraw1.surface.pixels[x,y]:=aColor;



You can also fill an area of the surface, like this:-


var
dst : TRect;
begin
dst.top:=10;
dst.bottom:=30;
dst.left:=10;
dst.right:=30;

dxdraw1.surface.fillRect(dst,aColor);
end;



In both examples, aColor is a colour value. I'm not sure whether they operate exactly like Delphi's standard TColor, where you specify the colour value in hex like this:- $bbggrr where bb, gg and rr are the values for Blue, Green and Red respectively. I think they may flip the Blue and Red around to the more traditional $rrggbb notation.

You also have another option for drawing on the TDXDraw surface. You can use a TDXImageList, that you load with images (this can be done at design time or dynamically at runtime). To get started, put the images into the TDXImageList at design time as its easier. Then, you can do this:-


dxImageList1.items[0].draw(dxdraw1.surface,xPos,yPos,pattern);



I use a pattern value of 0 as I have no idea what it does yet. This will draw the image in the image list at position 0 to the surface with its top left corner at xPos,Ypos on the surface. There are lots of different variations on this method that allow you to incorporate alpha blending and other effects.

And last but not least, the TDXDraw surface also has a fairly standard TCanvas property allowing you to plot lines, text, arcs. etc.


with dXDraw1.Surface.Canvas do
begin
Brush.Style := bsClear;
Font.Color := clWhite;
Font.Size := 8;
Font.style:=[fsBold];
Font.name:='Courier New';

TextOut(0,0,'Hello World');

Release;
end;



You must remember to release the canvas when you've finished using it.

So, bringing this all together, you might have something like this in a TDXTimer onTimer event:-


if dxdraw1.canDraw then
begin
dxdraw1.surface.fill(0); // Clear the draw area

dximagelist1.items[0].draw(dxdraw1.surface,0,0,0);
dximagelist1.items[1].draw(dxdraw1.surface,100,100,0);

with dxdraw1.surface.canvas do
begin
// Use the canvas here
release;
end;

dxdraw1.flip; // You must have doFlip in the options to use this
end;



You don't have to use flip, but using it makes for a smoother display since the user only sees the new screen when you've finished drawing it. But you must have the doFlip option set in the TDXDraw options. If you are using unDelphiX, to enable hardware acceleration, you should have the following options set to true:- do3D, doDirectX7Mode and doHardware.

You may also want to check out all the examples that come with unDelphiX. They are quite useful.

I hope this helps.

User137
05-02-2006, 12:23 AM
He means that image is multiplied with a color.

Here's discussion about improved undelphix and how it can be done:
http://www.delphigamedev.com/forums/viewtopic.php?t=292

It makes this kind of command possible:
DrawAlphaCol(Surface, DestRect, PatternIndex, RGB(0,255,0), Alpha);
That would draw grayscale image as green, red or blue image as black and so on...

Edit: Made this small demonstration :wink:
This uses only 1 TDXImageList item, only colors them with alpha weakening when going down.

http://i1.tinypic.com/n5n3n6.png

AthenaOfDelphi
05-02-2006, 09:45 AM
Neat.

I figured he wanted something else, because after I posted I read about Netsoccer. But still, worth my time posting, because now I've learned something :-)