這是在mac上運(yùn)行的第一個(gè)openGL程序,代碼來自《計(jì)算機(jī)圖形學(xué)(第四版)Computer Graphics with OpenGL》第三章,接口已經(jīng)過時(shí)了,但剛接觸,只能將就著用了:
//// main.cpp// OpenGLTest//// Created by Rick on 2017/3/6.// Copyright ? 2017年 Rick. All rights reserved.//#include <iostream>#include <GLUT/GLUT.h>#include <stdio.h>#include <stdlib.h>#include <math.h>void init(void){ glClearColor(1.0, 1.0, 1.0, 1.0); glMatrixMode(GL_PROJECTION); gluOrtho2D(0.0, 200.0, 0.0, 150.0);}void lineSegment(void){ glClear(GL_COLOR_BUFFER_BIT); glColor3f(0.0, 0.4, 0.2); glBegin(GL_LINES); glVertex2i(180, 15); glVertex2i(10, 145); glEnd(); glFlush();}int main(int argc, char ** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowPosition(50, 100); glutInitWindowSize(400, 300); glutCreateWindow("An Example"); init(); glutDisplayFunc(lineSegment); glutMainLoop();}期間遇到的問題:xcode自動(dòng)生成的c++代碼int main(int argc, char ** argv)中argv前加了const,會(huì)報(bào)錯(cuò) no matching function to call “glutInit”, 把const去掉,讓glutInit能修改argv就行。之后編譯仍舊會(huì)出現(xiàn)問題,報(bào)了是個(gè)錯(cuò)誤,這個(gè)是因?yàn)闆]有鏈接到GLUT的framework,加入相關(guān)frameWord就行了: 
 最終結(jié)果: 
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注