iNET Interactive - Online Advertising Agency
          
Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Game Programming > Trapezoid Blt?


Reply
 
Thread Tools Display Modes
  #1  
Old 02-06-2004, 07:16 AM
SpeedPear SpeedPear is offline
Regular
 
Join Date: Jan 2004
Posts: 103
Default Trapezoid Blt?

I need to blt the image of a wall to a trapezoid. Trapezoids are not squares so bitblt and strechblt wont work. Any ideas?
__________________
SpeedPear
Enter the pear
----------------------------------
Aeon Nexus Games
Reply With Quote
  #2  
Old 02-06-2004, 08:11 AM
Bljashinsky's Avatar
Bljashinsky Bljashinsky is offline
Senior Contributor
 
Join Date: Nov 2003
Location: California
Posts: 1,016
Default Bitblt will work won't it

I don't understand why bitblt won't work. Please enlighten me because as far as I know as long as you have a mask of an image any shape will work. I am sort of new to bitblt so I may be wrong.
__________________
Check out my website:
Reimagine Memories
Reply With Quote
  #3  
Old 02-06-2004, 08:16 AM
Iceplug's Avatar
Iceplug Iceplug is offline
MetaCenturion

Preferred language:
Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Hawaii, USA
Posts: 16,576
Default

Indeed, you should be able to draw a trapezoid picture of a wall with BitBlt... if you make a mask of a trapezoid, and then make a picture of the wall shaped like a trapezoid, then you can do it.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #4  
Old 02-06-2004, 01:28 PM
rpgnewbie's Avatar
rpgnewbie rpgnewbie is offline
Contributor
 
Join Date: Sep 2003
Location: Portland OR
Posts: 581
Default Use Stretchblt for trapezoidal...

Quote:
Originally Posted by SpeedPear
I need to blt the image of a wall to a trapezoid. Trapezoids are not squares so bitblt and strechblt wont work. Any ideas?



Please check out "VB_Image Perspective.zip" attached to this thread:
http://www.xtremevbtalk.com/t114884.html

I use this program (which uses stretchblt) to "reshape" a square bitmap into a trapezoidal shape to create perspective mapped textured "walls" for a pseudo-3d maze game I made.

Attached are a couple of screenies of the program at design and run time to show that the "reshaping" happens at run time;

And personnally I would never start a thread with a post saying something "won't" work. It's better to say "I don't know how to get such and such to work..."
Attached Images
File Type: jpg ImagePerspective_DesignForm.jpg (105.5 KB, 42 views)
File Type: jpg ImagePerspective_Runtime.jpg (113.6 KB, 47 views)
Reply With Quote
  #5  
Old 02-06-2004, 03:11 PM
SpeedPear SpeedPear is offline
Regular
 
Join Date: Jan 2004
Posts: 103
Default

RPG Newbie, thank you SO much. I still have a problem though. . I need to repeatedly stretch the wall and bitblt it right inside the trapezoid. Your code seems to go off of a mask. Since the trapezoid always changes depending on angle, it would be impossible to have enough masks for it, unless I'm just not understanding your code. other than that, its exactly what I was looking for. I already know how to use bitblt, but needed to put a square onto a trapezoid. Others, thanks for trying...
__________________
SpeedPear
Enter the pear
----------------------------------
Aeon Nexus Games

Last edited by SpeedPear; 02-06-2004 at 03:18 PM.
Reply With Quote
  #6  
Old 02-06-2004, 03:21 PM
Squalion Squalion is offline
Regular
 
Join Date: Sep 2003
Location: Manchester, England
Posts: 69
Default

I think to do that, and have it changed depending on angle, you'd need to be using some form of DirectX. Well it'd be easier that way, than finding a huge workaround in gdi or win32.
__________________
Currently working on:
Gdi32
Reply With Quote
  #7  
Old 02-06-2004, 03:29 PM
SpeedPear SpeedPear is offline
Regular
 
Join Date: Jan 2004
Posts: 103
Default

