Results 1 to 5 of 5

Thread: C++: Lock and Fill Surface Array

  1. #1

    Thread Starter
    PowerPoster Halsafar's Avatar
    Join Date
    Jun 2004
    Location
    Saskatoon, SK
    Posts
    2,339

    C++: Lock and Fill Surface Array

    I know in VB this was an easy easy easy process.

    To lock a surface, get a BYTE array full of each pixel's color value.
    Unlock the surface and continue.


    I need this to do the most simple alpha blend...fade an image to black.

    I got this far myself:

    PHP Code:
    //--------------------
    //Lock a surface
    //--------------------
    void DDSurface7::Lock()
    {
       
    m_Surface->Lock(NULL,&m_ddsdLock,DDLOCK_WAIT,NULL);
    }


    //--------------------
    //Unlock the surface
    //--------------------
    void DDSurface7::Unlock()
    {
        
    m_Surface->Unlock((LPRECT)m_ddsdLock.lpSurface);
    }


    //--------------------
    //Fill the array
    //--------------------
    void DDSurface7::FillByteArray()
    {    
       if (
    m_PixelArraym_PixelArray NULL;

       
       
    //m_PixelArray = new BYTE[m_ddsdLock.lPitch * m_ddsdLock.dwHeight];
       
    m_PixelArray = (BYTE*)m_ddsdLock.lpSurface;


    In order I call the Lock()
    Then I call FillByteArray. I then run a loop on m_PixelArray somewhere else in the program and it ALWAYS has a 0 for every value.

    What em I doing wrong???
    "From what was there, and was meant to be, but not of that was faded away." - - Steve Damm

    "The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm

    "When you do things right, people won't be sure if you did anything at all." - - God from Futurama

  2. #2
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: C++: Lock and Fill Surface Array

    Well your lucky I'm here because I happen to be almost an expert at this. You were supposed to fill the byte after you Lock it which is how you have it now and then unlock. Not sure if you unlocked it. Try it and let me know how it turns out. I'm assuming now you are using DirectX9 right?
    Last edited by Jacob Roman; Dec 5th, 2004 at 10:30 AM.

  3. #3

    Thread Starter
    PowerPoster Halsafar's Avatar
    Join Date
    Jun 2004
    Location
    Saskatoon, SK
    Posts
    2,339

    Re: C++: Lock and Fill Surface Array

    Dx9..I wish...I am using an 8mb video card. on a p2 celeron 333.

    Anyway...

    I am locking it.
    Then filling the array.
    Dealing with the array.
    Then Unlocking it.

    I assume that is that is how it goes.
    still...all = 0
    "From what was there, and was meant to be, but not of that was faded away." - - Steve Damm

    "The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm

    "When you do things right, people won't be sure if you did anything at all." - - God from Futurama

  4. #4

    Thread Starter
    PowerPoster Halsafar's Avatar
    Join Date
    Jun 2004
    Location
    Saskatoon, SK
    Posts
    2,339

    Re: C++: Lock and Fill Surface Array

    I am looking to right a basic SNES style alpha blending technique...

    ------------
    Color Addition Taking two colors, dividing their RGB values by a certain value (usually 2, the higher the value, the darker the resulting color is), and adding the two sets of RGB values together to form the result. This is the type of translucency the SNES used. Here's a formula, perhaps this will help:

    R(result) = (R(1) + R(2)) / 2;
    G(result) = (G(1) + G(2)) / 2;
    B(result) = (B(1) + B(2)) / 2;
    ------------

    If I can't lock the surface and get a plausable array I am just goona go the DC way....which I know I can do easily.

    I think I'm goona have to use GetPixel and SetPixel API anyway....Dx7 doesn't seem to have any such functions for their surfaces that I can find.
    "From what was there, and was meant to be, but not of that was faded away." - - Steve Damm

    "The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm

    "When you do things right, people won't be sure if you did anything at all." - - God from Futurama

  5. #5
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: C++: Lock and Fill Surface Array

    I'm no C++ guru but I'll try my best to solve it in C++. AH HA! I see it where you messed up now. Try this:

    *m_PixelArray = (BYTE *)m_ddsdLock.lpSurface;

    I added an astrick next to m_PixelArray. And here's an example C program I wrote to show you what it did:

    Code:
    #include <stdio.h>
    
    //lpSurface is a part of DirectX's DDSURFACEDESC2, 
    //but since I'm not using DirectX here, I created lpSurface 
    //myself.
    
    int main(void)
    {
    
    //You lock it here
    
    	int *Surface_Ptr, *lpSurface;
    
    	int Values_In_Surface[] = {10,20}; //2 Values for now.
    
    	int m_PixelArray[] = {0,0}; //2 Values for now.
    
    	lpSurface = Values_In_Surface;
    
    	*m_PixelArray = *lpSurface;
    
    //You unlock it here
    
    	printf("%d\n",m_PixelArray[0]); //Output is 10
    
    	return 0;
    
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width