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; y<20; y++){
for(x=0; x<30; 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; y<20; y++){
pos.Y = y;
for(x=0; x<30; 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;
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} },
/* 두 번째 블록
■
■
■
■
■ */
{
{0, 0, 0, 1},
{0, 0, 0, 1},
{0, 0, 0, 1},
{0, 0, 0, 1},
{0, 0, 0, 1} },
이런식인데 저 코드를 어떻게 바꿔야 할까요? .. 제가 스스로해야하는데 이렇게 질문올려서 죄송합니다..