Some C graphics stuff

Deeko

Lifer
Jun 16, 2000
30,213
12
81
I just got Borland Turbo C 2.01 so I could make some DOS graphics prorams. Anyway, I have the screen erasing(cleardevice()) each time through the main loop, and then everything redrawing, if there is a change. But it looks horrible. Back in Basic, I used to do this to avoid that:

DO
CLS
SOME OTHER CRAP
PUT(X,Y), image
PCOPY 1,0
LOOP

Pcopy set like a second page so that transitions were smooth...you didn't see the CLS'ing, you just saw the final product...is there anything like that I can do with graphics.h?
 

nd

Golden Member
Oct 9, 1999
1,690
0
0
Er.. clearing the screen everytime you want to update the graphics is a Very Bad Thing. The flicker would be terrible.

The thing you're talking about there is just storing a virtual copy of the screen in memory that you use to manipulate. When you are done manipulating the virtual screen, you copy (flip) it to the physical screen device.

I'm not too familiar with graphics.h, but I imagine it's similar to graph.tpu from Turbo Pascal.

In any case, I don't see a reason why you would want to clear the screen so often in the first place.
 

Deeko

Lifer
Jun 16, 2000
30,213
12
81
I know it's bad, but it's the only way I've figured out so far to do it. I just started working with C graphics a few days ago anyway. Is there a better way to update the objects on the screen? For instance, the one is a little space ship type thing, it is made up of a few simple polygons, ellipses and lines, so the only way to move all that stuff is to clear the screen, at least as far as I know. If there is no other way to do it, is it possible to do that page flip in C? Doing that does completely elliminate the flicker. Thanx.
 

nd

Golden Member
Oct 9, 1999
1,690
0
0
Well, you can just store a virtual screen yourself with an array of unsigned char's.. and use memcpy() to the graphics buffer (which you'd have to get from your graphics library, but I don't know the specifics).

Realize that you dont have to update the ENTIRE screen everytime you do something. You might be better off just clearing the space ship, and redrawing that (rather than everything) (hint: redraw the space ship with all black, or whatever the background it is for a cheap hack).

I'm by no means an expert in graphics coding, I am very much amateur, but I know the basics.
 

Deeko

Lifer
Jun 16, 2000
30,213
12
81
That's what I used to do back in Basic before I learned the Pcopy trick(which works better), but I had forgot about it. The first thing you said totally confused me :) so I'll stick to trying the second suggestion. Thanx
 

Deeko

Lifer
Jun 16, 2000
30,213
12
81
Well, I did that, and it works ok, but the old basic trick still looked better. I figured out how to do part of it, you have to run setactivepage(1) which sets the page you write to to 1, and setvisualpage(0), which sets the page you see to page 0. Problem is, I can't figure out how to copy page 1 to page 0, which would complete it. Anyknow know?
 

chiwawa626

Lifer
Aug 15, 2000
12,013
0
0
damn, we did this stuff last year in C++ (highschool class)
it got pretty entertaining.
Look at the help file for some more info they have lots of good sample codes in the help
 

chiwawa626

Lifer
Aug 15, 2000
12,013
0
0
instead of cleardevice(); u can just make a function call clear, and have it draw a giant black square, and that would be done a lot faster
 

Deeko

Lifer
Jun 16, 2000
30,213
12
81
Yea, I thought of that too. I did that, and it was better. But it still flickered when things were moving....so I have it draw a little black box over whatever it is clearing....here's my clear function

void objclear(int x, int y, int xsize, int ysize)
{
setcolor(BLACK);
setfillstyle(SOLID_FILL, BLACK);
bar(x, y, (x + xsize), (y + ysize));
}

it works, but it still flickers...argh there has to be a way to copy the two pages...if it can be done in basic, it almost has to be able to be done in C....I would just have to have it write to page 1, and then copy it to page 0 after it redraws, so u would never see the black box...anyone know how?
 

chiwawa626

Lifer
Aug 15, 2000
12,013
0
0
theres a way to stop the flickers, someone in my class did it, they used arrays and all this crazy stuff, just for a game of pong