|
-
Aug 8th, 2002, 07:50 PM
#1
Thread Starter
New Member
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.
-
Aug 8th, 2002, 11:31 PM
#2
Addicted Member
-
Aug 10th, 2002, 07:11 PM
#3
Frenzied Member
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
-
Aug 13th, 2002, 12:23 AM
#4
Thread Starter
New Member
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
-
Aug 13th, 2002, 04:40 PM
#5
Frenzied Member
Ok... this is the code I use to load an empty surface:
VB Code:
Public Type KSurface
SURF As DirectDrawSurface7
DESC As DDSURFACEDESC2
Width As Long
Height As Long
End Type
'Loads an empty surface, based on width/height
Sub LoadEmptySurface(Width As Long, Height As Long, Dest As KSurface, Optional SpecialEffect As Boolean = False)
'Set the surface's width and height
Dest.Width = Width
Dest.Height = Height
'Set the flags
Dest.DESC.lFlags = DDSD_CAPS Or DDSD_HEIGHT Or DDSD_WIDTH
If Not SpecialEffect Then
'Load it as a regular surface
Dest.DESC.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
Else
'System memory is faster when it comes to special effects :)
Dest.DESC.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN Or DDSCAPS_SYSTEMMEMORY
End If
'Width/height of the image...
Dest.DESC.lWidth = Width
Dest.DESC.lHeight = Height
'Create it...
Set Dest.SURF = DDraw.CreateSurface(Dest.DESC)
'Set the color key to black
Dim Key As DDCOLORKEY
Key.low = 0
Key.high = Key.low
Dest.SURF.SetColorKey DDCKEY_SRCBLT, Key
End Sub
And this one to manipulate it as an array:
VB Code:
Dim EmptyRect As RECT
Dim DestArray() As Byte
Backbuffer.SURF.Lock EmptyRect, Backbuffer.DESC, DDLOCK_NOSYSLOCK Or DDLOCK_WAIT, 0
Backbuffer.SURF.GetLockedArray DestArray()
'Manipulate it here... I assume you already know how the array is organized :) (BGR-BGR-BGR...)
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
-
Aug 15th, 2002, 05:34 AM
#6
Thread Starter
New Member
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??
-
Aug 15th, 2002, 09:58 AM
#7
Good Ol' Platypus
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)
-
Aug 15th, 2002, 10:01 AM
#8
Good Ol' Platypus
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)
-
Aug 15th, 2002, 10:38 AM
#9
Thread Starter
New Member
Okay, I found it 
Everything works perfectly now! Thanks a lot guys.
-
Aug 15th, 2002, 06:57 PM
#10
-
Aug 17th, 2002, 01:07 AM
#11
Good Ol' Platypus
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)
-
Aug 18th, 2002, 05:54 PM
#12
Frenzied Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|