作者onionys (.)
看板MacDev
標題[問題] 用c++練習寫OpenGL程式時出錯...
時間Sat Nov 13 22:26:53 2010
最近在試著學OpenGL,用的是C++。
使用的是Xcode。
加了兩個framework:
OpenGL.framework 和 GLUT.framework
然後參考這個網頁的教學:
http://janusbooks.myweb.hinet.net/
寫了以下的程式碼:
#include <iostream>
#include <GLUT/glut.h>
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <OpenGL/glext.h>
using namespace std;
{有點長就放在最後面...}
--
但是神奇的是build過了,也產生了一個執行擋。
但是在run的時候什麼事都沒發生,而在Debugger Console裡出現了這一個錯誤訊息:
NSSoftLinking - The function 'CGLSetOption' can't be found in
the OpenGL framework.
去查Apple的網頁的時候有看到這麼一個描述:
======================================================
CGLSetOption
Sets the value of a global option.
(Deprecated. Use CGLSetGlobalOption instead.)
CGLError CGLSetOption (
CGLGlobalOption pname,
GLint param
);
========================================================
想問一下有沒有什麼解決方法....
人生的第一個openGL就跌股....Orz...
=============程式碼分隔線,感謝教學頁網==================
#include <iostream>
#include <GLUT/glut.h>
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <OpenGL/glext.h>
using namespace std;
int WinNumber;
void OnDraw(void){
printf("OnDraw\n");
glClearColor(0.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0, 0.0, 1.0);
glRectf(-25, -25, 25, 25);
glFlush();
}
void OnSize(int w, int h){
printf("OnSize\n");
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-50, 50, -50, 50, -50.0, 50.0);
glMatrixMode(GL_MODELVIEW);
}
void OnKey(unsigned char key, int x, int y){
printf("key = %x x=%d y=%d\n",key,x,y);
switch (key) {
case 27:
glutDestroyWindow(WinNumber);
exit(0);
break;
}
}
void OnMouse(int button, int state, int x, int y){
printf("button = %d, state = %d, (%d, %d)\n",button,state,x,y);
}
int main (int argc, char** argv) {
glutInitDisplayMode(GLUT_RGB);
glutInitWindowSize(300, 300);
glutInitWindowPosition(50, 50);
WinNumber = glutCreateWindow("Base");
glutReshapeFunc(OnSize );
glutDisplayFunc(OnDraw );
glutKeyboardFunc(OnKey);
glutMouseFunc(OnMouse);
glutMainLoop();
return 0;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 219.84.125.162
1F:→ onionys:順便問一下,有沒有什麼推薦的教材? 11/13 22:30
2F:→ zonble:在 main() 的第一行 11/14 00:37
3F:→ zonble:加上 glutInit(&argc, argv); 11/14 00:37
4F:→ onionys:原來是我少打了第一行...囧...眼殘 11/14 02:00
5F:→ onionys:感謝解惑,不然我還在和google以及說明文件奮戰...orz.. 11/14 02:01
7F:→ zonble:其實最近 Jeff LaMarche 還有一系列 OpenGL ES 的文章 11/15 15:47
8F:→ zonble:直接去看上面連結的 blog ,今年十月到十一月的文章 11/15 15:47