디시인사이드 갤러리

갤러리 이슈박스, 최근방문 갤러리

갤러리 본문 영역

형님들 불쌍한 아해 하나 구원해주세요 API 프로그래밍질문

살려줘(110.35) 2011.06.12 20:16:07
조회 179 추천 0 댓글 15

지금 팩맨 만드는중인데요 미로를 구현하는부분에서 앞에 배열주는법은 알겠는데

콜백이랑 드로우 함수에서 뭐라고 줘야 0과 1을 구분해서 적용시킬 수 있을지 모르겠어요

제발 고수형님들 살려주세요 저 F받으면 졸업못해요 ㅠ.ㅠ

#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <gl/gl.h>
#include <gl/glu.h>

#define IDT_TIMER 1

// global variables
char *szClassName = "Computer Graphics";

HWND MyWND = 0;

HDC MyDC;
HGLRC MyRC;

LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );

bool bSetupPixelFormat(void);
void Resize(const int cx, const int cy);
void DrawScene(void);

void DoColide(void);

-----------------------------------------------------------------------------------

bool maze[10][10] = {
{ 1, 0, 1, 1, 1, 1, 1, 1, 1, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 1, 1, 1, 1, 1, 1, 1, 0, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 1, 1, 1, 1, 1, 1, 1, 0, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 0, 1, 1, 1, 1, 1, 1, 1, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 1, 1, 1, 1, 1, 1, 1, 0, 1 }};

 

--------------------------------------------------------------------------------------

 

const int numRect = 2;
float centerPos[numRect][2] = {{0.1f, 0.1f}, {0.0f, 0.0f}};
float moveDirection[numRect][2] = {{0.05f, 0.0}, {0.0f, 0.05f}};

//void DrawScore(float posX, float posY);


//bool DoColide (float left, float bottom, float right, float top);
//bool DoColide (float centerX, float centerY);

//float centerPos[2] = {0.0f, 0.0f};
//float moveDirection[2] = {0.0f, 0.05f};

/*
* WinMain
*/
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE, LPSTR, int nShowCmd )
{
 // Registers the window class
 WNDCLASS wc;

 wc.style   = CS_HREDRAW | CS_VREDRAW;
 wc.lpfnWndProc  = (WNDPROC)WndProc;
 wc.cbClsExtra  = 0;
 wc.cbWndExtra  = 0;
 wc.hInstance  = hInstance;
 wc.hIcon   = LoadIcon( hInstance, IDI_APPLICATION );
 wc.hCursor   = LoadCursor( 0, IDC_ARROW );
 wc.hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH );
 wc.lpszMenuName  = NULL;
 wc.lpszClassName = szClassName;

 RegisterClass(&wc);

 // Create the main window
 MyWND = CreateWindow( szClassName,
  "Simple OpenGL Example",
  WS_OVERLAPPEDWINDOW,
  CW_USEDEFAULT,
  CW_USEDEFAULT,
  CW_USEDEFAULT,
  CW_USEDEFAULT,
  0,
  0,
  hInstance,
  0 );

 // Make sure that window was created
 if( !MyWND )
  return false;

 ShowWindow( MyWND, nShowCmd );
 UpdateWindow( MyWND );

 // Main message loop
 MSG msg;
 while( GetMessage( &msg, 0, 0, 0 ) )
 {
  TranslateMessage( &msg );
  DispatchMessage (&msg );
 }

 UnregisterClass( szClassName, wc.hInstance );

 return msg.wParam;
}


