Graphics Programming in Visual Basic - An Introduction
"Visual Basic CAN Do Fast Graphics"
By: Tanner "DemonSpectre" Helland
Despite what many programmers will tell you, Visual Basic is an excellent programming language for high-end graphic applications - with or without DirectX and OpenGL. Many VB programmers seem to believe that the only way to get fast 2D graphics is with DirectDraw…and they are completely wrong! Using some creativity and efficient coding you can get the API to do anything that DirectDraw does - and nearly as fast (and in some cases faster!). But this is not to say that only the DirectX-paranoid can benefit from this tutorial, because even the best DX experts could use a good explanation of how Windows handles graphics routines. This series of articles will explain not only how to do fast graphics but how fast graphics work. You will first learn about pure VB routines for graphics processing; next comes the basic API routines of GetPixel and SetPixel/V; third comes the more advanced GetBitmapBits, SetBitmapBits, and DIB sections; the last tutorial will cover additional optimizations for the real speed demons out there. By the end of this series of tutorials you will be able to effectively write any graphics application you can dream up using nothing but Visual Basic and the Windows API.
But first, it's probably good to clarify a little bit about graphics programming in general.
-GENERAL GRAPHICS PROGRAMMING STUFF-
Graphics programming (hereafter referred to as GP) is - hands down - the most far-reaching aspect of programming. Every Windows, Linux, and Macintosh program that has been written in the last fifteen years has utilized graphics in some way. Because of the popularity of GUI-based operating systems every programmer has been forced to learn at least the fundamentals of GP because any program they write must show nice little picture boxes, have nice little buttons and toolbars, have a pretty splash screen, etc etc.
Now granted, some programs utilize graphics more than others, but every program uses some graphics. Next time you turn on your computer start thinking about all of the GP involved in simple, everyday routines - clicking your start bar, the animated folder that appears when you copy a file, that progress bar at the bottom of your window. You'll quickly be amazed at how many GP techniques are utilized within every program you run.
While I could go on for pages about the various aspects of GP, neither you or I want me too. :) So here's the part of GP that this set of tutorials will cover: per-pixel graphic interface routines. Basically, we're going to discuss how to get a picture's pixel information, how to transfer it into a data format we can use, and how to put those pixels back onto the screen once we're done with them. We'll go from the easiest and slowest ways to the fastest and most advanced ways available to you, the common Visual Basic programmer.
What this tutorial will not cover is how to do specific image editing routines (please refer to my source code examples and/or future tutorials for that), how to write graphics-based dlls or ocxs, or how to use DirectX. There are resources for each of these if you are interested; my goal is simply to outline the standard API graphical interface methods.
Anyhow, you get the idea. Onto the tutorials!
Copyright 2002 by Tanner "DemonSpectre" Helland. This article may not be reproduced in any form (printed or electronic) without prior written consent from the author. This site may, however, be hyperlinked on the world wide web without permission from the author.
This programming source code is provided "as is". In no event shall the author or any of his affiliates be liable for any consequential, special, incidental or indirect damages of any kind arising out of the delivery, performance or use of this source code, to the maximum extent permitted by applicable law. While the source code has been developed with great care, it is not possible to warrant that it is error free. This source code is not designed or intended to be used in any activity that may cause personal injury, death or any other severe damage or loss.
Please contact
tannerhelland@hotmail.com with feedback and questions regarding this tutorial.