老师布置的作业,在vs2008下,用c#语言,opengl技术画一面五星红旗,求高手帮忙啊
发布网友
发布时间:2022-08-16 03:32
我来回答
共4个回答
热心网友
时间:2023-09-28 08:08
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CsGL.OpenGL;
namespace mySecondExample
{
public partial class OGLview : OpenGLControl
{
public OGLview()
{
InitializeComponent();
}
protected override void InitGLContext()
{
base.InitGLContext();
GL.glClearColor(1.0f, 0.0f, 0.0f, 0.0f); // 设置OpenGl视图空间的背景色为黑色
GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);// Clear Screen And Depth Buffer
GL.glMatrixMode(GL.GL_PROJECTION); // 将变换矩阵模式设为投影变换
GL.glLoadIdentity(); // 加载投影变换单位矩阵重置视景体
// 用正射投影设置一个边长为20个单位的立方体兴视景体
GL.glOrtho(-1.0, 1.0, -1, 1.0, 0, 20);
//TODO: 可添加其他初始化动作
}
protected override void OnSizeChanged(EventArgs e)
{
try
{
base.OnSizeChanged(e);
}
catch (Exception)
{
}
// 设置视口尺寸与视图类控件的尺寸相同
GL.glViewport(0, 0, this.Size.Width, this.Size.Height);
GL.glMatrixMode(GL.GL_MODELVIEW); // 设置当前为模型视图矩阵
GL.glLoadIdentity(); // 重置模型视图矩阵
}
public override void glDraw()
{
GL.glClearColor(1.0f, 0.0f, 0.0f, 0.0f); // 设置OpenGl视图空间的背景色为黑色
GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);// Clear Screen And Depth Buffer
GL.glColor3f(1.0f, 1f, 0.0f);
/* draw two redish triangles - at upper-right corner */
GL.glBegin(GL.GL_TRIANGLES);
GL.glVertex2f(0f, 0.1f);
GL.glVertex2f(-0.035f, 0.05f);
GL.glVertex2f(0.035f, 0.05f);
GL.glVertex2f(0.035f, 0.05f);
GL.glVertex2f(-0.1f, 0.05f);
GL.glVertex2f(-0.05f, 0f);
GL.glVertex2f(0.035f, 0.05f);
GL.glVertex2f(-0.05f, 0f);
GL.glVertex2f(0.05f, 0f);
GL.glVertex2f(0.05f, 0f);
GL.glVertex2f(0.035f, 0.05f);
GL.glVertex2f(0.1f, 0.05f);
GL.glVertex2f(0.05f, 0f);
GL.glVertex2f(0.07f, -0.07f);
GL.glVertex2f(0f, -0.0f);
GL.glVertex2f(-0.05f, 0f);
GL.glVertex2f(-0.07f, -0.07f);
GL.glVertex2f(0f, 0f);
GL.glEnd();
}
}
}
这是一个五角星 你可以运行试一下
如果合适 那就采纳把 记得分儿~
热心网友
时间:2023-09-28 08:09
你不会是西邮的孩子吧
热心网友
时间:2023-09-28 08:09
不知道啊追问你真好玩,打击我啊
热心网友
时间:2023-09-28 08:10
界面上有个Form1 我没实现那么多,只实现了 把Form1变成五角星,并且可以移动,
双击五角星 退出程序~~~~~~
关键代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace 可移动的五角形
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private Point MousePos; // 记录鼠标指针的坐标
private bool bMouseDown = false;//记录鼠标是否按下
private void Form1_Paint(object sender, PaintEventArgs e)
{
GraphicsPath myGraphicsPath = new GraphicsPath(); //实例化五角形的线
//定义五个 点数组
Point[] myPoint = {
new Point(130,100),
new Point(300,000),
new Point(470,100),
new Point(400,300),
new Point(200,300),
};
myGraphicsPath.AddPolygon(myPoint); //绘制五角形
this.Region = new Region(myGraphicsPath);//控件关联的窗口区域
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
MousePos.X = -e.X - SystemInformation.FrameBorderSize.Width;
MousePos.Y = -e.Y - SystemInformation.CaptionHeight - SystemInformation.FrameBorderSize.Height;
bMouseDown = true;
}
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (bMouseDown)
{
Point CurrentPos = Control.MousePosition;
CurrentPos.Offset(MousePos.X,MousePos.Y);
Location = CurrentPos;
}
}
private void Form1_DoubleClick(object sender, EventArgs e)
{
this.Close();
this.Dispose();
}
}
}
合适就采纳把~~~~追问您好,能留个QQ吗,我加你详细问问
追答QQ : 1656081482