OpenGL画简单图形

#include <GL/glut.h>
#pragma comment(linker,"/subsystem:\"windows\" /entry:\"mainCRTStartup\"") 
/*
三角形
GL_TRIANGLES(三个点成一个三角形)
GL_TRIANGLE_STRIP(相邻三点成一个三角形)
GL_TRIANGLE_FAN(同第二个,后2个和第一个成三角形)
四边形
GL_QUADS(四点一个)
GL_QUAD_STRIP(相邻四点一个)
多边形
GL_POLYGON
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
*/
void drawPoint(void)
{
int i;
glColor3f (0.0, 0.0, 1.0);
glPointSize(5);
glBegin(GL_POINTS);
for (i = 0; i < 7; i++)
glVertex2f (0.2 + ((GLfloat) i * 0.1), 0.6);
glEnd ();
}
void drawLines(void)
{
glColor3f(0.0,0.0,1.0);
glLineWidth(5);
glBegin(GL_LINES);
glVertex2f(0.0, 0.0);
glVertex2f(0.25,0.25);
glVertex2f(0.75,0.25);
glVertex2f(0.0,0.0);
glEnd();
}
void drawOneLine(GLfloat a,GLfloat b,GLfloat c,GLfloat d)
{
glBegin(GL_LINES);
glVertex2f(a,b);
glVertex2f(c,d);
glEnd();
}
void drawLineStripple(void)
{
glEnable (GL_LINE_STIPPLE);
glColor3f (0.0, 0.0, 1.0);
glLineStipple (1, 0x0101);  /*  dotted  */
drawOneLine (-0.25, 0.8, -0.75, 0.8);
glLineStipple (1, 0x00FF);  /*  dashed  */
drawOneLine (-0.25, 0.6, -0.75, 0.6);
glLineStipple (1, 0x1C47);  /*  dash/dot/dash  */
drawOneLine (-0.25, 0.4, -0.75, 0.4);
///* in 2nd row, 3 wide lines, each with different stipple */
glLineWidth (5.0);
glLineStipple (1, 0x0101);  /*  dotted  */
drawOneLine (-0.25, 0.2, -0.75, 0.2);
glLineStipple (1, 0x00FF);  /*  dashed  */
drawOneLine (-0.25, 0.0, -0.75, 0.0);
glLineStipple (1, 0x1C47);  /*  dash/dot/dash  */
drawOneLine (-0.25, -0.2, -0.75, -0.2);
glLineWidth (1.0);
///* in 4th row, 6 independent lines with same stipple  */
int i;
for (i = 0; i < 6; i++) {
drawOneLine (0.05 + ((GLfloat) i * 0.01), 0.5,
0.05 + ((GLfloat)(i+1) * 0.01), 0.5);
}
//
///* in 5th row, 1 line, with dash/dot/dash stipple    */
///* and a stipple repeat factor of 5                  */
glLineStipple (5, 0x1C47);  /*  dash/dot/dash  */
drawOneLine (50.0, 25.0, 350.0, 25.0);
glDisable (GL_LINE_STIPPLE);
}
void drawLineStrip()
{
glColor3f (0.0, 0.0, 1.0);
glPointSize(5);
// glBegin(GL_LINE_STRIP);
glBegin(GL_LINE_LOOP);
glVertex2f(0.0,0.0);
glVertex2f(-0.3,-0.5);
glVertex2f(0.3,-0.5);
glEnd ();
}
void myDisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT);
// glRectf(-0.5f, -0.5f, 0.5f, 0.5f);
//设置颜色
glColor3f(1.0,1.0,0.0);
//画出矩形
glBegin(GL_POLYGON);
glVertex3f(0.25,0.25,0.25);
glVertex3f(0.75,0.25,0.0);
glVertex3f(0.75,0.75,0.0);
glVertex3f(0.25,0.75,0.0);
//glVertex3f(0.0,0.5,0.0);
glEnd();
drawPoint();
drawLines();
drawLineStripple();
drawLineStrip();
glFlush();
}
void reshape (int w, int h)
{
// glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
//gluOrtho2D (0.0, (GLdouble) w, 0.0, (GLdouble) h);
// glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
//glOrtho(left, right, bottom, top, near, far)
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowPosition(100, 100);
glutInitWindowSize(400, 400);
glutCreateWindow("第一个OpenGL程序");
//glClearColor (0.0, 1.0, 1.0, 0.0);
glutDisplayFunc(myDisplay);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}

Learn From

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/508713.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

ubuntu下编译OpenGL

安装基本编译环境&#xff1a; sudo apt-get install build-essential 安装Opengl工具箱&#xff1a; sudo apt-get install freeglut3-dev /* main.cpp */ #include <GL/glut.h> #include <stdlib.h> #include <stdio.h> #include "app.h" using …

关于linux的进程和线程

关于linux的进程和线程 http://kenby.iteye.com/blog/1014039 Linux下的多线程编程 http://fanqiang.chinaunix.net/a4/b8/20010811/0905001105.html 线程的最大特点是资源的共享性&#xff0c;但资源共享中的同步问题是多线程编程的难点。linux下提供了多种方式来处理线程…

linux setsockopt函数

功能描述&#xff1a; 获取或者设置与某个套接字关联的选 项。选项可能存在于多层协议中&#xff0c;它们总会出现在最上面的套接字层。当操作套接字选项时&#xff0c;选项位于的层和选项的名称必须给出。为了操作套接字层的选项&#xff0c;应该 将层的值指定为SOL_S…

struct linger

