我希望大家度过一个愉快的一天,我不太相信我的英语,所以对我可能犯的错误感到抱歉。我尝试了各种可能的方法来用c ++启动OpenGL,例如带minGW的Eclipse,带Cygwin的NetBeans以及您可能想到的任何其他组合。我观看了每个视频,阅读了每个教程。之前曾问过这个话题,但那些也帮不了我。
所以,这是我的代码;
/*
* OGL01Shape3D.cpp: 3D Shapes
*/
#include <windows.h> // for MS Windows
#include <GL/freeglut.h> // GLUT, include glu.h and gl.h
/* Global variables */
char title[] = "3D Shapes";
/* Initialize OpenGL Graphics */
void initGL() {
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Set background color to black and opaque
glClearDepth(1.0f); // Set background depth to farthest
glEnable(GL_DEPTH_TEST); // Enable depth testing for z-culling
glDepthFunc(GL_LEQUAL); // Set the type of depth-test
glShadeModel(GL_SMOOTH); // Enable smooth shading
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Nice perspective corrections
}
/* Handler for window-repaint event. Called back when the window first appears and
whenever the window needs to be re-painted. */
void display() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear color and depth buffers
glMatrixMode(GL_MODELVIEW); // To operate on model-view matrix
// Render a color-cube consisting of 6 quads with different colors
glLoadIdentity(); // Reset the model-view matrix
glTranslatef(1.5f, 0.0f, -7.0f); // Move right and into the screen
glBegin(GL_QUADS); // Begin drawing the color cube with 6 quads
// Top face (y = 1.0f)
// Define vertices in counter-clockwise (CCW) order with normal pointing out
glColor3f(0.0f, 1.0f, 0.0f); // Green
glVertex3f( 1.0f, 1.0f, -1.0f);
glVertex3f(-1.0f, 1.0f, -1.0f);
glVertex3f(-1.0f, 1.0f, 1.0f);
glVertex3f( 1.0f, 1.0f, 1.0f);
// Bottom face (y = -1.0f)
glColor3f(1.0f, 0.5f, 0.0f); // Orange
glVertex3f( 1.0f, -1.0f, 1.0f);
glVertex3f(-1.0f, -1.0f, 1.0f);
glVertex3f(-1.0f, -1.0f, -1.0f);
glVertex3f( 1.0f, -1.0f, -1.0f);
// Front face (z = 1.0f)
glColor3f(1.0f, 0.0f, 0.0f); // Red
glVertex3f( 1.0f, 1.0f, 1.0f);
glVertex3f(-1.0f, 1.0f, 1.0f);
glVertex3f(-1.0f, -1.0f, 1.0f);
glVertex3f( 1.0f, -1.0f, 1.0f);
// Back face (z = -1.0f)
glColor3f(1.0f, 1.0f, 0.0f); // Yellow
glVertex3f( 1.0f, -1.0f, -1.0f);
glVertex3f(-1.0f, -1.0f, -1.0f);
glVertex3f(-1.0f, 1.0f, -1.0f);
glVertex3f( 1.0f, 1.0f, -1.0f);
// Left face (x = -1.0f)
glColor3f(0.0f, 0.0f, 1.0f); // Blue
glVertex3f(-1.0f, 1.0f, 1.0f);
glVertex3f(-1.0f, 1.0f, -1.0f);
glVertex3f(-1.0f, -1.0f, -1.0f);
glVertex3f(-1.0f, -1.0f, 1.0f);
// Right face (x = 1.0f)
glColor3f(1.0f, 0.0f, 1.0f); // Magenta
glVertex3f(1.0f, 1.0f, -1.0f);
glVertex3f(1.0f, 1.0f, 1.0f);
glVertex3f(1.0f, -1.0f, 1.0f);
glVertex3f(1.0f, -1.0f, -1.0f);
glEnd(); // End of drawing color-cube
// Render a pyramid consists of 4 triangles
glLoadIdentity(); // Reset the model-view matrix
glTranslatef(-1.5f, 0.0f, -6.0f); // Move left and into the screen
glBegin(GL_TRIANGLES); // Begin drawing the pyramid with 4 triangles
// Front
glColor3f(1.0f, 0.0f, 0.0f); // Red
glVertex3f( 0.0f, 1.0f, 0.0f);
glColor3f(0.0f, 1.0f, 0.0f); // Green
glVertex3f(-1.0f, -1.0f, 1.0f);
glColor3f(0.0f, 0.0f, 1.0f); // Blue
glVertex3f(1.0f, -1.0f, 1.0f);
// Right
glColor3f(1.0f, 0.0f, 0.0f); // Red
glVertex3f(0.0f, 1.0f, 0.0f);
glColor3f(0.0f, 0.0f, 1.0f); // Blue
glVertex3f(1.0f, -1.0f, 1.0f);
glColor3f(0.0f, 1.0f, 0.0f); // Green
glVertex3f(1.0f, -1.0f, -1.0f);
// Back
glColor3f(1.0f, 0.0f, 0.0f); // Red
glVertex3f(0.0f, 1.0f, 0.0f);
glColor3f(0.0f, 1.0f, 0.0f); // Green
glVertex3f(1.0f, -1.0f, -1.0f);
glColor3f(0.0f, 0.0f, 1.0f); // Blue
glVertex3f(-1.0f, -1.0f, -1.0f);
// Left
glColor3f(1.0f,0.0f,0.0f); // Red
glVertex3f( 0.0f, 1.0f, 0.0f);
glColor3f(0.0f,0.0f,1.0f); // Blue
glVertex3f(-1.0f,-1.0f,-1.0f);
glColor3f(0.0f,1.0f,0.0f); // Green
glVertex3f(-1.0f,-1.0f, 1.0f);
glEnd(); // Done drawing the pyramid
glutSwapBuffers(); // Swap the front and back frame buffers (double buffering)
}
/* Handler for window re-size event. Called back when the window first appears and
whenever the window is re-sized with its new width and height */
void reshape(GLsizei width, GLsizei height) { // GLsizei for non-negative integer
// Compute aspect ratio of the new window
if (height == 0) height = 1; // To prevent divide by 0
GLfloat aspect = (GLfloat)width / (GLfloat)height;
// Set the viewport to cover the new window
glViewport(0, 0, width, height);
// Set the aspect ratio of the clipping volume to match the viewport
glMatrixMode(GL_PROJECTION); // To operate on the Projection matrix
glLoadIdentity(); // Reset
// Enable perspective projection with fovy, aspect, zNear and zFar
gluPerspective(45.0f, aspect, 0.1f, 100.0f);
}
/* Main function: GLUT runs as a console application starting at main() */
int main(int argc, char** argv) {
glutInit(&argc, argv); // Initialize GLUT
glutInitDisplayMode(GLUT_DOUBLE); // Enable double buffered mode
glutInitWindowSize(640, 480); // Set the window's initial width & height
glutInitWindowPosition(50, 50); // Position the window's initial top-left corner
glutCreateWindow(title); // Create window with the given title
glutDisplayFunc(display); // Register callback handler for window re-paint event
glutReshapeFunc(reshape); // Register callback handler for window re-size event
initGL(); // Our own OpenGL initialization
glutMainLoop(); // Enter the infinite event-processing loop
return 0;
}
这是我从互联网上找到的示例代码。这些就是我得到的错误,无论我做什么;
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/Cygwin_1-Windows/cppapplication_3.exe
make[2]: Entering directory '/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3'
mkdir -p dist/Debug/Cygwin_1-Windows
g++ -o dist/Debug/Cygwin_1-Windows/cppapplication_3 build/Debug/Cygwin_1-Windows/main.o
build/Debug/Cygwin_1-Windows/main.o: In function `Z6initGLv':
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:12: undefined reference to `_imp__glClearColor@16'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:13: undefined reference to `_imp__glClearDepth@8'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:14: undefined reference to `_imp__glEnable@4'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:15: undefined reference to `_imp__glDepthFunc@4'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:16: undefined reference to `_imp__glShadeModel@4'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:17: undefined reference to `_imp__glHint@8'
build/Debug/Cygwin_1-Windows/main.o: In function `Z7displayv':
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:23: undefined reference to `_imp__glClear@4'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:24: undefined reference to `_imp__glMatrixMode@4'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:27: undefined reference to `_imp__glLoadIdentity@0'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:28: undefined reference to `_imp__glTranslatef@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:30: undefined reference to `_imp__glBegin@4'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:33: undefined reference to `_imp__glColor3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:34: undefined reference to `_imp__glVertex3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:35: undefined reference to `_imp__glVertex3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:36: undefined reference to `_imp__glVertex3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:37: undefined reference to `_imp__glVertex3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:40: undefined reference to `_imp__glColor3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:41: undefined reference to `_imp__glVertex3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:42: undefined reference to `_imp__glVertex3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:43: undefined reference to `_imp__glVertex3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:44: undefined reference to `_imp__glVertex3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:47: undefined reference to `_imp__glColor3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:48: undefined reference to `_imp__glVertex3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:49: undefined reference to `_imp__glVertex3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:50: undefined reference to `_imp__glVertex3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:51: undefined reference to `_imp__glVertex3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:54: undefined reference to `_imp__glColor3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:55: undefined reference to `_imp__glVertex3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:56: undefined reference to `_imp__glVertex3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:57: undefined reference to `_imp__glVertex3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:58: undefined reference to `_imp__glVertex3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:61: undefined reference to `_imp__glColor3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:62: undefined reference to `_imp__glVertex3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:63: undefined reference to `_imp__glVertex3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:64: undefined reference to `_imp__glVertex3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:65: undefined reference to `_imp__glVertex3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:68: undefined reference to `_imp__glColor3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:69: undefined reference to `_imp__glVertex3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:70: undefined reference to `_imp__glVertex3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:71: undefined reference to `_imp__glVertex3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:72: undefined reference to `_imp__glVertex3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:73: undefined reference to `_imp__glEnd@0'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:76: undefined reference to `_imp__glLoadIdentity@0'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:77: undefined reference to `_imp__glTranslatef@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:79: undefined reference to `_imp__glBegin@4'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:81: undefined reference to `_imp__glColor3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:82: undefined reference to `_imp__glVertex3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:83: undefined reference to `_imp__glColor3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:84: undefined reference to `_imp__glVertex3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:85: undefined reference to `_imp__glColor3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:86: undefined reference to `_imp__glVertex3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:89: undefined reference to `_imp__glColor3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:90: undefined reference to `_imp__glVertex3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:91: undefined reference to `_imp__glColor3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:92: undefined reference to `_imp__glVertex3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:93: undefined reference to `_imp__glColor3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:94: undefined reference to `_imp__glVertex3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:97: undefined reference to `_imp__glColor3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:98: undefined reference to `_imp__glVertex3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:99: undefined reference to `_imp__glColor3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:100: undefined reference to `_imp__glVertex3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:101: undefined reference to `_imp__glColor3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:102: undefined reference to `_imp__glVertex3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:105: undefined reference to `_imp__glColor3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:106: undefined reference to `_imp__glVertex3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:107: undefined reference to `_imp__glColor3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:108: undefined reference to `_imp__glVertex3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:109: undefined reference to `_imp__glColor3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:110: undefined reference to `_imp__glVertex3f@12'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:111: undefined reference to `_imp__glEnd@0'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:113: undefined reference to `glutSwapBuffers'
build/Debug/Cygwin_1-Windows/main.o: In function `Z7reshapeii':
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:124: undefined reference to `_imp__glViewport@16'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:127: undefined reference to `_imp__glMatrixMode@4'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:128: undefined reference to `_imp__glLoadIdentity@0'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:130: undefined reference to `gluPerspective@32'
build/Debug/Cygwin_1-Windows/main.o: In function `main':
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:135: undefined reference to `glutInit'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:136: undefined reference to `glutInitDisplayMode'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:137: undefined reference to `glutInitWindowSize'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:138: undefined reference to `glutInitWindowPosition'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:139: undefined reference to `glutCreateWindow'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:140: undefined reference to `glutDisplayFunc'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:141: undefined reference to `glutReshapeFunc'
/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3/main.cpp:143: undefined reference to `glutMainLoop'
collect2: error: ld returned 1 exit status
make[2]: *** [nbproject/Makefile-Debug.mk:63: dist/Debug/Cygwin_1-Windows/cppapplication_3.exe] Error 1
make[2]: Leaving directory '/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3'
make[1]: *** [nbproject/Makefile-Debug.mk:59: .build-conf] Error 2
make[1]: Leaving directory '/cygdrive/c/Users/Yiğit Efe/Documents/NetBeansProjects/CppApplication_3'
make: *** [nbproject/Makefile-impl.mk:40: .build-impl] Error 2
BUİLD FAILED (exit value 2, total time: 1s)
由于无法构建,我没有.exe文件
我们将不胜感激。
编辑:#include GL / glut.h我得到相同的错误