I AM going to do it in bitblt or some other form of API. I've tryed DirectX and it's not my cup of tea. I figure it won't be worth it. I mainly want to specify 4 x,y coordinates to the function and have it draw it. Of course there will be other parameters to this function that i will make. This is urgent in case you guys were wondering...
__________________
SpeedPear
Enter the pear
----------------------------------
Aeon Nexus Games

Last edited by SpeedPear; 02-06-2004 at 03:37 PM.
Reply With Quote
  #8  
Old 02-06-2004, 05:21 PM
rpgnewbie's Avatar
rpgnewbie rpgnewbie is offline
Contributor
 
Join Date: Sep 2003
Location: Portland OR
Posts: 581
Default Programmatic masking

Quote:
Originally Posted by SpeedPear
I AM going to do it in bitblt or some other form of API. I've tryed DirectX and it's not my cup of tea. I figure it won't be worth it. I mainly want to specify 4 x,y coordinates to the function and have it draw it. Of course there will be other parameters to this function that i will make. This is urgent in case you guys were wondering...


Why is it that knee jerk response is so often DirectX. It's a great "tool", but you don't always have to use it for everything. (a hammer doesn't make a good screwdriver )

Anyway, I think if you wise to be seeking another method if you have a lot of masks to generate (they can take up a lot of space).

Here is OnErrOr's Code Library thread to get you started with "programmatic" (on-the-fly) masking:
http://www.xtremevbtalk.com/t109862.html
Reply With Quote
  #9  
Old 02-06-2004, 05:53 PM
SpeedPear SpeedPear is offline
Regular
 
Join Date: Jan 2004
Posts: 103
Default

actually, i've generated masks during run time. of course this od can be VERY slow, if i'm correct, on error does it differently then I did. Generally, I'm very good at looking at code and then learning from it. However, I don't know anything about DCs and that stuff. I generally bitblt from picture boxes ect. Any ideas on how I can port this code to about a 20-30 function to generate masks quickly?
__________________
SpeedPear
Enter the pear
----------------------------------
Aeon Nexus Games
Reply With Quote
  #10  
Old 02-06-2004, 06:31 PM
hDC_0 hDC_0 is offline
Junior Contributor

Preferred language:
* Expert *
 
Join Date: Feb 2004
Posts: 259
Default Device Contexts...

Quote:
Originally Posted by SpeedPear
actually, i've generated masks during run time. of course this od can be VERY slow, if i'm correct, on error does it differently then I did. Generally, I'm very good at looking at code and then learning from it. However, I don't know anything about DCs and that stuff. I generally bitblt from picture boxes ect. Any ideas on how I can port this code to about a 20-30 function to generate masks quickly?



Hmmm, on one hand you are complaining about speed and the other you say you don't know much about "DCs and such"...

I guess I can only tell you that using MemoryDCs ARE the answer to any speed concerns. They are the fastest way that VB has to manipulate graphics short of DirectX.

So my "idea" about porting OnErrOr's code (to what you specifically want to do) is to just try getting it to do what you want. Maybe the learning curve for working with Device Contexts is not as steep as you think. If you run into difficulties, post the code that is giving you problems and someone (maybe even OnErrOr) will try to help...

I noticed your "Aeon Nexus" page has a link to "New World Games" - Are you doing this project in connection with Bljashinsky?
Reply With Quote
  #11  
Old 02-06-2004, 09:29 PM
Rockoon's Avatar
Rockoon Rockoon is offline
Joseph Koss

Preferred language:
* Guru *
 
Join Date: Aug 2003
Location: Unfashionable End
Posts: 3,313
Default

This falls under the texture mapping algorithms..

..the idea is rather simple to understand tho not so simple to code up and make everything work .. but given a 4-cornered polygon specified by 4 X/Y pairs -- its simply a matter of looping through all the pixels within this polygon and convert the pixels X/Y to the textures (bitmap) X/Y .. and grabbing the color for the pixel from it.

I've used the term 'simply' when really its not so simple until you understand it.. very detailed docs can be found on GameDev

The hard part isnt so much the texture mapping - the hard part is optimising it.
Reply With Quote
  #12  
Old 02-07-2004, 07:40 AM
SpeedPear SpeedPear is offline
Regular
 
Join Date: Jan 2004
Posts: 103
Default

I've started on something that goes pixel by pixel stretching it to the trapezoid with no luck. I have the basic concept on how to do it but for some reason I can't do it. About the site, BJashinsky's link is on it because I think he asked me to put it on it. I think that's how it was but I don't remember that well. He is not working on it. I guess you were also asking me that to know why I'm working on this instead of the RPG. The answer is that this game was a side project type deal. I guess it's time to start learning about Device Contexts and how to use them and take advantage of them for my programs. Do any of you know of a good tutorial to get me started?
__________________
SpeedPear
Enter the pear
----------------------------------
Aeon Nexus Games
Reply With Quote
  #13  
Old 02-07-2004, 06:12 PM
SpeedPear SpeedPear is offline
Regular
 
Join Date: Jan 2004
Posts: 103
Default

Anyone?
__________________
SpeedPear
Enter the pear
----------------------------------
Aeon Nexus Games
Reply With Quote
  #14  
Old 02-07-2004, 07:16 PM
JimCamel's Avatar
JimCamel JimCamel is offline
Mostly Absent

Preferred language:
* Expert *
 
Join Date: Jun 2002
Location: Christchurch, New Zealand
Posts: 2,006
Default

If you're doing it pixel by pixel, you could try something like this:

Code:
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long Private Declare Function SetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long Private Sub Command1_Click() Dim i As Integer, j As Integer Dim startx As Integer For j = 0 To srcPicture.Height For i = 0 To srcPicture.Width SetPixel destPicture.hdc, i + startx, j, GetPixel(srcPicture.hdc, i, j) Next i startx = startx + 1 Next j End Sub

All you need is an image in a picturebox called srcPicture, and a picturebox called destPicture which will be drawn in. If you want to change the slope, just change the value which you're adding to StartX each loop.
Attached Files
File Type: zip Trapezoid.zip (1.4 KB, 19 views)
__________________
Sometimes it happens feelings die, Whole years are lost in the blink of an eye
We once had it all but event conspired, Sometimes
Now that it's over, it is through, It gets me everytime I think of you
Sometimes It happens, feelings die, Sometimes
Reply With Quote
  #15  
Old 02-07-2004, 07:19 PM
Bljashinsky's Avatar
Bljashinsky Bljashinsky is offline
Senior Contributor
 
Join Date: Nov 2003
Location: California
Posts: 1,016
Default Not sure if you still need this but here's something from MSDN

Here's a link to the MSDN page on device context's.
http://msdn.microsoft.com/library/de...vcons_0g6r.asp
__________________
Check out my website:
Reimagine Memories
Reply With Quote
  #16  
Old 02-07-2004, 09:30 PM
rpgnewbie's Avatar
rpgnewbie rpgnewbie is offline
Contributor
 
Join Date: Sep 2003
Location: Portland OR
Posts: 581
Default Device Context Tutorials

On Lucky's gaming site there is an article (you might want to look at comparing times with different techinques: Pset/Point, GetPixel/SetPixel, GetPixel/SetPixel with DCs, and using Pointers:
http://www.rookscape.com/vbgaming/tutAY.php

I have spent many hours playing with the code on BillSoo's Tutor's Corner post dealing with Direct memory Access (DMA):
http://www.xtremevbtalk.com/t25347.html

There are many places on the Internet to learn about using Device Contexts with VB. Here's just a few:
http://www.officecomputertraining.co...ges/page44.asp
http://www.vb-helper.com/howto_memory_bitmap_text.html

and check out "Using and creating memory DCs" at the bottom of this page:
http://www.vbexplorer.com/VBExplorer/gdi2.asp

Note the MemoryDC sample mentioned on the page link above is part of a zip package "sam_pro.zip" which can be downloaded by clicking on "Download All Sample" link on this page:
http://www.vbexplorer.com/VBExplorer/gdi.asp
Reply With Quote
  #17  
Old 02-08-2004, 09:46 AM
SpeedPear SpeedPear is offline
Regular
 
Join Date: Jan 2004
Posts: 103
Default

Thank you all so much.
__________________
SpeedPear
Enter the pear
----------------------------------
Aeon Nexus Games
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement: