I have a BIG Problem...

Started by
6 comments, last by Protricity 22 years, 10 months ago
I''ve been programming for a few years and got good at simple 2D games, so I decided to take on a big game project, I made a Space Fighting game in 2D using nothing but lines and pixels, the graphics/physics are great, I love what it has become and so on.. The Problem is, I used a simple GDI interface for borland C++ that allows me to draw lines, pixels, squares, and circles. The Game draws around 5000 lines a second and requires a Pentium 800Mhz processor to run at full speed In other words, the GUI is waaaaayyy to slow in drawing the lines and pixels and I suspect it is using absolutely no Hardware accelleration. My game is nearly complete and looks great, but is way to laggy and slow on high end computers and is terrible on slower ones SO, I tried using DirectX and OpenGL''s interfaces to allow faster graphics drawing, but I cant find ANY documentation on how to draw lines and pixels. What I need is a simple interface that initializes a window/surface and allows me to draw on it with something like a simple line() or putpixel() command. It must use Hardware support or whatever to make these simple commands as fast as possible and then I''ll move my game over to this GDI and then it will really rock! If anyone can help me find such an GDI I would most appreciate it seeing that all my work would otherwise go to waste and every programmer knows HOW MUCH ThAT SUCKS!! If you could contact me on ICQ with a sugestion you will become my new best buddy!
Advertisement
Well, I dont have ICQ so I suppose I am not going to be your best buddy, but OpenGL and DirectX both allow you to draw lines and points....

In D3D you use D3DPT_POINTLIST or D3DPT_LINELIST in the primitive type parameter of the call to drawprimitive. In OGL you call Begin with GL_LINES or GL_POINTS as a parameter.
Thx for the reply!
I already figured that one out, but the line command requires 3 coordiates per point (X,Y,Z) and is being drawn in a 3D environment. My game is set up in 640x480 mode and uses commands like line(20,20,200,200) the OpenGL commands use the 1.0f stuff.
What I need is a Hardware based function that draws a line the old way - by pixels.
Again, thx for any sugesstions.
Are you actually drawing straight onto a GDI surface? The fastest way to do drawing under windows is to create your own buffer, do ALL your drawing on this buffer, and when you want to send it to the screen, copy it over to a DIB, and have the BLT to the screen. This can be VERY fast.

Just a thought,
Andy
Yeah, I was thinking about that,
but I was afraid it would be too slow.
What is the best way to make your own buffer and write on it?
Is there any documentation for this?
Guess I just need to go read all the OpenGL and DirectX docs, right

In general, for what I am trying, which is better? OpenGL or DirectX?
If you use DirectDraw, you have to write your own line and pixel functions (not hard, you can just use one of the many algorithms out there). But it will be much faster that GDI. And, you definately need to use some sort of off-screen buffer. Drawing directly to the screen is absurd since you will be able to see the frame as it is drawn (which makes it look like it''s flickering). The best way to learn this stuff is from a book. You can try the documentation, but I''d recommend getting a book like Tricks of the Windows Game Programming Gurus. If you read that, you can make a nice fast-running professional quality game on your own. Remember your game isn''t a simple office application, so you need something a little more powerful. Especially since your using direct lines and pixels instead of bitmaps. But trust me, a book is a lot better than looking through documentation.
For 2D graphics I''d suggest just writing your own line and pixel plotting functions and use simple DirectDraw surfaces to handle the double buffering.

This would allow you to write the functions to use the same interface as what you''re currently using. The main bottleneck is probably your use of the GDI. You might actually be able to achieve respectable results without using DirectX or OpenGL at all. If you create a memory buffer and write your own graphics functions to write to that buffer rather than using the GDI, you''d probably notice a hugh increase in speed.

There''s probably dozens of sources on the web that have line drawing algorithms (probably on this site if you look around a bit). Search for "Bresenham line drawing" in Google.
Yeah, that would be exactly what I need, but on this site and others, I could never find good documentation on how to do any of that. I know how to make a line from pixels and such, but I cant find any interfaces that allow me to do such a simple thing. I recently found out that I could use OpenGL to draw a line using glVertex2f( x,y ); but I cant find any documentation on how to impliment that function or set up the perspective or anything. Guess I better just go buy some books and read them

This topic is closed to new replies.

Advertisement