Advertisement

A tale of two problems!

Started by March 22, 2000 12:06 PM
10 comments, last by ProgHawk 24 years, 7 months ago
I''m having two problems with my program that im writing. One is that one of my functions won''t return values like it should. Here are the parameters. void Get_16Pixel(int x, int y, int r, int g, int b); The function is supposed to return the red, green, and blue bits of the pixel that is specified with the coordinates, but it is returning 0''s. Why? The other is that my DDraw.H header doesn''t support my directx, and when i use any directdraw parts other than the originals, it has errors in the header.


issue 1:

void Get_16Pixel( int x, int y, int r, int g, int b ); 


should probably be:

void Get_16Pixel( int x, int y, int *r, int *g, int *b ); 


that is, if you intend to return values in the r,g,b params.

So, you might call it like:

int r,g,b;Get_16Pixel(x,y, &r, &g, &b ); 


issue 2:

It sounds like your compiler may be picking up the old directx header files instead of the later version you may have installed. Be sure to check your directory paths for your compiler and make sure they are pointing to the new versions, and that they have a higher priority than the originals (they are higher on the list).

HTH,

-mordell


__________________________________________

Yeah, sure... we are laughing WITH you ...
Advertisement
You could also use:

void Get_16Pixel(int x, int y, int &r, int &g, int &b);

and call it like

int red, green , blue;
Get_16Pixel(x,y, red, green,blue);

Look for info on "passing by value" and "passing by reference" for details.

Andrew

Edited by - acraig on 3/22/00 12:25:27 PM

Edited by - acraig on 3/22/00 12:26:20 PM
I was just about to say that, Craig! Only, I think that you can only do that in C++. In C, you have to do what mordell said (don''t quote me on that, though, because I''m not absolutely positive).

If you code it, they will come...

Commander M
http://commanderm.8m.com
cmndrm@commanderm.8m.com
You quite right CmndrM, for straight C that will not work.



Andrew
Hey, I have another idea how to do this (or maybe i just read the original problem wrong ).

Why don''t you create a struct or class like:

typedef struct rgbstruct {
int r;
int g;
int b;
} RGB;

//create r, g, and b integers.

int red, green, blue;

//function...

RGB Get_16Pixel(int x, int y, int *r, int *g, int *b);

and return the RGB struct (that you filled in when you called the function). Of course, you''d probably be better of using this way when there''s actually a good reason to create an rgb struct.

Martin
______________Martin EstevaolpSoftware
Advertisement
adding on to lpsoftware''s idea with the structure, simply pass the enitre structure as a parameter, and return the values in the struture:

typedef struct rgbstuff{
int r,g,b;
} RGB, * RGB_PTR; // Need asterik to create pointer!!!

RGB rgb_values;

void Get_RGB(int x, int y, RGB_PTR vals) //You need the pointer to the structure!!!
{
int red,green,blue;
// Get RGB values here...
vals.r = red;
vals.g = green;
vals.b = blue;
}

thats it!!!

On a bit of a tangent...

If I were you, I would not use GetPixel and PutPixel routines in DirectX, unless you are only dealing with one or two pixels.

I say this (and I might be wrong) because you''re going to have to lock the surface before you can access it at a pixel level, and unlock it afterwards. If you create getpixel and putpixel routines, they might well be spending a lot of time locking & unlocking the surface, just to acquire/change the contents of one pixel.

Instead: lock the surface, play around with the pixels as you please (do all the stuff you''d use getpixel or putpixel for), then unlock the surface. This will save you a lot of time.

George.

"Who says computer games affect kids, imagine if PacMan affected us as kids, we'd all sit around in a darkened room munching pills and listening to repetitive music....uh oh!"

George. F"Who says computer games affect kids, imagine if PacMan affected us as kids, we'd all sit around in a darkened room munching pills and listening to repetitive music....uh oh!"
Do never forget the difference between data variables and pointers to them!!!

GA @ Rarebyte
Visit our homepage: www.rarebyte.de.stGA
Thanks for all of the help. It finally works, and now about 50% of my graphics library is finished.

This topic is closed to new replies.

Advertisement