2013-04-25 3 views
-2

색상을 변경하는 사각형을 그려야하는 프로그램을 만들어야합니다. 이 프로그램은 흰색 배경, 256x256 픽셀의 크기, 왼쪽 상단 정점 좌표 (x, y) = (30, 226) 및 오른쪽 하단 좌표 (x, y) = (226, 30). 'a'(키 코드 = 97) 키를 누르면 정사각형이 파란색으로 고정됩니다. 'v'키 (keycode = 118)를 누르면 정사각형이 다시 빨간색으로 바뀝니다. ESC 키 (keycode = 27)를 누르면 프로그램을 종료해야합니다.OpenGL을 사용하는 C++ - 사각형 그리기

- 로그가 있습니다 ...

Build Log  
Build started: 
Project: square, Configuration: Debug|Win32 

Command Lines  
Creating temporary file "c:\Users\TEMP\Documents\Visual Studio 2008\Projects\square\square\Debug\RSP00000544445896.rsp" with contents 
[ 
/OUT:"C:\Users\TEMP\Documents\Visual Studio 2008\Projects\square\Debug\square.exe" /MANIFEST /MANIFESTFILE:"Debug\square.exe.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"C:\Users\TEMP\Documents\Visual Studio 2008\Projects\square\Debug\square.pdb" /DYNAMICBASE /NXCOMPAT /MACHINE:X86 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib 

".\Debug\square.obj" 
] 
Creating command line "link.exe @"c:\Users\TEMP\Documents\Visual Studio 2008\Projects\square\square\Debug\RSP00000544445896.rsp" /NOLOGO /ERRORREPORT:PROMPT" 


Output Window  
Linking... 
square.obj : error LNK2019: unresolved external symbol [email protected] referenced in function [email protected] 
square.obj : error LNK2019: unresolved external symbol [email protected] referenced in function [email protected] 
C:\Users\TEMP\Documents\Visual Studio 2008\Projects\square\Debug\square.exe : fatal error LNK1120: 2 unresolved externals 


Results  
Build log was saved at "file://c:\Users\TEMP\Documents\Visual Studio 2008\Projects\square\square\Debug\BuildLog.htm" 
square - 3 error(s), 0 warning(s) 

코드 :

#include <GL/glut.h> 

// Function callback that is called to manage the keyboard tasks 
float r = 0.0f; 
float g = 0.0f; 
float b = 0.0f; 
void GerenciaTeclado(unsigned char key, int x, int y) 
{ 
    switch (key) { 
    case 'a':// change the actual color to red 
     r = 1.0f; 
     g = 0.0f; 
     b = 0.0f; 
     break; 
    case 'v':// change de color to blue 
     r = 0.0f; 
     g = 0.0f; 
     b = 1.0f; 
     break; 
    case 27:// close the screen 
     exit(0); 
     break; 
    } 
    glutPostRedisplay(); 
} 

// Function callback that is called to draw 
void Desenha(void) 
{ 
    // Clean the window 
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f); 
    glClear(GL_COLOR_BUFFER_BIT); 

    // Initializes the coordinates system 
    glMatrixMode(GL_PROJECTION); 
    glLoadIdentity(); 
    double w = glutGet(GLUT_WINDOW_WIDTH); 
    double h = glutGet(GLUT_WINDOW_HEIGHT); 
    double ar = w/h; 
    glOrtho(-2 * ar, 2 * ar, -2, 2, -1, 1); 

    glMatrixMode(GL_MODELVIEW); 
    glLoadIdentity(); 

    // Draw a square 
    glBegin(GL_QUADS); 
    // Shows that the color is red 
    //  R G B 
    glColor3f(r, g, b); 
    glVertex2f(-1, -1); 
    glVertex2f(1, -1); 
    // Shows that the color is blue 
    glColor3f(0.0f, 0.0f, 1.0f); 
    glVertex2f(1, 1); 
    glVertex2f(-1, 1); 
    glEnd(); 

    glutSwapBuffers(); 
} 

// Main Program 
int main(int argc, char** argv) 
{ 
    glutInit(&argc, argv); 
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); 
    glutInitWindowSize(256,256); 
    glutInitWindowPosition(10,10); 
    glutCreateWindow("Quadrado"); 
    glutDisplayFunc(Desenha); 
    glutKeyboardFunc(GerenciaTeclado); 
    glutMainLoop(); 
} 
+0

언제든지 오류를 게시하십시오. 아무도 파란색으로 추측 할 수 없게됩니다. –

+0

지금 오류 이미지를 추가했습니다 ... 정말 고마워요. – Dreamer

+0

질문에 복사하여 붙여 넣는 것이 더 좋았을 것입니다. 어쨌든 이제는 코드를 컴파일하기 위해 ** 링커 ** 오류가 있다는 것을 알았습니다. 그것은 연결되지 않았습니다. –

답변

1

당신이 과잉 라이브러리와 코드 연결해야 GLUT 뭔가를 구축. Google에 추가 타사 라이브러리와 시각적 스튜디오를 연결하는 방법을 시도해보십시오. 귀하의 경우에는 다른 라이브러리 디렉토리를 추가하고 프로젝트 링커 속성에 추가 종속성 (glut.lib)을 추가해야한다고 생각합니다.