当前位置:网站首页>7. Draw a Bezier curve on the screen and smooth the curve with anti aliasing technology.
7. Draw a Bezier curve on the screen and smooth the curve with anti aliasing technology.
2022-07-24 05:32:00 【Mo xiaodai ^o^】
#define GLUT_DISABLE_ATEXIT_HACK
#include "windows.h"
#include <gl/glut.h>
#include "math.h"
/** Array of control points */
GLfloat points[4][3] = {
{ -4.0f, -2.0f, 0.0f }, { -2.0f, 3.0f, 2.0f},
{ 2.0f, -3.0f, -2.0f }, { 4.0f, 2.0f, 0.0f} };
// initialization OpenGL
void init(void)
{
/** User defined initialization process */
glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
glClearDepth(1.0f);
glDepthFunc(GL_LEQUAL);
glEnable(GL_DEPTH_TEST);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
/** Enable and define a one-dimensional evaluator */
glEnable(GL_MAP1_VERTEX_3);
glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, &points[0][0]);
}
// The main drawing process
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);// Clear color cache
glShadeModel(GL_FLAT);
glLoadIdentity();
glTranslatef(-1, 1, -7.0);
// evaluation
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glEnable(GL_LINE_SMOOTH); /**< Enable straight line anti aliasing */
/**< Enable hybrid */
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); /**< Specify mixing factor */
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); /**< behavior control */
glBegin(GL_LINE_STRIP);
for (int i = 0; i < 100; i++)
{
/** Perform the evaluation procedure */
glEvalCoord1f((float)i / 100.0f);
}
glEnd();
// glMapGrid1f(100, 0.0, 1.0);
// glEvalMesh1(GL_LINE, 0, 100);
// Draw control points
glPointSize(4.0);
glBegin(GL_POINTS);
for (int j = 0; j < 4; j++)
glVertex3fv(&points[j][0]);
glEnd();
glFlush(); /**< Enforce all OpenGL command */
glutSwapBuffers();
}
// Call when the window changes size
void reshape(int w, int h) {
glViewport(0, 0, w, h);// Set up the viewport
glMatrixMode(GL_PROJECTION);// Set the current projection transformation mode
glLoadIdentity();// Replace the current transformation matrix with the identity matrix
gluPerspective(90, (float)w / h, 4, 10.0);// Set the orthographic projection body
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
}
// Dealing with keyboards
void keyboard(unsigned char key, int x, int y) {
switch (key) {
case 27://esc Key to exit
exit(0);
break;
default:
break;
}
}
int main(int argc, char* argv[]) // The main function : The number of arguments & Parameter values
{
glutInit(&argc, argv);
glutInitWindowSize(640, 480);
glutCreateWindow("Basic");// Set the window title
init();// initialization OpenGL
glutDisplayFunc(display);// Set display callback function
glutReshapeFunc(reshape);// Set up reshape Callback function
glutKeyboardFunc(keyboard);// Set the keyboard callback function
glutMainLoop();// Enter the main loop
}
边栏推荐
猜你喜欢
随机推荐
MySQL之索引&执行计划
谈谈对未来的想法
special effects - 鼠标点击,自定义 DOM 跟随移动
9.使用网格技术,在屏幕上绘制一个五角形。
C文件读写加链表增删改查
面向 对象
MySQL之CRUD
通用分页2.0
gdb调试core/dump
OpenGL simulates the process of a ball falling to the ground and bouncing up in real life. Draw a ball on the screen, and the ball will fall from top to bottom, hit the ground and bounce up again.
String_ Method_ 01match method
canvas - 旋转
OpenGL draws a cone on the screen, which has four faces, each of which is a triangle. Add lighting and texture effects to the cone
MySQL的使用
Some experience of using D2L package and related environment configuration
根据数组中对象的某个属性值进行排序
B站视频评论爬取——以鬼灭之刃为例(并将其存储到csv中)
JS输出字符串中出现最多次数的字符
在屏幕上绘制一个正方形,用ice.bmp对正方形做纹理映射;在正方形后绘制一个黄色的茶壶,假设正方形是透明的,绘制茶壶与正方形的混合效果;通过A,D,W和K按键调整茶壶在X轴和Y轴的位置,具体如下
AttributeError: ‘NoneType‘ object has no attribute ‘shape‘