/*
* WndProc: to process messages for the main window
*/
LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
 RECT rect;

 switch( msg )
 {
 case WM_CREATE:
  // Initialize for the OpenGL rendering
  MyDC = GetDC(hWnd);
  if( !bSetupPixelFormat() )
   PostQuitMessage (0);

  MyRC = wglCreateContext(MyDC);
  wglMakeCurrent(MyDC, MyRC);

  SetTimer(hWnd, IDT_TIMER, 100, NULL);

  SelectObject( MyDC, GetStockObject(SYSTEM_FONT) );
  wglUseFontBitmaps( MyDC, 0, 255, 1000 );
  glListBase( 1000 );

 // InitStage();

  break;

 case WM_SIZE:
  GetClientRect(hWnd, &rect);
  Resize(rect.right, rect.bottom);

  InvalidateRect(hWnd, NULL, FALSE);

  break;

 case WM_DESTROY:
  // Destroy all about OpenGL
  if( MyRC )
   wglDeleteContext(MyRC);

  if( MyDC )
   ReleaseDC(hWnd, MyDC);

  KillTimer(hWnd, IDT_TIMER);

  glDeleteLists( 1000, 255 );

  PostQuitMessage(0);
  break;

 case WM_PAINT:
  DrawScene();
  ValidateRect(hWnd, NULL);
  break;

 case WM_TIMER:
  switch(wParam){
   case IDT_TIMER:
   /*
   float centerX = centerPos[0] + moveDirection[0];
    float centerY = centerPos[1] + moveDirection[1];

    if(!DoColide( centerX-0.1f, centerY-0.1f, centerX+0.1f, centerY+0.1f)){
     centerPos[0] += moveDirection[0];
     centerPos[1] += moveDirection[1];
     InvalidateRect(hWnd, NULL, false);
    }*/
    DoColide();
    InvalidateRect(hWnd, NULL, false);
    break;
  }
 break;

 case WM_KEYDOWN:
  /*
  if(wParam == VK_LEFT){
   if(!DoColide(centerPos[0]-0.2f, centerPos[1])){
    centerPos[0] -= 0.2f;
    InvalidateRect(hWnd, NULL, false);
   } 
  
  }
  else if(wParam == VK_RIGHT){
   if(!DoColide(centerPos[0]+0.2f, centerPos[1])){
    centerPos[0] += 0.2f;
    InvalidateRect(hWnd, NULL, false);
   }
  }
  
  else if(wParam == VK_UP){
   if(!DoColide(centerPos[0], centerPos[1]-0.2f)){
    centerPos[1] += 0.2f;
    InvalidateRect(hWnd, NULL, false);
   }
  }


  else if(wParam == VK_DOWN){
   if(!DoColide(centerPos[0], centerPos[1]-0.2f)){
    centerPos[1] -= 0.2f;
    InvalidateRect(hWnd, NULL, false);
   }
  }*/

  if( wParam == VK_ESCAPE )
  {
   DestroyWindow( MyWND );
  }
  break;

 default:
  return DefWindowProc( hWnd, msg, wParam, lParam );
 }

 return 0;
}

/*
* bSetupPixelFormat : to setup the format of pixel for OpenGL
*/
bool bSetupPixelFormat(void)
{
 PIXELFORMATDEOR pfd;
 int pixelformat;

 pfd.nSize= sizeof( PIXELFORMATDEOR );
 pfd.nVersion= 1;
 pfd.dwFlags= PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
 pfd.dwLayerMask= PFD_MAIN_PLANE;
 pfd.iPixelType= PFD_TYPE_RGBA;
 pfd.cColorBits= 24;
 pfd.cDepthBits= 16;
 pfd.cAccumBits= 0;
 pfd.cStencilBits= 0;

 if( (pixelformat= ChoosePixelFormat( MyDC, &pfd ))==0 ) {
  MessageBox( NULL, "ChoosePixelFormat failed", "Error", MB_OK );
  return false;
 }

 if( SetPixelFormat( MyDC, pixelformat, &pfd )==false ) {
  MessageBox( NULL, "SetPixelFormat failed", "Error", MB_OK );
  return false;
 }

 return true;
}

/*
* Resize : to re-initialize
*/
void Resize(const int cx, const int cy)
{
 glMatrixMode( GL_PROJECTION );
 glLoadIdentity();

 glViewport( 0, 0, cx, cy );

 // 3D orthographic viewing
 if( cx <= cy ) {
  float ratio = (float)cy/(float)cx;
  glOrtho( -1.0, 1.0, -ratio, ratio, -1.0, 1.0 );
 }
 else {
  float ratio = (float)cx/(float)cy;
  glOrtho( -ratio, ratio, -1.0, 1.0, -1.0, 1.0 );
 }

 return;
}   

/*
* DrawScene : to draw a scene
*/

void DrawScene(void)
{
 glEnable(GL_DEPTH_TEST);

 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

 glMatrixMode(GL_MODELVIEW);
 glLoadIdentity();

 

 //DrawScore( 1.1f, 0.8f );


 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);

 glColor3f(0.0f, 0.0f, 0.0f);
 glRectf( centerPos[0][0]-0.1f,centerPos[0][1]-0.1f,centerPos[0][0]+0.1f,centerPos[0][1]+0.1f);
 glRectf( centerPos[1][0]-0.1f,centerPos[1][1]-0.1f,centerPos[1][0]+0.1f,centerPos[1][1]+0.1f);

 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
 
 glColor3f(0.0f, 1.0f, 0.0f);
 glRectf( centerPos[0][0]-0.1f,centerPos[0][1]-0.1f,centerPos[0][0]+0.1f,centerPos[0][1]+0.1f);
 glColor3f(1.0f, 0.0f, 0.0f);
 glRectf( centerPos[1][0]-0.1f,centerPos[1][1]-0.1f,centerPos[1][0]+0.1f,centerPos[1][1]+0.1f);
 
 glColor3f(1.0f, 1.0f, 0.5f);
 glRectf(-1.5f, -1.0f, 1.5f, 1.0f);

 glFlush();
 SwapBuffers(MyDC);

 return;
}
/*
bool DoColide(float centerX, float centerY)
{
 if( centerX >= 1.0f || centerY >= 1.0 || centerX <= -1.0f || centerY <= -1.0f)
  return true;

 return false;
}

bool DoColide(float left, float bottom, float right, float top)
{
 float bound = 1.00001f;
 if( left < -bound || bottom < -bound ){
  moveDirection[0] = -moveDirection[0];
  return true;
 }
 else if(bottom < -bound || top > bound){
  moveDirection[1] = -moveDirection[1];
  return true;
 }
 return false;
}
*/

