作者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