Results 1 to 12 of 12

Thread: Loading a surface from a custom file format *RESOLVED*

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Location
    Texas
    Posts
    15

    Loading a surface from a custom file format *RESOLVED*

    In the past I've always used API calls like SetPixelV to draw my graphics, but I've decided its time to upgrade to DirectX. What I'm doing right now is trying to convert one of my old programs that uses SetPixelV into a new one that draws the same stuff with DirectX7. I'm fairly new to DX, and I've read a few tutorials on drawing surfaces, and basic stuff, but I've run into a problem: The images I display are stored in a binary file with pixel information in it instead of a normal bitmap file. I was told that in order to display the image using DirectX, I would have to create a surface and draw directly to its pixel data. Since I am new to DirectX, I have no idea how to do this.

    Are there any tutorials out there that would show me how to load a DirectX surface from a custom file format that stores pixel data, instead of a simple jpeg, bitmap, etc. (preferably in Visual Basic)

    Thanks
    Last edited by Satch; Aug 15th, 2002 at 10:39 AM.

  2. #2
    Addicted Member
    Join Date
    Aug 2002
    Location
    Baltimore, MD
    Posts
    230

  3. #3
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    If you're still interested, post here again. I have some code to create an empty surface and another code chunk to access the surface pixels directly as an array
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  4. #4

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Location
    Texas
    Posts
    15
    Thanks, I got it to work using StretchDIBits

    I'd like to try to access the pixels as an array too, to see what's easier. I'd appreciate it if you showed me how

  5. #5
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Ok... this is the code I use to load an empty surface:

    VB Code:
    1. Public Type KSurface
    2.     SURF As DirectDrawSurface7
    3.     DESC As DDSURFACEDESC2
    4.     Width As Long
    5.     Height As Long
    6. End Type
    7.  
    8. 'Loads an empty surface, based on width/height
    9. Sub LoadEmptySurface(Width As Long, Height As Long, Dest As KSurface, Optional SpecialEffect As Boolean = False)
    10.     'Set the surface's width and height
    11.     Dest.Width = Width
    12.     Dest.Height = Height
    13.    
    14.     'Set the flags
    15.     Dest.DESC.lFlags = DDSD_CAPS Or DDSD_HEIGHT Or DDSD_WIDTH
    16.    
    17.     If Not SpecialEffect Then
    18.         'Load it as a regular surface
    19.         Dest.DESC.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
    20.     Else
    21.         'System memory is faster when it comes to special effects :)
    22.         Dest.DESC.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN Or DDSCAPS_SYSTEMMEMORY
    23.     End If
    24.    
    25.     'Width/height of the image...
    26.     Dest.DESC.lWidth = Width
    27.     Dest.DESC.lHeight = Height
    28.    
    29.     'Create it...
    30.     Set Dest.SURF = DDraw.CreateSurface(Dest.DESC)
    31.    
    32.     'Set the color key to black
    33.     Dim Key As DDCOLORKEY
    34.     Key.low = 0
    35.     Key.high = Key.low
    36.     Dest.SURF.SetColorKey DDCKEY_SRCBLT, Key
    37. End Sub

    And this one to manipulate it as an array:

    VB Code:
    1. Dim EmptyRect As RECT
    2.     Dim DestArray() As Byte
    3.     Backbuffer.SURF.Lock EmptyRect, Backbuffer.DESC, DDLOCK_NOSYSLOCK Or DDLOCK_WAIT, 0
    4.     Backbuffer.SURF.GetLockedArray DestArray()
    5.  
    6.     'Manipulate it here... I assume you already know how the array is organized :) (BGR-BGR-BGR...)
    7.  
    8.     Backbuffer.SURF.Unlock EmptyRect

    Hope that helps

    You can remove the NOSYSLOCK flag to speed up your app, but that means that windows won't be running while the surface is locked so you can't use any Windows APIs and NO errors can occur or your computer will crash
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  6. #6

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Location
    Texas
    Posts
    15
    Okay, I have an array of RGB values for the image I want to paint. What I was doing before was SetLockedPixel, but for some reason the RGB values do not work with it and the colors get all messed up. I think it's because the SetLockedPixel color needs to be 16-Bit, and I have no clue how to convert my RGB colors to this format, and I haven't had luck with GetLockedArray either.

    How can I change my RGB value to the proper 16-bit format used for SetLockedPixel??

  7. #7
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    There's a conversion in one of the horribly-named DirectX4VB apps... You'll need to look. Like I said, you can't find out what one of them means!
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  8. #8
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    And Jotaf, why are you using a type to hold your surface? Oh well, its only a matter of opinion, but seriously. Drop the width/height from that, you can get it from the DDSurfaceDesc.

    Just so you know, Satch, system memory is RAM, therefore if you're putting large surfaces in it your system's going to SLOW DOWN. Also, if you don't delete these surfaces at the end, you'll be cursing yourself while you lose many megs of memory even after your program's finished

    Just to let you know



    (PS. and one more thing, DirectDraw is pretty much depricated. Microsoft wants everyone to jump onto the 3D bandwagon. Though Directdraw is a starting point, you may want to look into DirectGraphics (8) when developing final applications due for release.)
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  9. #9

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Location
    Texas
    Posts
    15

    Talking

    Okay, I found it

    Everything works perfectly now! Thanks a lot guys.

  10. #10
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Heh you're welcome

    Sas what do you mean with that? Ok I'll drop the Width/Height thing (it's faster to type ) but what's wrong with using a UDT?
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  11. #11
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Not much... like I said, coding style. If you like it, go with it. I merely said it for.... actually, I had no reason to say it
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  12. #12
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457


    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

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