public void createStemAndLeafs() { GL.glNewList(STEM_AND_LEAVS_LIST + currentTree, GL.GL_COMPILE); GL.glPushMatrix(); GL.glPushAttrib(GL.GL_LIGHTING_BIT); GL.glCallList(STEM_LIST + currentTree); GL.glCallList(LEAF_MAT); for (int i = 0; i < 3; i++) { GL.glTranslatef(0, (float)1 / 3, 0); GL.glRotatef(90, 0, 1, 0); GL.glPushMatrix(); GL.glRotatef(50, 1, 0, 0); GL.glCallList(LEAF_LIST + currentTree); GL.glPopMatrix(); GL.glPushMatrix(); GL.glRotatef(180, 0, 1, 0); GL.glRotatef(60, 1, 0, 0); GL.glCallList(LEAF_LIST + currentTree); GL.glPopMatrix(); } GL.glPopAttrib(); GL.glPopMatrix(); GL.glEndList(); }
public static void glutWireTorus(double innerRadius, double outerRadius, int nsides, int rings) { GL.glPushAttrib(GL.GL_POLYGON_BIT); GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE); Doughnut((float)innerRadius, (float)outerRadius, nsides, rings); GL.glPopAttrib(); }
void CreateTree() { GL.glNewList(TREE_LIST + currentTree, GL.GL_COMPILE); GL.glPushMatrix(); GL.glPushAttrib(GL.GL_LIGHTING_BIT); GL.glCallList(TREE_MAT); GL.glScaled(amplitude, amplitude, amplitude); FractalTreeRec(0); GL.glPopAttrib(); GL.glPopMatrix(); GL.glEndList(); }
public void Draw() { pos[0] = -4 + (float)xExisOrigin + (float)ScrollValue[11]; pos[1] = 15 + (float)yExisOrigin + (float)ScrollValue[12]; pos[2] = 15 + (float)ScrollValue[13]; if (m_uint_DC == 0 || m_uint_RC == 0) { return; } GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT); GL.glLoadIdentity(); // not trivial double [] ModelVievMatrixBeforeSpecificTransforms = new double[16]; double [] CurrentRotationTraslation = new double[16]; GLU.gluLookAt(ScrollValue[0], ScrollValue[1], ScrollValue[2], ScrollValue[3], ScrollValue[4], ScrollValue[5], ScrollValue[6], ScrollValue[7], ScrollValue[8]); GL.glTranslatef(0.0f, 0.0f, -30.0f); GL.glRotatef(105, 0, 0, 1); GL.glRotatef(70, 0, 1, 0); GL.glRotatef(15, 1, 0, 0); //save current ModelView Matrix values //in ModelVievMatrixBeforeSpecificTransforms array //ModelView Matrix ========>>>>>> ModelVievMatrixBeforeSpecificTransforms GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, ModelVievMatrixBeforeSpecificTransforms); //ModelView Matrix was saved, so GL.glLoadIdentity(); // make it identity matrix //make transformation in accordance to KeyCode float delta; if (intOptionC != 0) { delta = 5.0f * Math.Abs(intOptionC) / intOptionC; // signed 5 switch (Math.Abs(intOptionC)) { case 1: GL.glRotatef(delta, 1, 0, 0); break; case 2: GL.glRotatef(delta, 0, 1, 0); break; case 3: GL.glRotatef(delta, 0, 0, 1); break; case 4: GL.glTranslatef(delta / 20, 0, 0); break; case 5: GL.glTranslatef(0, delta / 20, 0); break; case 6: GL.glTranslatef(0, 0, delta / 20); break; } } //as result - the ModelView Matrix now is pure representation //of KeyCode transform and only it !!! //save current ModelView Matrix values //in CurrentRotationTraslation array //ModelView Matrix =======>>>>>>> CurrentRotationTraslation GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, CurrentRotationTraslation); //The GL.glLoadMatrix function replaces the current matrix with //the one specified in its argument. //The current matrix is the //projection matrix, modelview matrix, or texture matrix, //determined by the current matrix mode (now is ModelView mode) GL.glLoadMatrixd(AccumulatedRotationsTraslations); //Global Matrix //The GL.glMultMatrix function multiplies the current matrix by //the one specified in its argument. //That is, if M is the current matrix and T is the matrix passed to //GL.glMultMatrix, then M is replaced with M • T GL.glMultMatrixd(CurrentRotationTraslation); //save the matrix product in AccumulatedRotationsTraslations GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, AccumulatedRotationsTraslations); //replace ModelViev Matrix with stored ModelVievMatrixBeforeSpecificTransforms GL.glLoadMatrixd(ModelVievMatrixBeforeSpecificTransforms); //multiply it by KeyCode defined AccumulatedRotationsTraslations matrix GL.glMultMatrixd(AccumulatedRotationsTraslations); //REFLECTION//DrawAxes(); //REFLECTION b intOptionB += 1; //for rotation intOptionC += 10; //for rotation // without REFLECTION was only DrawAll(); // now //!!!!------sky box GL.glPushMatrix(); GL.glPushAttrib(GL.GL_CURRENT_BIT); GL.glColor4f(1.0f, 1.0f, 1.0f, 0.5f); GL.glEnable(GL.GL_TEXTURE_2D); GL.glDisable(GL.GL_BLEND); GL.glRotatef(90, 1, 0, 0); DrawTexturedCube(); GL.glPopAttrib(); GL.glPopMatrix(); ///// GL.glEnable(GL.GL_BLEND); GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); //only floor, draw only to STENCIL buffer GL.glEnable(GL.GL_STENCIL_TEST); GL.glStencilOp(GL.GL_REPLACE, GL.GL_REPLACE, GL.GL_REPLACE); GL.glStencilFunc(GL.GL_ALWAYS, 1, 0xFFFFFFFF); // draw floor always GL.glColorMask((byte)GL.GL_FALSE, (byte)GL.GL_FALSE, (byte)GL.GL_FALSE, (byte)GL.GL_FALSE); GL.glDisable(GL.GL_DEPTH_TEST); DrawFloor3(); // restore regular settings GL.glColorMask((byte)GL.GL_TRUE, (byte)GL.GL_TRUE, (byte)GL.GL_TRUE, (byte)GL.GL_TRUE); GL.glEnable(GL.GL_DEPTH_TEST); // reflection is drawn only where STENCIL buffer value equal to 1 GL.glStencilFunc(GL.GL_EQUAL, 1, 0xFFFFFFFF); GL.glStencilOp(GL.GL_KEEP, GL.GL_KEEP, GL.GL_KEEP); GL.glEnable(GL.GL_STENCIL_TEST); // draw reflected scene GL.glPushMatrix(); GL.glScalef(1, 1, -1); //swap on Z axis GL.glEnable(GL.GL_CULL_FACE); GL.glCullFace(GL.GL_BACK); DrawFigures(); GL.glCullFace(GL.GL_FRONT); DrawFigures(); GL.glDisable(GL.GL_CULL_FACE); GL.glPopMatrix(); // really draw floor //( half-transparent ( see its color's alpha byte))) // in order to see reflected objects GL.glDepthMask((byte)GL.GL_FALSE); DrawFloor3(); GL.glDepthMask((byte)GL.GL_TRUE); // Disable GL.GL_STENCIL_TEST to show All, else it will be cut on GL.GL_STENCIL GL.glDisable(GL.GL_STENCIL_TEST); DrawFigures(); GL.glDisable(GL.GL_TEXTURE_2D); GL.glFlush(); WGL.wglSwapBuffers(m_uint_DC); }
private static void DrawTeapot(int grid, double scale, uint type) { float[ , , ] p = new float[4, 4, 3]; float[ , , ] q = new float[4, 4, 3]; float[ , , ] r = new float[4, 4, 3]; float[ , , ] s = new float[4, 4, 3]; long i, j, k, l; GL.glPushAttrib(GL.GL_ENABLE_BIT | GL.GL_EVAL_BIT); GL.glEnable(GL.GL_AUTO_NORMAL); GL.glEnable(GL.GL_NORMALIZE); GL.glEnable(GL.GL_MAP2_VERTEX_3); GL.glEnable(GL.GL_MAP2_TEXTURE_COORD_2); GL.glPushMatrix(); GL.glRotatef(270.0f, 1.0f, 0.0f, 0.0f); GL.glScalef(0.5f * (float)scale, 0.5f * (float)scale, 0.5f * (float)scale); GL.glTranslatef(0.0f, 0.0f, -1.5f); for (i = 0; i < 10; i++) { for (j = 0; j < 4; j++) { for (k = 0; k < 4; k++) { for (l = 0; l < 3; l++) { p[j, k, l] = cpdata[patchdata[i, j * 4 + k], l]; q[j, k, l] = cpdata[patchdata[i, j * 4 + (3 - k)], l]; if (l == 1) { q[j, k, l] *= -1.0f; } if (i < 6) { r[j, k, l] = cpdata[patchdata[i, j * 4 + (3 - k)], l]; if (l == 0) { r[j, k, l] *= -1.0f; } s[j, k, l] = cpdata[patchdata[i, j * 4 + k], l]; if (l == 0) { s[j, k, l] *= -1.0f; } if (l == 1) { s[j, k, l] *= -1.0f; } } } } } int cnt = 0; float[] tex1 = new float[8]; for (int d = 0; d < 2; d++) { for (int e = 0; e < 2; e++) { for (int f = 0; f < 2; f++) { tex1[cnt] = tex[d, e, f]; cnt++; } } } GL.glMap2f(GL.GL_MAP2_TEXTURE_COORD_2, 0, 1, 2, 2, 0, 1, 4, 2, tex1); cnt = 0; float[] p1 = new float[48]; for (int d = 0; d < 4; d++) { for (int e = 0; e < 4; e++) { for (int f = 0; f < 3; f++) { p1[cnt] = p[d, e, f]; cnt++; } } } GL.glMap2f(GL.GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, p1); GL.glMapGrid2f(grid, 0.0f, 1.0f, grid, 0.0f, 1.0f); GL.glEvalMesh2(type, 0, grid, 0, grid); cnt = 0; int cnt1 = 0; int cnt2 = 0; float[] q1 = new float[48]; float[] r1 = new float[48]; float[] s1 = new float[48]; for (int d = 0; d < 4; d++) { for (int e = 0; e < 4; e++) { for (int f = 0; f < 3; f++) { q1[cnt] = q[d, e, f]; cnt++; } } } GL.glMap2f(GL.GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, q1); GL.glEvalMesh2(type, 0, grid, 0, grid); if (i < 6) { for (int d = 0; d < 4; d++) { for (int e = 0; e < 4; e++) { for (int f = 0; f < 3; f++) { r1[cnt1] = r[d, e, f]; cnt1++; } } } GL.glMap2f(GL.GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, r1); GL.glEvalMesh2(type, 0, grid, 0, grid); for (int d = 0; d < 4; d++) { for (int e = 0; e < 4; e++) { for (int f = 0; f < 3; f++) { s1[cnt2] = s[d, e, f]; cnt2++; } } } GL.glMap2f(GL.GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, s1); GL.glEvalMesh2(type, 0, grid, 0, grid); } } GL.glPopMatrix(); GL.glPopAttrib(); }