더블버퍼링 질문입니다..
무크
질문 제목 : 질문 내용 :
c언어로 시계프로그램을 만들었는데 1/100초씩 tick받아서 갱신해주는 거라 깜빡임이 너무 심하네요..그래서 알아봤더니 더블버퍼링을 쓰면 된다고 하시는데 한번도 들어보거나 본적이 없어서 어떻게 써야할지 난감하네요..검색을하고 공부하려고 해도 api를 몰라서 공부하고 쓰기엔 시간이 너무 촉박해서 염치없이 질문올립니다..#include stdio.h
#include windows.h
#include tchar.h
#include stdlib.h
void printconsolescreen(const int ncurview, handle hconsolebuf[2], lpctstr lpcharacter, coord dwwritecoord);
void updatescreen(int *ncurview, handle hconsolebuf[2]);
void drawrectangle(){
char mark[21][4] = { ☆,★,○,●,◎,◇,◆,□,■,△,▲,▽,▼,◈,▣,♤,♠,♡,♥,♧,♣};
int x,y;
system(cls);
for(y=0; y20; y++){
for(x=0; x30; x++){
printf(%s, mark[rand()%21]);
}
printf(\n);
}
}}
void drawrectanglebuffering(int *ncurview, handle hconsolebuf[2]){
coord pos = {0, 0};
int x,y;
lpctstr mark[21] = { _t(☆),_t(★),_t(○),_t(●),_t(◎),_t(◇),_t(◆),_t(□),_t(■),_t(△),_t(▲),_t(▽),_t(▼),_t(◈),_t(▣),_t(♤),_t(♠),_t(♡),_t(♥),_t(♧),_t(♣)};
for(y=0; y20; y++){
pos.y = y;
for(x=0; x30; x++){
pos.x = 2*x;
printconsolescreen(*ncurview, hconsolebuf, mark[rand()%21], pos);
}
}
updatescreen(ncurview, hconsolebuf);
}
int main(int argc, const char *argv[]){
handle hconsolebuf[2];
int ncurview=0;
bool bflag;
int i=0;
hconsolebuf[0] = createconsolescreenbuffer(generic_read|generic_write, 0, null, console_textmode_buffer, null);
hconsolebuf[1] = createconsolescreenbuffer(generic_read|generic_write, 0, null, console_textmode_buffer, null);
while(i++100){
drawrectanglebuffering(&ncurview, hconsolebuf);
//drawrectangle();
sleep(100);
}
return 0;
}
void printconsolescreen(const int ncurview, handle hconsolebuf[2], lpctstr lpcharacter, coord dwwritecoord)
{
writeconsoleoutputcharacter(hconsolebuf[ncurview], lpcharacter, _tcslen(lpcharacter), dwwritecoord, null);
}
void updatescreen(int *ncurview, handle hconsolebuf[2])
{
setconsoleactivescreenbuffer(hconsolebuf[*ncurview]);
*ncurview = (*ncurview+1)%2;
}인터넷에서 더블버퍼링이라고 올려진 코드를 찾아봤는데요 .. 위에 코드가 나오더라구요제가 출력해주고 싶은건
char blockmodel[10][5][4]=
{
/* 첫 번째 블록
■■■■
■ ■
■ ■
■ ■
■■■■ */
{
{1, 1, 1, 1},
{1, 0, 0, 1},
{1, 0, 0, 1},
{1, 0, 0, 1},
{1, 1, 1, 1} },
/* 두 번째 블록
■
■
■
■
죃sp; ■ */
{
{0, 0, 0, 1},
{0, 0, 0, 1},
{0, 0, 0, 1},
{0, 0, 0, 1},
{0, 0, 0, 1} }, 이런식인데 저 코드를 어떻게 바꿔야 할까요? ..