Chat on IRC |
Newbie Graphics C++
Posted by gbyte222 [send private reply] at April 26, 2002, 05:52:11 PM
I want to know how to program 2d graphics without using any other program besides my compiler. ex. no DirectX or DirectDraw. Please include syntax. I have been trying for a while to find out, but haven't had any luck.
Thanx
Posted by CodeRed [send private reply] at April 26, 2002, 06:05:33 PM
You could either use modeX or mode13h, for a beginner I suggest 13h because modeX uses multiple pages and double/triple buffers (the way that it is implemented is hard to get used to) VGA Mode13h is 320x200x256, if you ask nicely I'll look through my old floppy disks and try to find the old 13HGraphics library I wrote.
Posted by Psion [send private reply] at April 26, 2002, 06:42:15 PM
DirectX and DirectDraw are not programs, and I would like to hear what reason you have for not wanting to use them. I doubt it's a good one.
Posted by gbyte222 [send private reply] at April 26, 2002, 07:31:20 PM
psion
i do not want to use them because i do not understand how to use them
Posted by CodeRed [send private reply] at April 26, 2002, 08:11:09 PM
It may be harder to learn to use 13h than directx...
Posted by CodeRed [send private reply] at April 26, 2002, 08:17:58 PM
Here are some of the functions you will need, compile them into a class or whatever you want yourself, I don't have time:
//wait for verticle retrace period void wtsync(void) { asm mov dx,3DAh WaitVR1: asm in al,dx asm test al,8 asm jne WaitVR1 WaitVR2: asm in al,dx asm test al,8 asm je WaitVR2 } //Set mode (pass 0x0013 for 13h, 3 for standard DOS) void setmode(int mode) { asm mov ax,mode asm int 10h } //Draw a pixel of color (color) at coordinates (x,y) //You can pass integers to color that correspond to pallette void putpixel(int x,int y,char color) { int offs; offs=320*y + x; asm { mov ax,0a000h mov es,ax mov di,offs mov al,color mov [es:di],al } } Thats about all you need, the rest you can extrapolate yourself, if you need help with line/circle algorithms search for bressenham, or just ask me for them
Posted by CodeRed [send private reply] at April 26, 2002, 08:19:50 PM
Oops, that WaitVR2 line label belongs one line down
Posted by Psion [send private reply] at April 26, 2002, 08:27:33 PM
gbyte, you won't get anywhere at that rate. Like CodeRed said, doing these things "manually" will require that you learn assembly, etc., which is harder by far.
Posted by unknown_lamer [send private reply] at April 27, 2002, 07:30:20 PM
Use SDL (libsdl.org). SDL seems easy enough to read (I have a book on it,
but I never read it because I only got it because I know the author...my invisible character "Invisible Bob" was mentioned in the preface too :)
Posted by gian [send private reply] at April 29, 2002, 05:42:19 AM
Yeah, I played with SDL a bit... didn't do anything with it, but it seemed effective.
Posted by unknown_lamer [send private reply] at April 30, 2002, 05:41:15 PM
and it's portable, so people not using windows can (if you wrote the non-graphic parts portable) use it too.
Posted by metamorphic [send private reply] at April 30, 2002, 06:04:04 PM
An alternative to SDL would be Allegro, which is a great graphics programming library. Its really easy to use and is very portable.
For example to small program to blit a bitmap to the screen would be: #include <allegro.h> int main() { allegro_init(); // Initialize Allegro install_keyboard(); // Initialize keyboard routines set_color_depth(16); // Set the color depth set_gfx_mode(GFX_AUTODETECT, 640,480,0,0); // 640 x 480 mode BITMAP *my_pic; //Declare a BITMAP called my_pic PALLETE pal; //Declare a pallete called pal my_pic = load_bitmap("picture.bmp", pal); // Load our picture acquire_screen(); blit(my_pic, screen, 0,0,0,0,640,480);//Draw the whole bitmap to the screen at (0,0) release_screen(); readkey();// Wait untill a key is pressed destroy_bitmap(my_pic);//Release the bitmap data return(0);// Exit with no errors } END_OF_MAIN(); // needed by allegro thats it! that will blit the bitmap "picture.bmp" to the screen in 640 x 480 mode. I dont think even SDL is as easy as that
Posted by CodeRed [send private reply] at April 30, 2002, 06:27:05 PM
Wow, that sucks, using my old 13h library all I had to do was:
#include <13hgraphics.h> void main() { //Load the bitmap; Bitmap bmp1 = loadBMP("Bitmap1.bmp"); //Set the screen mode to 13h setmode(0x0013); //Display the bitmap at (0,0) displayBMP(bmp1,0,0); }
Posted by CodeRed [send private reply] at April 30, 2002, 06:29:06 PM
I know, I know, displayBMP should be a member function of the Bitmap class so you could to this:
bmp1.Display(0,0); Yes, that would be a lot better, but thats not the way I did it.
Posted by RedX [send private reply] at April 30, 2002, 06:30:58 PM
13h sucks compared to 800x600 SVGA, it even suck compared to 640x480 SVGA. And Allegro makes this very easy to do.
RedX
Posted by CodeRed [send private reply] at April 30, 2002, 06:32:25 PM
The only disadvantage of this that I can see over the allegro code is that the bitmap used in mine had to be 256 color (or it would look like crap), I can't remember, but it's possible that it's dimensions had to be divisible by 8, or 16 or something, maybe I fixed that, I can't remember
Posted by CodeRed [send private reply] at April 30, 2002, 06:34:05 PM
I had a primitive SVGA library going too but I abondoned it when I started learning OGL
Posted by metamorphic [send private reply] at May 01, 2002, 05:35:41 AM
codered, im guessing your 13h lib was wrote entirly in ASM. If the whole thing was, it would mean that it would not be portable off the i586 platform, Allegro has ports to many platroms. Also Allegro is designed to be easy on begginers to graphics programming,
Posted by unknown_lamer [send private reply] at May 01, 2002, 08:45:16 AM
Allegro is a good choice too, but displaying an image uses about the same amount of lines in Allegro as SDL. Of course, most of that in SDL is just boilerplate--you have to figure out how many colors you have on screen. Once you get past that, unpacking and displaying images is easy. Of course, I do believe you have to write the image decoders yourself...or you can use something like ImageMagick (libmagick). I don't really know, I haven't really done much in SDL. Of course, you can't do OpenGL with allegro, can you?
Posted by metamorphic [send private reply] at May 01, 2002, 08:48:39 AM
Allegro running on windows boxes uses DX at runtime, it does use OGL but only for linux and PPC/non intel platforms
Posted by CodeRed [send private reply] at May 01, 2002, 10:18:13 AM
"codered, im guessing your 13h lib was wrote entirly in ASM. If the whole thing was, it would mean that it would not be portable off the i586 platform"
Actually no, I don't know asm from a hole in the ground. The 4 or so low level asm functions that I use are all public domain, I didn't make them, I just use them.
Register as a new user | |||||||||||||||||||||||