2013-04-25 90 views
-2

我必须制作一个应该绘制改变颜色的正方形的程序。 (x,y)=(30,226)和右下角坐标(x,y)=(226,256)的红色正方形的白色背景,256×256像素的尺寸, 30)。按下键'a'(键码= 97)时,正方形应该保持蓝色。当按下'v'键(键码= 118)时,方块应该回到红色。当按下ESC键(键码= 27)时,程序应该终止。C++与OpenGL - 绘制广场

- 有日志...

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

当你有错时总是发布你的错误。没有人应该能够从蓝色中猜出它。 – 2013-04-25 11:04:04

+0

我已经添加了错误的图像现在...非常感谢。 – Dreamer 2013-04-25 11:14:03

+0

复制并粘贴到问题中会更好。无论如何,现在你发布它,我看到你有**链接器**错误,所以你的代码编译。它没有链接。 – 2013-04-25 11:16:50

回答

1

在建设有你需要你的代码glut库链接GLUT东西。尝试谷歌你如何链接一个视觉工作室与额外的第三方库。在你的情况下,我相信你将需要添加另一个库目录,并在项目链接器属性中添加额外的依赖项(glut.lib)。