-
大小: 10.03MB文件类型: .rar金币: 1下载: 0 次发布日期: 2023-11-06
- 语言: 其他
- 标签:
资源简介
图形学的实验~鼠标画线、键盘移动、创建颜色选择菜单三个功能皆实现了。如果项目运行有BUG的话,直接把cpp文件里的代码复制过去新建个项目就可以了
代码片段和文件信息
#include “stdafx.h“
#include
#include
#include
GLfloat vVertex[] = { 100 150 500 450 };
GLsizei winWidth = 800 winHeight = 600; // 窗口的大小
GLfloat red = 0.0 green = 0.0 blue = 0.0; //颜色
GLenum fillMode = GL_SMOOTH;
bool Line Circle Rectanger;
int xstart ystart xend yend;//鼠标的坐标
float r;//圆的半径
int NUM = 200;// 定义绘制圆时用的顶点数(用顶点组成的线段逼近圆)(new)
void fillOption(GLint s) {
//glutPostRedisplay();
}
void colorselection(GLint selectedOption)
{
switch (selectedOption) {
case 1:red = true; green = false; blue = false; break;
case 2:red = false; green = true; blue = false; break;
case 3:red = false; green = false; blue = true; break;
}
}
void lineSegment(void)
{
glLineWidth(10);
glClear(GL_COLOR_BUFFER_BIT); // Clear display window.
glColor3f(1.0 0.0 0.0); // Set line segment color to green.
glBegin(GL_LINES);
glVertex2i(vVertex[0] vVertex[1]); // Specify line-segment geometry.
glVertex2i(vVertex[2] vVertex[3]); //起点坐标,x横坐标,y纵坐标
glEnd();
glFlush(); // Process all OpenGL routines as quickly as possible.
}
void mousemove(int xmove int ymove)
{
if (red) {
glColor3f(1.0 0.0 0.0);
}
else if (green)
{
glColor3f(0.0 1.0 0.0);
}
else {
glColor3f(0.0 0.0 1.0);
}
glEnable(GL_COLOR_LOGIC_OP);
glLogicOp(GL_XOR);
glBegin(GL_LINES);
glVertex2i(xstart ystart);
glVertex2i(xend yend);
glEnd();
xend = xmove;
yend = winHeight - ymove;
glLineWidth(10);
glBegin(GL_LINES);
glVertex2i(xstart ystart);
glVertex2i(xend yend);
glEnd();
glFlush();
}
void mouseud(int btn int state int x int y)
{
if (btn == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
{
xstart = x;
ystart = winHeight - y;
xend = xstart;
yend = ystart;
}
else if (btn == GLUT_LEFT_BUTTON && state == GLUT_UP)
{
xend = x;
yend = winHeight - y;
glDisable(GL_COLOR_LOGIC_OP);
if (red) {
glColor3f(1.0 0.0 0.0);
}
else if (green)
{
glColor3f(0.0 1.0 0.0);
}
else {
glColor3f(0.0 0.0 1.0);
}
glLineWidth(10);
glBegin(GL_LINES);
glVertex2i(xstart ystart);
glVertex2i(xend yend);
glEnd();
glFlush();
}
}
//键盘移动
void SpecialKeys(int key int x int y)
{
GLfloat stepSize = 10; //增加的步量
GLfloat blockX = 0;
GLfloat blockY = 0;
//上
if (key == GLUT_KEY_UP)
{
blockY += stepSize;
}
//下
if (key == GLUT_KEY_DOWN)
{
blockY -= stepSize;
}
//左
if (key == GLUT_KEY_LEFT)
{
blockX -= stepSize;
}
//右
if (key == GLUT_KEY_RIGHT)
{
blockX += stepSize;
}
//改变顶点数据
vVertex[0] = vVertex[0] + blockX;
vVertex[1] = vVertex[1] + blockY;
vVertex[2] = vVertex[2] + blockX;
vVertex[3] = vVertex[3] + blockY;
glutPostRedisplay(); //更新窗口内容
}
void init(void)
{
glClearColor(1.0 1.0 1.0 1.0); //设置窗口颜色为白色
glMatrixMode(GL_PROJECTION); // Set projection parameters.
gluOrtho2D(0.0
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 69632 2017-04-16 21:42 Experiment3\Debug\Experiment3.exe
文件 957872 2017-04-16 21:42 Experiment3\Debug\Experiment3.ilk
文件 961536 2017-04-16 21:42 Experiment3\Debug\Experiment3.pdb
文件 218624 2017-04-13 18:36 Experiment3\Debug\freeglut.dll
文件 337408 2017-04-13 18:36 Experiment3\Debug\glew32.dll
文件 350720 2017-04-13 18:36 Experiment3\Debug\glewinfo.exe
文件 43520 2017-04-13 18:36 Experiment3\Debug\glfw3.dll
文件 222720 2017-04-13 18:36 Experiment3\Debug\visualinfo.exe
文件 2290 2017-04-16 21:42 Experiment3\Experiment3\Debug\cl.command.1.tlog
文件 21146 2017-04-16 21:42 Experiment3\Experiment3\Debug\CL.read.1.tlog
文件 1338 2017-04-16 21:42 Experiment3\Experiment3\Debug\CL.write.1.tlog
文件 98 2017-04-16 21:42 Experiment3\Experiment3\Debug\Experiment3.lastbuildstate
文件 2631 2017-04-16 21:42 Experiment3\Experiment3\Debug\Experiment3.log
文件 164769 2017-04-16 21:42 Experiment3\Experiment3\Debug\Experiment3.obj
文件 1245184 2017-04-13 18:46 Experiment3\Experiment3\Debug\Experiment3.pch
文件 2 2017-04-16 21:42 Experiment3\Experiment3\Debug\li
文件 2 2017-04-16 21:42 Experiment3\Experiment3\Debug\li
文件 2 2017-04-16 21:42 Experiment3\Experiment3\Debug\li
文件 2 2017-04-16 21:42 Experiment3\Experiment3\Debug\li
文件 2 2017-04-16 21:42 Experiment3\Experiment3\Debug\li
文件 2 2017-04-16 21:42 Experiment3\Experiment3\Debug\li
文件 2 2017-04-16 21:42 Experiment3\Experiment3\Debug\li
文件 2 2017-04-16 21:42 Experiment3\Experiment3\Debug\li
文件 2 2017-04-16 21:42 Experiment3\Experiment3\Debug\li
文件 2 2017-04-16 21:42 Experiment3\Experiment3\Debug\li
文件 2572 2017-04-16 21:42 Experiment3\Experiment3\Debug\li
文件 4106 2017-04-16 21:42 Experiment3\Experiment3\Debug\li
文件 920 2017-04-16 21:42 Experiment3\Experiment3\Debug\li
文件 11807 2017-04-13 18:46 Experiment3\Experiment3\Debug\stdafx.obj
文件 519168 2017-04-16 21:42 Experiment3\Experiment3\Debug\vc110.idb
............此处省略76个文件信息
- 上一篇:仿京东购物车页面
- 下一篇:网络设备visio图标
评论
共有 条评论