Linux下tcp连接断开的时候调用close()函数&#xff0c;有优雅断开和强制断开两种方式。那么如何设置断开连接的方式呢&#xff1f;是通过设置socket描述符一个linger结构体属性。linger结构体数据结构如下&#xff1a; #include <arpa/inet.h>struct linger {int l_onoff…

几种常见的排序算法

冒泡排序 冒泡排序算法的运作如下: 1、比较相邻的元素。如果第一个比第二个大&#xff0c;就交换他们两个。 2、对每一对相邻元素作同样的工作&#xff0c;从开始第一对到结尾的最后一对。这步做完后&#xff0c;最后的元素会是最大的数。 3、针对所有的元素重复以上的步骤…

linux下调试工具的应用

http://www.ibm.com/developerworks/cn/linux/l-pow-debug/

数据结构--赫夫曼树及其应用

讲解请参考 赫夫曼 ------ 赫夫曼树和赫夫曼编码的存储表示------ typedef struct {unsigned int weight;unsigned int parent,lchild,rchild; }HTNode,*HuffmanTree; typedef char ** HuffmanCode;void HuffmanCoding(HuffmanTree& HT,HuffmanCode & HC,int *w,int …

sqlite C/C++ API

官网&#xff1a;https://sqlite.org/download.html 下载代码安装三步走&#xff1a; ./configure // ./configure --help查看安装参数设置&#xff0c;学习configure的配置&#xff0c;明白安装后include、lib、bin等文件的位置 make make install学习SQL基本语法&#xff0…

线程属性总结

今天面试那哥们问起线程属性&#xff0c;me竟然就说出了一个&#xff0c;囧 学习&#xff1a;http://blog.csdn.net/zsf8701/article/details/7842392 http://blog.csdn.net/jxhnuaa/article/details/3254299 http://blog.sina.com.cn/s/blog_9bd573450101hgdr.html int pthre…

单链表面试经典问题

/************************************************** http://www.cnblogs.com/lifuqing/archive/2011/08/20/List.html http://www.cnblogs.com/wenjiang/p/3310233.html 链表经典问题汇总:http://blog.csdn.net/vividonly/article/details/6673758 链表有关的常见面试题:htt…

Linux SO_KEEPALIVE属性,心跳

对于面向连接的TCP socket,在实际应用中通常都要检测对端是否处于连接中,连接端口分两种情况: 1、连接正常关闭,调用close() shutdown()连接优雅关闭,send与recv立马返回错误,select返回SOCK_ERR; 2、连接的对端异常关闭,比如网络断掉,突然断电. 对于第二种情况,判断连接是否断…

Linux下ARM开发环境搭建

本人的系统环境&#xff1a;Linux ubuntu 3.8.0-35-generic #50-Ubuntu SMP Tue Dec 3 01:25:33 UTC 2013 i686 i686 i686 GNU/Linux 1、安装skyeye sudo apt-get install skyeye s kyeye -h可以看到skyeye的版本号为1.2.5也可以到http://sourceforge.jp/projects/sfnet_skyeye…

cygwin开发环境搭建与apt-cyg的应用

1、Cygwin安装 http://www.cygwin.com/下载安装工具 具体安装过程参照http://jingyan.baidu.com/article/6b97984d83dfe51ca2b0bf0e.html 2、Cygwin一些设置 打开Cygwin终端,右击打开 Options...选项 Text可以设置字体的一些属性,如大小、编码,Locale 选择C, Character set 选择…

CentOS下升级python版本

源码安装python 安装python源码所依赖的工具及依赖的库 yum install -y make gcc gcc-c yum install -y bzip2 bzip2-devel yum install zlib-devel openssl openssl-devel -y yum install -y make xz下载安装python源码 从官方网站或者华为镜像源下载所有需的源码包&#xff0…

linux下confstr与uname函数_获取C库与内核信息

#include <stdio.h> #include <sys/utsname.h> //unameint main(int argc, char **argv[]) {struct utsname u;if (uname(&u) ! -1) {printf("获取当前内核的名称和信息如下\n""sysname:%s\n""nodename:%s\n""release:%s\…

linux下getrlimit与sysconf函数

#include <stdio.h> #include <sys/time.h> #include <sys/resource.h>int main(int argc, char *argv[]) {struct rlimit nofile_rlmt;if (getrlimit(RLIMIT_NOFILE, &nofile_rlmt) ! -1) {printf("获取进程最大能打开的文件描述符个数信息:\n&quo…

Linux下environ环境变量操作函数

#include <stdio.h>int main(int argc,char *argv[],char **envptr) {int i0;for(i0; envptr[i]!NULL; i)printf("%s\n",envptr[i]);return 0; } main函数是程序的入口函数,int main(int argc,char *argv[]); argc是程序参数的个数,argv保存参数 与下边的程…

Linux网络编程--聊天室客户端程序

聊天室客户端程序 #define _GNU_SOURCE 1 #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <assert.h> #include <stdio.h> #include <unistd.h> #include <string.h&…

二叉树学习之二叉查找树

写在前面的话 最近接到几个大学同学研究生毕业不是签华为就是签百度,本人取经得到:操作系统、数据结构与算法、网络编程与数据库是面试中利器。想想自己工作2.5年月薪还不到10K,过着苦逼的码农生活,而他们一出校门就是大放光芒(最起码进入的公司就让人觉得牛逼哄哄的).本人痛定…

二叉树学习之非递归遍历

二叉树递归遍历可谓是学过数据结构的同仁都能想一下就能写出来,但在应聘过程我们常常遇到的是写出一个二叉树非递归遍历函数,接着上篇文章写二叉树的非递归遍历,先难后易,一步一步的来. 先上代码: #include "binarytree.h" #include <stack> #include <queu…