打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
在xcode上搭建OpenGL3.x运行景象,上海软件开发|上海软件开发公司|软件定制|ERP开发|IT咨询服务

在xcode上搭建OpenGL3.x运行景象

2014年2月17日  作者:Admin

比来开端进修OpenGL,网上的教程太没体系,我又是零根蒂根基,于是筹算照着红宝书《OpenGL编程指南(第七版)》来进修。


于是在Mac上搭建一下Demo景象。斗劲便利的是,OS X上已经装了OpenGL 3.x所以很是简单。


起首,在xcode上建树os x的command line,即hello world。


然后,把以下两个库经由过程add files添加到里:


/System/Library/Frameworks/OpenGL.framework


/System/Library/Frameworks/GLUT.framework


前者就是OpenGL 3.x;后者是OpenGL的界面和交互库,因为OpenGL只负责策画,并没有显示功能。


重视,GLUT库已经过期,os x在10.9版本已经弃用,改成什么我还不知道。


接下来,在main.cpp里include以下头文件:


#include <OpenGL/gl.h>


#include <OpenGL/glu.h>


#include <GLUT/glut.h>


最后,把下面的代码贴到main.cpp里编译运行即可


 



void display(void)
{
/* clear all pixels */
glClear (GL_COLOR_BUFFER_BIT);

/* draw white polygon (rectangle) with corners at
* (0.25, 0.25, 0.0) and (0.75, 0.75, 0.0)
*/
glColor3f (1.0, 1.0, 1.0);
glBegin(GL_POLYGON);

glVertex3f (0.25, 0.25, 0.0);
glVertex3f (0.75, 0.25, 0.0);
glVertex3f (0.75, 0.75, 0.0);
glVertex3f (0.25, 0.75, 0.0);

glEnd();

/* don""t wait!
* start processing buffered OpenGL routines
*/
glFlush ();
}

void init (void)
{
/* clearing color */
glClearColor (0.0, 0.0, 0.0, 0.0);

/* initialize viewing values */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
}

/*
* Declare initial window size, position, and display mode
* (single buffer and RGBA). Open window with "hello"
* in its title bar. Call initialization routines.
* Register callback function to display graphics.
* Enter main loop and process events.
*/
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (250, 250);
glutInitWindowPosition (100, 100);
glutCreateWindow ("hello");
init ();
glutDisplayFunc(display);
glutMainLoop();
return 0; /* ANSI C requires main to return int. */
}


运行后,号令行窗口会显示一个白色的方块如图:



OK,开端深切进修吧!

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
10 《高效学习OpenGL》之Hello OpenGl
opengl矩阵变换代码举例
fedora23 安装OpenGL
如何配置OpenGL库详解
OpenGL VS2008 环境配置
Win8+VS2012配置OpenGL SuperBible的环境
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服