国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

用C#開發opengl

2024-07-21 02:25:20
字體:
來源:轉載
供稿:網友
微軟提供較少的標準支持,對于和他們競爭的東西—比如corba(com的競爭對手)和opengl(directx的競爭對手)。
不過在c#中實現opengl也并非沒有可能,有很多很好的第3方庫可以使用,這里列舉2個。
(1)csgl
http://csgl.sourceforge.net/index.html
名氣較大的opengl庫,有穩定版本。sf上的項目地址http://sourceforge.net/project/showfiles.php?group_id=33241。
目前有多個3d引擎項目使用的這個庫。

(2)csopengl
http://www.ia.hiof.no/gb/ptools/csharp/p-csharp.html
有較詳細的文檔和例子。sf上的項目地址http://sourceforge.net/project/showfiles.php?group_id=54966&package_id=49782。

csopengl的一個例子(我在vs2005上編譯)
-------form1.cs-------
#region using directives

using system;
using system.collections.generic;
using system.drawing;
using system.collections;
using system.componentmodel;
using system.windows.forms;
using system.data;
using csopengl;
#endregion

namespace opentest
{
partial class form1 : system.windows.forms.form
{
//private system.componentmodel.container components = null;
private glview view;

public form1()
{
initializecomponent();

view = new glview();
view.parent = this;
view.createcontrol();
view.dock = dockstyle.fill;
view._onpaint = new painter();

}

/*
protected override void dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.dispose();
}
view.dispose();
}
base.dispose(disposing);
}
*/

private void form1_load(object sender, eventargs e)
{

}

}


public class painter : glviewpainter
{
public painter() { }

public override void paint(glview view)
{
glviewport(0, 0, view.width, view.height);
glmatrixmode(gl_projection);
glloadidentity();
gluperspective(45.0f, 1.0f, 0.1f, 100.0f);
glshademodel(gl_smooth);

glclearcolor(0.0f, 0.0f, 0.0f, 0.0f);
glcleardepth(1.0f);
glenable(gl_depth_test);
gldepthfunc(gl_lequal);
glhint(gl_perspective_correction_hint, gl_nicest);

glclear(gl_color_buffer_bit | gl_depth_buffer_bit);
glmatrixmode(gl_modelview);
//drawpyramid();
//drawsphere();
drawcube();
glflush();
}

private void drawpyramid()
{
glloadidentity();
gltranslatef(-0.2f, 0.3f, -4.0f);
glrotatef(45.0f, 1.0f, 1.0f, 1.0f);

glbegin(gl_triangles);

// front face triangle:
glcolor3f(1.0f, 0.0f, 0.0f);
glvertex3f(0.0f, 1.0f, 0.0f);
glcolor3f(0.0f, 1.0f, 0.0f);
glvertex3f(-1.0f, -1.0f, 1.0f);
glcolor3f(0.0f, 0.0f, 1.0f);
glvertex3f(1.0f, -1.0f, 1.0f);

// right face triangle:
glcolor3f(1.0f, 0.0f, 0.0f);
glvertex3f(0.0f, 1.0f, 0.0f);
glcolor3f(0.0f, 0.0f, 1.0f);
glvertex3f(1.0f, -1.0f, 1.0f);
glcolor3f(0.0f, 1.0f, 0.0f);
glvertex3f(1.0f, -1.0f, -1.0f);

//back face triangle:
glcolor3f(1.0f, 0.0f, 0.0f);
glvertex3f(0.0f, 1.0f, 0.0f);
glcolor3f(0.0f, 1.0f, 0.0f);
glvertex3f(1.0f, -1.0f, -1.0f);
glcolor3f(0.0f, 0.0f, 1.0f);
glvertex3f(-1.0f, -1.0f, -1.0f);

// left face triangle:
glcolor3f(1.0f, 0.0f, 0.0f);
glvertex3f(0.0f, 1.0f, 0.0f);
glcolor3f(0.0f, 0.0f, 1.0f);
glvertex3f(-1.0f, -1.0f, -1.0f);
glcolor3f(0.0f, 1.0f, 0.0f);
glvertex3f(-1.0f, -1.0f, 1.0f);

glend();
}

private void drawcube()
{
// enable color blending:
glenable(gl_blend);
glblendfunc(gl_src_alpha, gl_one_minus_src_alpha);
glloadidentity();

gltranslatef(0.0f, 0.2f, -6.0f);
glrotatef(45.0f, 1.0f, 1.0f, 1.0f);

glbegin(gl_quads);
// tegner først de sidene som ikke skal være gjennomsiktige:
//the back:
glcolor4f(1.0f, 1.0f, 0.0f, 1.0f); // yellow
glvertex3f(1.0f, -1.0f, -1.0f);
glvertex3f(-1.0f, -1.0f, -1.0f);
glvertex3f(-1.0f, 1.0f, -1.0f);
glvertex3f(1.0f, 1.0f, -1.0f);

//the bottom:
glcolor4f(1.0f, 0.5f, 0.0f, 1.0f); // orange
glvertex3f(1.0f, -1.0f, 1.0f);
glvertex3f(-1.0f, -1.0f, 1.0f);
glvertex3f(-1.0f, -1.0f, -1.0f);
glvertex3f(1.0f, -1.0f, -1.0f);

//the right face:
glcolor4f(1.0f, 0.0f, 1.0f, 0.75f); // cyan
glvertex3f(1.0f, 1.0f, -1.0f);
glvertex3f(1.0f, 1.0f, 1.0f);
glvertex3f(1.0f, -1.0f, 1.0f);
glvertex3f(1.0f, -1.0f, -1.0f);

// de sidene som skal være gjennomsiktige:
// setter depthbuffer read-only:
gldepthmask(0);
//the front:
glcolor4f(1.0f, 0.0f, 0.0f, 0.75f); // red
glvertex3f(1.0f, 1.0f, 1.0f);
glvertex3f(-1.0f, 1.0f, 1.0f);
glvertex3f(-1.0f, -1.0f, 1.0f);
glvertex3f(1.0f, -1.0f, 1.0f);

//the top:
glcolor4f(0.0f, 1.0f, 0.0f, 0.75f); // green
glvertex3f(1.0f, 1.0f, -1.0f);
glvertex3f(-1.0f, 1.0f, -1.0f);
glvertex3f(-1.0f, 1.0f, 1.0f);
glvertex3f(1.0f, 1.0f, 1.0f);

//the left face:
glcolor4f(0.0f, 0.0f, 1.0f, 0.75f); // blue
glvertex3f(-1.0f, 1.0f, 1.0f);
glvertex3f(-1.0f, 1.0f, -1.0f);
glvertex3f(-1.0f, -1.0f, -1.0f);
glvertex3f(-1.0f, -1.0f, 1.0f);
glend();

gldepthmask(1);
gldisable(gl_blend);
}

private void drawsphere()
{
float[] ambient = { 1.0f, 1.0f, 0.0f, 1.0f };
float[] diffuse = { 1.0f, 1.0f, 0.0f, 1.0f };
float[] specular = { 1.0f, 1.0f, 1.0f, 1.0f };
float[] position = { 4.0f, 0.0f, 6.0f, 0.0f };

gllightfv(gl_light0, gl_ambient, ambient);
gllightfv(gl_light0, gl_diffuse, diffuse);
gllightfv(gl_light0, gl_specular, specular);
gllightfv(gl_light0, gl_position, position);
glenable(gl_light0);
glenable(gl_lighting);

glulookat(-4.0, -5.0, 6.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);

intptr hdc = glunewquadric();
glusphere(hdc, 2.0, 40, 40);
gludeletequadric(hdc);
}
}

}

-------------program.cs--------------
#region using directives

using system;
using system.collections.generic;
using system.windows.forms;

#endregion

namespace opentest
{
static class program
{
/// <summary>
/// the main entry point for the application.
/// </summary>
[stathread]
static void main()
{
application.enablevisualstyles();
application.enablertlmirroring();
application.run(new form1());
}
}
}



發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 澄城县| 扎赉特旗| 察雅县| 铜山县| 兰坪| 怀仁县| 康马县| 汉中市| 隆昌县| 思茅市| 老河口市| 冕宁县| 汾西县| 措勤县| 海伦市| 乐都县| 高密市| 广宗县| 平果县| 龙里县| 乐山市| 西安市| 焉耆| 浦江县| 门源| 赣榆县| 武陟县| 苍梧县| 祁东县| 名山县| 双柏县| 安泽县| 马关县| 莆田市| 靖安县| 罗平县| 康马县| 聂荣县| 保山市| 得荣县| 邢台市|