色が変わる四角形を描画するプログラムを作成する必要があります。このプログラムは、白い背景、256x256 ピクセルの寸法、左上の頂点座標 (x, y) = (30, 226) および右下隅の座標 (x, y) = (226 , 30) の赤い正方形のウィンドウを描画します。 )。キー 'a' (キーコード = 97) を押すと、四角形が青色でくっつくはずです。「v」キー (キーコード = 118) を押すと、正方形が赤に戻ります。ESC キー (キーコード = 27) を押すと、プログラムが終了します。
-- ログがあります...
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 __imp____glutInitWithExit@12 referenced in function _glutInit_ATEXIT_HACK@8
square.obj : error LNK2019: unresolved external symbol __imp____glutCreateWindowWithExit@8 referenced in function _glutCreateWindow_ATEXIT_HACK@4
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();
}