void DoColide(void)
{
 for(int index=0; index<2; index++){
  float centerX = centerPos[index][0]+moveDirection[index][0];
  float centerY = centerPos[index][1]+moveDirection[index][1];

  float left = centerX-0.1f, right = centerX+ 0.1f;
  float bottom = centerY-0.1f, top = centerY+ 0.1f;

  float bound = 1.00001f;
  if( left < -bound || right > bound ){
   moveDirection[index][0] = -moveDirection[index][0];
   return;
  }
  else if( bottom < -bound || top > bound ){
   moveDirection[index][1] = -moveDirection[index][1];
   return;
  }
  
  centerPos[index][0]+=moveDirection[index][0];
  centerPos[index][1]+=moveDirection[index][1];
 }
 return;
}

/*
void DrawScore( float posX, float posy )
{
 char str[256];
 sprintf_s( str, "Score: %2d", num_items );

 glRasterPos2f( posX, posY );
 glCallLists( strlen(str), GL_UNSIGNED_BYTE, str );

 glColor3f( 0.75f, 0.75f, 0.75f );
 glRectf( posX-0.02f, posY-0.02f, posX+0.23f, posY+0.05f );

 return;
}
*/

추천 비추천

0

고정닉 0

0

댓글 영역

전체 댓글 0
본문 보기

하단 갤러리 리스트 영역

왼쪽 컨텐츠 영역

갤러리 리스트 영역

