zoukankan      html  css  js  c++  java
  • 【OpenGL学习代码笔记之二】 三维空间中点的绘制

    继续捣鼓OpenGL,练习了下3D坐标下点的绘制

    代码如下:

     1 #include<glut.h>
    2 #include<math.h>
    3
    4 #define GL_PI 3.1415f
    5 void SetupRC()
    6 {
    7 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    8 glColor3f(0.0f, 1.0f, 0.0f);
    9 }
    10
    11 void myDisplay(void)
    12 {
    13 GLfloat x,y;
    14 GLfloat sizes[2]; // 用于存储glPointSize最小有效值和最大有效值
    15 GLfloat curSize; // 用来存储当前点的大小
    16 GLfloat step; // 用于存储点大小之间允许的最小增量
    17
    18 glGetFloatv(GL_POINT_SIZE_RANGE,sizes); // 获取最小、最大有效值
    19 glGetFloatv(GL_POINT_SIZE_GRANULARITY,&step); // 获取最小增量
    20 curSize = sizes[0];
    21
    22 y = 0.0f;
    23 x = -0.9f;
    24 glClear(GL_COLOR_BUFFER_BIT);
    25 glColor3f(1.0f,1.0f,1.0f);
    26
    27 // 以x为横轴自变量,y为变量绘制正弦曲线
    28 for(;x<0.9f;x+=0.01f)
    29 {
    30 y = 0.5f*sin(x*GL_PI*2);
    31 glPointSize(curSize); // 必须写在glBegin和glEnd范围外
    32
    33 glBegin(GL_POINTS); // 调用glBegin之后才开始画点
    34 glVertex2f(x,y);
    35 glEnd();
    36
    37 curSize += step; // 超过sizes[2]范围的点会取合法值域内最接近的值
    38 }
    39
    40 glFlush();
    41
    42 }
    43
    44
    45 void main()
    46 {
    47 glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
    48 glutCreateWindow("sin-curve");
    49 glutDisplayFunc(myDisplay);
    50 SetupRC();
    51 glutMainLoop();
    52
    53 }

    最终结果如下:


    总结:

    绘制点需要用到 glVertex3f(x,y,z)

    且点的大小可以改变:

    glGetFloatv(GL_POINT_SIZE_RANGE,sizes); // 获取最小、最大有效值
    glGetFloatv(GL_POINT_SIZE_GRANULARITY,&step); // 获取最小增量

    设置大小时:  glPointSize(curSize);// 必须写在glBegin和glEnd范围外

  • 相关阅读:
    基于NEO4J的高级检索功能
    Neo4j 3.5发布,在索引方面大幅增强
    Neo4j 全文检索
    主流图数据库Neo4J、ArangoDB、OrientDB综合对比:架构分析
    neo4j常用cypher语句
    Neo4j使用简单例子
    neo4j 初探
    neo4j 基本概念和Cypher语句总结
    NEO4J亿级数据全文索引构建优化
    自定义中文全文索引
  • 原文地址:https://www.cnblogs.com/shiyanch/p/2375836.html
Copyright © 2011-2022 走看看