update opengl example

This commit is contained in:
Vadim Lopatin 2016-01-13 14:25:33 +03:00
parent 73035e925d
commit 73686fc1d4
1 changed files with 22 additions and 21 deletions

View File

@ -54,6 +54,14 @@ class MyOpenglWidget : VerticalLayout {
padding: 20 padding: 20
layoutWidth: fill; layoutHeight: fill layoutWidth: fill; layoutHeight: fill
TextWidget { text: "DlangUI OpenGL custom drawable example"; textColor: "red"; fontSize: 150%; fontWeight: 800; fontFace: "Arial" }
TextWidget { text: "Choose OpenGL drawable:" }
VerticalLayout {
RadioButton { id: rbExample1; text: "Shaders based example - Cube"; checked: true }
RadioButton { id: rbExample2; text: "Legacy OpenGL API example - glxGears" }
}
TextWidget { text: "Some controls to draw on top of OpenGL scene"; textColor: "red"; fontSize: 150%; fontWeight: 800; fontFace: "Arial" } TextWidget { text: "Some controls to draw on top of OpenGL scene"; textColor: "red"; fontSize: 150%; fontWeight: 800; fontFace: "Arial" }
// arrange controls as form - table with two columns // arrange controls as form - table with two columns
@ -77,11 +85,6 @@ class MyOpenglWidget : VerticalLayout {
CheckBox { id: cb2; text: "checkbox 2" } CheckBox { id: cb2; text: "checkbox 2" }
} }
} }
TextWidget { text: "Choose OpenGL example:" }
VerticalLayout {
RadioButton { id: rbExample1; text: "Shaders based example - Cube"; checked: true }
RadioButton { id: rbExample2; text: "Legacy OpenGL API example - glxGears" }
}
VSpacer { layoutWeight: 10 } VSpacer { layoutWeight: 10 }
HorizontalLayout { HorizontalLayout {
Button { id: btnOk; text: "Ok" } Button { id: btnOk; text: "Ok" }
@ -116,7 +119,7 @@ class MyOpenglWidget : VerticalLayout {
// rotate gears // rotate gears
angle += interval * 0.000002f; angle += interval * 0.000002f;
} else { } else {
// TODO: animate new API example // TODO: some other animation for new API example
angle += interval * 0.000002f; angle += interval * 0.000002f;
} }
invalidate(); invalidate();
@ -218,6 +221,7 @@ class MyOpenglWidget : VerticalLayout {
void createMesh() { void createMesh() {
if (!_tx) if (!_tx)
_tx = new GLTexture("crate"); _tx = new GLTexture("crate");
// define Cube mesh // define Cube mesh
auto p000 = [-1.0f, -1.0f, -1.0f]; auto p000 = [-1.0f, -1.0f, -1.0f];
auto p100 = [ 1.0f, -1.0f, -1.0f]; auto p100 = [ 1.0f, -1.0f, -1.0f];
@ -227,12 +231,12 @@ class MyOpenglWidget : VerticalLayout {
auto p101 = [ 1.0f, -1.0f, 1.0f]; auto p101 = [ 1.0f, -1.0f, 1.0f];
auto p011 = [-1.0f, 1.0f, 1.0f]; auto p011 = [-1.0f, 1.0f, 1.0f];
auto p111 = [ 1.0f, 1.0f, 1.0f]; auto p111 = [ 1.0f, 1.0f, 1.0f];
vertices = p000 ~ p010 ~ p110 ~ p110 ~ p100 ~ p000 // front face vertices = p000 ~ p010 ~ p110 ~ p110 ~ p100 ~ p000 // front face
~ p101 ~ p111 ~ p011 ~ p011 ~ p001 ~ p101 // back face ~ p101 ~ p111 ~ p011 ~ p011 ~ p001 ~ p101 // back face
~ p100 ~ p110 ~ p111 ~ p111 ~ p101 ~ p100 // right face ~ p100 ~ p110 ~ p111 ~ p111 ~ p101 ~ p100 // right face
~ p001 ~ p011 ~ p010 ~ p010 ~ p000 ~ p001 // left face ~ p001 ~ p011 ~ p010 ~ p010 ~ p000 ~ p001 // left face
~ p010 ~ p011 ~ p111 ~ p111 ~ p110 ~ p010 // top face ~ p010 ~ p011 ~ p111 ~ p111 ~ p110 ~ p010 // top face
~ p001 ~ p000 ~ p100 ~ p100 ~ p101 ~ p001 // bottom face ~ p001 ~ p000 ~ p100 ~ p100 ~ p101 ~ p001 // bottom face
; ;
// texture coordinates // texture coordinates
float[2] uv = _tx.uv; float[2] uv = _tx.uv;
@ -240,12 +244,12 @@ class MyOpenglWidget : VerticalLayout {
float tx1 = uv[0]; float tx1 = uv[0];
float ty0 = 0.0f; float ty0 = 0.0f;
float ty1 = uv[1]; float ty1 = uv[1];
float[12] facetx = [tx1, ty1, float[12] facetx = [tx1, ty1, // triangle 1
tx0, ty0, tx0, ty0,
tx0, ty1, tx0, ty1,
tx0, ty1, tx0, ty1, // triangle 2
tx1, ty0, tx1, ty0,
tx1, ty1]; tx1, ty1];
texcoords = facetx ~ facetx ~ facetx ~ facetx ~ facetx ~ facetx; texcoords = facetx ~ facetx ~ facetx ~ facetx ~ facetx ~ facetx;
// init with white color (1, 1, 1, 1) // init with white color (1, 1, 1, 1)
foreach(ref cl; colors) foreach(ref cl; colors)
@ -307,7 +311,6 @@ class MyGLProgram : GLProgram {
return false; return false;
glEnable(GL_BLEND); glEnable(GL_BLEND);
//checkgl!glDisable(GL_CULL_FACE);
checkgl!glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); checkgl!glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
bind(); bind();
checkgl!glUniformMatrix4fv(matrixLocation, 1, false, matrix.ptr); checkgl!glUniformMatrix4fv(matrixLocation, 1, false, matrix.ptr);
@ -499,8 +502,6 @@ static void
static void glxgears_draw() static void glxgears_draw()
{ {
glClear(/*GL_COLOR_BUFFER_BIT | */GL_DEPTH_BUFFER_BIT);
glPushMatrix(); glPushMatrix();
glRotatef(view_rotx, 1.0, 0.0, 0.0); glRotatef(view_rotx, 1.0, 0.0, 0.0);
glRotatef(view_roty, 0.0, 1.0, 0.0); glRotatef(view_roty, 0.0, 1.0, 0.0);