private void openGLControl1_OpenGLDraw( object sender, PaintEventArgs e)
{
// 将纹理绑定在要绘制的图像表面
SharpGL.OpenGL gl = this.openGLControl1.OpenGL;
//清除屏幕及深度缓存
gl.Clear(OpenGL.COLOR_BUFFER_BIT | OpenGL.DEPTH_BUFFER_BIT);
//选择纹理
texture1.Bind(gl);
for ( int loop = 0; loop < starnumber; loop++)
{
gl.LoadIdentity();
gl.Translate(0f, 0f, zoom);
gl.Rotate(tilt, 1f, 0f, 0f);
gl.Rotate(star[loop].angle, 0f, 1f, 0f);
gl.Translate(star[loop].dist, 0f, 0f);
gl.Rotate(-star[loop].angle, 0f, 1f, 0f);
gl.Rotate(-tilt, 1f, 0f, 0f);
if (twinkle)
{
gl.Color(star[starnumber - loop - 1].r, star[starnumber - loop - 1].g, star[starnumber - loop - 1].b, 1f);
gl.Begin(OpenGL.QUADS);
gl.TexCoord(0.0f, 0.0f); gl.Vertex(-1.0f, -1.0f, 0.0f); // Bottom Left Of The Texture and Quad
gl.TexCoord(1.0f, 0.0f); gl.Vertex(1.0f, -1.0f, 0.0f); // Bottom Right Of The Texture and Quad
gl.TexCoord(1.0f, 1.0f); gl.Vertex(1.0f, 1.0f, 0.0f); // Top Right Of The Texture and Quad
gl.TexCoord(0.0f, 1.0f); gl.Vertex(-1.0f, 1.0f, 0.0f); // Top Left Of The Texture and Quad
gl.End();
//gl.Flush();
}
gl.Rotate(spin, 0f, 0f, 1f);
gl.Color(star[loop].r, star[loop].g, star[loop].b, 1f);
gl.Begin(OpenGL.QUADS);
gl.TexCoord(0.0f, 0.0f); gl.Vertex(-1.0f, -1.0f, 0.0f); // Bottom Left Of The Texture and Quad
gl.TexCoord(1.0f, 0.0f); gl.Vertex(1.0f, -1.0f, 0.0f); // Bottom Right Of The Texture and Quad
gl.TexCoord(1.0f, 1.0f); gl.Vertex(1.0f, 1.0f, 0.0f); // Top Right Of The Texture and Quad
gl.TexCoord(0.0f, 1.0f); gl.Vertex(-1.0f, 1.0f, 0.0f); // Top Left Of The Texture and Quad
gl.End();
spin += 0.01f;
star[loop].angle += ( float)loop / starnumber;
star[loop].dist -= 0.01f;
if (star[loop].dist < 0.0f)
{
star[loop].dist += 5f;
byte[] starcolor = new byte[3];
rand.NextBytes(starcolor);
star[loop].r = ( float)starcolor[0] / 255;
star[loop].g = ( float)starcolor[1] / 255;
star[loop].b = ( float)starcolor[2] / 255;
}
}
}