갤러리 리스트
번호 제목 글쓴이 작성일 조회 추천
설문 끝까지 다 본 걸 후회하게 만든 용두사미 드라마는? 운영자 25/07/07 - -
338701 matlab 허세용 언어아님? [1] ㅁㄴㅇㄴ(59.11) 12.11.25 81 0
338700 자꾸 책추천 책추천 그러는데 책사는법 알려준다 ㅁㄴㅇㄴ(59.11) 12.11.25 46 0
338699 이정도면 선정리 甲아님? [3] ㅇㅇㅇ(1.209) 12.11.25 137 0
338698 vc++만 쓰다가 오랜만에 이클립스 최신판 써본 소감.txt [5] 김주갤(125.177) 12.11.25 114 0
338697 아냐 확실히 물 쓰레기된건 사실 [6] 김주갤(125.177) 12.11.25 138 0
338696 HTML5 책 추천좀 해주세요 [5] 네로시엔갤로그로 이동합니다. 12.11.25 160 0
338695 아! 내가 해냈다! [4] appllee갤로그로 이동합니다. 12.11.25 98 0
338694 확실히 프갤 많이 바꼈다 [3] 김주갤(125.177) 12.11.25 95 0
338693 매트랩은 도대체 어따 써먹나염 [2] 에루스(223.33) 12.11.25 98 0
338692 xp에 이클립스 깔았는데 괄호 찾기가 안된다;;;;;;;;;; 으아아아악(125.177) 12.11.25 99 0
338690 여자 음부에서 식초냄새날까? 이쁜 메이크업 뒤어 숨겨저있는 공포네 [1] Kyle(220.244) 12.11.25 341 0
338689 dc차단기를 만들껀데 aa2(211.244) 12.11.25 37 0
338688 프로그래밍 잘하게되고싶다 티버애니갤로그로 이동합니다. 12.11.25 59 0
338687 Kyle's Quest란 게임이 있었지 에어로홍갤로그로 이동합니다. 12.11.25 66 0
338686 왜 내 도메인은 www. 붙여야 되는거임 [4] appllee갤로그로 이동합니다. 12.11.25 105 0
338685 페이스북 사용할때 불편했던 단점같은것좀 말해주라 [3] 아이디(121.176) 12.11.25 80 0
338682 게임핵 만드려면 어느정도 실력이여야되나요? [1] Coffee갤로그로 이동합니다. 12.11.25 162 0
338681 천재 프로그래머라하면 어떤게 천재임? [7] r(175.192) 12.11.25 450 0
338672 1년차 지방 이직 할때 단가가 얼마정도인가요? 3424(121.183) 12.11.25 49 0
338669 1990년대 초부터 시작해서 작금에 이르기까지 이럴수가! [2] 때릴꺼야?(116.40) 12.11.25 110 0
338668 c언어 초보인데 이것좀 알려주세요 초보(175.206) 12.11.25 79 0
338667 리버싱 초고수가 될거다 리버싱갤로그로 이동합니다. 12.11.25 69 0
338666 지금 전문학교 다니는중인데 후회된다... [3] ㅁㄴㅇ(119.82) 12.11.25 210 0
338664 소켓+MFC로 2D 축구게임 만드려고 하는데 어떨거같냐? [5] ㅁㄴㅇ(119.82) 12.11.25 142 0
338663 니네 포탈건 있으면 뭐할거냐 [5] (59.14) 12.11.25 146 1
338662 pc용 게임 개발하면 어떻게팜? [4] 티버애니갤로그로 이동합니다. 12.11.25 130 0
338660 세그먼트 오류 어디서 발생한지 알수있는법 있나여? [1] (220.94) 12.11.25 73 0
338657 소켓통신에서 멀티플렉싱이랑 멀티스레드중 속도 어느게 빠르나요 [1] c(121.145) 12.11.25 115 0
338656 2차원배열에 쓰기좋은 반복문 없음? appllee갤로그로 이동합니다. 12.11.25 67 0
338654 2D 개발엔진 찾아보니 [14] 뉴비(223.33) 12.11.24 230 0
338653 에휴..... ㅇ.갤로그로 이동합니다. 12.11.24 30 0
338651 내 고추를 스스로빨면 그게 근친상간임 아님 게이임? [5] sxbxb(220.244) 12.11.24 499 0
338650 레노미냐야, 내가 언제 너를 무시했냐? [2] Kyle(220.244) 12.11.24 61 0
338649 근데 드립 아니고 실제로 RPG만들기로 만든 게임으로 돈 번 놈 있는데 [4] 영꼰이갤로그로 이동합니다. 12.11.24 246 0
338647 getAverage()함수 템플릿 작성 문제입니다. 도와줘요. 뽀로뤼갤로그로 이동합니다. 12.11.24 53 0
338646 웹에서 간단한 C 코드 컴파일하고 빌드된거 다운 받을 수 있는 곳 없음? [3] 수노구(175.112) 12.11.24 80 0
338645 근데 게임회사 프로그래머로 들어가는 놈들은 포트폴리오 낼 때 [2] 영꼰이갤로그로 이동합니다. 12.11.24 207 0
338644 형들 과제좀 제발 ㅠㅠ [4] 난바빠(121.148) 12.11.24 217 0
338643 RPG 메이커 진지하게 작업하면 블리저드 가능함? [10] Kyle(220.244) 12.11.24 220 0
338642 형님들 진지하게 해킹이랑 리버싱에 관해서 물어보는건데 [6] 프갤(180.66) 12.11.24 180 0
338638 int 변환형 cool 내가붙인이름 (int a) 매개변수 << 이게 먼 [12] 상상(175.123) 12.11.24 63 0
338637 어셈블리어 간단한거 하나만 질문 [2] 해킨(175.112) 12.11.24 80 0
338636 앙망글 2탄 간다. rlatifkenqkq(119.198) 12.11.24 45 0
338634 printf 질문좀 ㅇㅇ [2] rlatifkenqkq(119.198) 12.11.24 59 0
338633 프로그래밍에 대한 흥미가 떨어졌다 [3] ㅁㄴㅇ(119.82) 12.11.24 91 0
338632 프갤러들아 게임 질문좀 [25] 뉴비(223.33) 12.11.24 187 1
338631 c 레포트 만들려면 얼마줘야대나여? [8] (211.234) 12.11.24 96 0
338630 횽들 JSP는 편집기 뭐써? [24] aaa(118.36) 12.11.24 241 0
338629 어떤 분야에서도 성공하는 사람이 되는법 ㅎㅎㅎ(58.233) 12.11.24 62 0
338628 형들 군대 휴가나온 군인이야 .. 몇가지 물어볼게있어 콤티비갤로그로 이동합니다. 12.11.24 55 0
뉴스 ‘펜싱’ 오상욱, 日 모델 열애설에 침묵…“애인 있냐” 질문에 보인 반응 디시트렌드 07.07
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

뉴스

디시미디어

디시이슈

1/2