Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / dbGetPixelsPointer to write directly to memory

Author
Message
Jash
15
Years of Service
User Offline
Joined: 12th Oct 2009
Location:
Posted: 16th Oct 2009 03:34
In the darkgdk documentation, the description for dbGetPixelsPointer() says we can use this with dbLockPixels() to manipulate pixels directly in memory. I cant find any info about this. dbGetPixelsPointer only returns the first pixel, but what about the rest of them? dbDot() is too slow, so how to I get dbGetPixelsPointer to work?

I make the same kind of games as any Chemisty major would.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 16th Oct 2009 05:57
Did you know that pointers are variable? When you increment the pointer it now points to the next pixel. A pointer to a pixel is not the value of the pixel itself. It's the address of where in memory that pixel resides. You have to dereference the pointer to get the value that it points to.

The best advice I could give you regarding C++ is to learn how to use pointers effectively.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Jash
15
Years of Service
User Offline
Joined: 12th Oct 2009
Location:
Posted: 16th Oct 2009 09:25
Yes, I know that pointers are variables. I know the basics of pointers - I've used them before when I was playing with large arrays. I see what you mean about incrementing the pointer, so now I understand how to access all the pixels in memory. But, I still have the question of how to change the color values of those pixels.
ty Lilith, I'm one step closer to figuring this out.

I make the same kind of games as any Chemisty major would.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 16th Oct 2009 17:02
*pixelPtr = dbRGB (red, green, blue);

or, to retrieve the color of a pixel

DWORD pixelClr = *pixelPtr;

I don't know if it's any faster but when assigning a color I prefer to use

DWORD color = (255 << 24) | (red << 16) | (green << 8) | blue;

And certainly assign the color to a DWORD ahead of time then use that to set the color instead of using dbRGB() if the color is consistent.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
prasoc
16
Years of Service
User Offline
Joined: 8th Oct 2008
Location:
Posted: 16th Oct 2009 18:28
Isn't it using the deference operator to get a value of a pointer ? ( &pixelPtr rather than *pixelPtr)


Your signature has been erased by a mod
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 16th Oct 2009 18:49
Nope! the & operator is strictly "address of" in this context. It's never used for dereferncing. It can be used to indicate a logical "and" operation and it can be used to specify that a value being passed as a parameter is the address of the variable it refers to. It can also be used to declare a variable as a reference.

The use of "*" regarding pointers can be a little confusing until you get used to it. You use it to declare a variable as a pointer but you also use it to dereference an address to derive the value stored at that address. Having used it so much over the years it becomes automatic in my thinking. But I used to have to think something along the lines of

*pixelPtr is "that to which pixelPtr points."

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
prasoc
16
Years of Service
User Offline
Joined: 8th Oct 2008
Location:
Posted: 16th Oct 2009 19:27
I need to get my head around them some more :S thanks for "addressing" (lol) that problem.


Your signature has been erased by a mod
Jash
15
Years of Service
User Offline
Joined: 12th Oct 2009
Location:
Posted: 17th Oct 2009 07:26
Ok thanks again Lilith, I've got it working now. Here is the code if anyone needs it:


void pp(int x, int col){

int* pixel = (int*)dbGetPixelsPointer();
*(pixel+x) = col;
}
[/code
the points wrap when they excede the window's pixel limit. you must use dbLockPixels before the function is called and dbUnlockPixels after it.

I make the same kind of games as any Chemisty major would.

Login to post a reply

Server time is: 2024-11-20 13:34:15
Your offset time is: 2024-11-20 13:34:15