public static void OnRenderFloor() { float s = 10.0f, t = 10.0f; float e = 30.0f; GL.PushAttrib(AttribMask.AllAttribBits); GL.Disable(EnableCap.CullFace); GL.Disable(EnableCap.Blend); GL.Disable(EnableCap.Lighting); GL.PolygonMode(MaterialFace.Front, PolygonMode.Line); GL.PolygonMode(MaterialFace.Back, PolygonMode.Fill); //So that the model clips with the floor GL.Enable(EnableCap.DepthTest); GL.Enable(EnableCap.Texture2D); GL.MatrixMode(MatrixMode.Texture); GL.LoadIdentity(); GLTexture bgTex = TKContext.FindOrCreate("TexBG", GLTexturePanel.CreateBG); bgTex.Bind(); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); GL.Color4(_floorHue); GL.Begin(BeginMode.Quads); GL.TexCoord2(0.0f, 0.0f); GL.Vertex3(-e, 0.0f, -e); GL.TexCoord2(s, 0.0f); GL.Vertex3(e, 0.0f, -e); GL.TexCoord2(s, t); GL.Vertex3(e, 0.0f, e); GL.TexCoord2(0.0f, t); GL.Vertex3(-e, 0.0f, e); GL.End(); GL.Disable(EnableCap.Texture2D); GL.PopAttrib(); }
private unsafe void modelPanel1_PreRender(object sender, TKContext ctx) { if (RenderFloor) { GLTexture _bgTex = ctx.FindOrCreate <GLTexture>("TexBG", GLTexturePanel.CreateBG); float s = 10.0f, t = 10.0f; float e = 30.0f; GL.Disable(EnableCap.CullFace); GL.Disable(EnableCap.Blend); GL.Disable(EnableCap.Lighting); GL.PolygonMode(MaterialFace.Front, PolygonMode.Line); GL.PolygonMode(MaterialFace.Back, PolygonMode.Fill); GL.Enable(EnableCap.Texture2D); GL.Color4(StaticMainWindow._floorHue); _bgTex.Bind(); GL.Begin(BeginMode.Quads); GL.TexCoord2(0.0f, 0.0f); GL.Vertex3(-e, 0.0f, -e); GL.TexCoord2(s, 0.0f); GL.Vertex3(e, 0.0f, -e); GL.TexCoord2(s, t); GL.Vertex3(e, 0.0f, e); GL.TexCoord2(0, t); GL.Vertex3(-e, 0.0f, e); GL.End(); GL.Disable(EnableCap.Texture2D); } Attributes.PreRender(); }
protected internal unsafe override void OnRender(TKContext ctx, PaintEventArgs e) { GLTexture _bgTex = ctx.FindOrCreate <GLTexture>("TexBG", CreateBG); _bgTex.Bind(); //Draw BG float s = (float)Width / (float)_bgTex.Width, t = (float)Height / (float)_bgTex.Height; GL.Begin(BeginMode.Quads); GL.TexCoord2(0.0f, 0.0f); GL.Vertex2(0.0f, 0.0f); GL.TexCoord2(s, 0.0f); GL.Vertex2(1.0, 0.0f); GL.TexCoord2(s, t); GL.Vertex2(1.0, 1.0); GL.TexCoord2(0, t); GL.Vertex2(0.0f, 1.0); GL.End(); //Draw texture if ((_currentTexture != null) && (_currentTexture._texId != 0)) { float tAspect = (float)_currentTexture.Width / _currentTexture.Height; float wAspect = (float)Width / Height; float *points = stackalloc float[8]; if (tAspect > wAspect) //Texture is wider, use horizontal fit { points[0] = points[6] = 0.0f; points[2] = points[4] = 1.0f; points[1] = points[3] = ((Height - ((float)Width / _currentTexture.Width * _currentTexture.Height))) / Height / 2.0f; points[5] = points[7] = 1.0f - points[1]; } else { points[1] = points[3] = 0.0f; points[5] = points[7] = 1.0f; points[0] = points[6] = (Width - ((float)Height / _currentTexture.Height * _currentTexture.Width)) / Width / 2.0f; points[2] = points[4] = 1.0f - points[0]; } GL.BindTexture(TextureTarget.Texture2D, _currentTexture._texId); GL.Begin(BeginMode.Quads); GL.TexCoord2(0.0f, 0.0f); GL.Vertex2(&points[0]); GL.TexCoord2(1.0f, 0.0f); GL.Vertex2(&points[2]); GL.TexCoord2(1.0f, 1.0f); GL.Vertex2(&points[4]); GL.TexCoord2(0.0f, 1.0f); GL.Vertex2(&points[6]); GL.End(); } }
public void Render(bool targetModel, ModelPanelViewport viewport, Vector3 parentPos = new Vector3()) { if (!_render) { return; } //Draw name if selected if (_nodeColor != Color.Transparent && viewport != null) { Vector3 screenPos = viewport.Camera.Project(_frameMatrix.GetPoint()); viewport.ScreenText[Name] = new Vector3(screenPos._x, screenPos._y - 9.0f, screenPos._z); } float alpha = targetModel ? 1.0f : 0.45f; //Set bone line color if (_boneColor != Color.Transparent) { GL.Color4(_boneColor.R / 255.0f, _boneColor.G / 255.0f, _boneColor.B / 255.0f, alpha); } else { GL.Color4(targetModel ? DefaultLineColor : DefaultLineDeselectedColor); } //Draw bone line Vector3 currentPos = _frameMatrix.GetPoint(); GL.Begin(BeginMode.Lines); GL.Vertex3((float *)&parentPos); GL.Vertex3((float *)¤tPos); GL.End(); //Set bone orb color if (_nodeColor != Color.Transparent) { GL.Color4(_nodeColor.R / 255.0f, _nodeColor.G / 255.0f, _nodeColor.B / 255.0f, alpha); } else { GL.Color4(DefaultNodeColor.R / 255.0f, DefaultNodeColor.G / 255.0f, DefaultNodeColor.B / 255.0f, alpha); } //Draw bone orb GL.PushMatrix(); bool ignoreBoneScale = true; bool scaleBones = viewport != null && viewport._renderAttrib._scaleBones; Matrix transform = _frameMatrix; if (ignoreBoneScale) { transform = Matrix.TranslationMatrix(currentPos) * _frameMatrix.GetRotationMatrix() * Matrix.ScaleMatrix(new Vector3(1.0f)); } if (viewport._renderAttrib._renderBonesAsPoints) { GL.MultMatrix((float *)&transform); if (!scaleBones) { GL.PointSize(1.0f / (ModelEditorBase.OrbRadius(this, viewport.Camera)) * 10.0f); } else { GL.PointSize(10.0f); } GL.Enable(EnableCap.PointSmooth); GL.Begin(BeginMode.Points); GL.Vertex3(0, 0, 0); GL.End(); } else { if (scaleBones) { transform.Scale(new Vector3(ModelEditorBase.OrbRadius(this, viewport.Camera))); } GL.MultMatrix((float *)&transform); //Orb TKContext.FindOrCreate <GLDisplayList>("BoneNodeOrb", CreateNodeOrb).Call(); //Axes DrawNodeOrients(alpha); } GL.PopMatrix(); //Render children foreach (MDL0BoneNode n in Children) { n.Render(targetModel, viewport, currentPos); } }
protected internal unsafe override void OnRender(TKContext ctx, PaintEventArgs e) { GLTexture _bgTex = ctx.FindOrCreate<GLTexture>("TexBG", CreateBG); _bgTex.Bind(); //Draw BG float s = (float)Width / (float)_bgTex.Width, t = (float)Height / (float)_bgTex.Height; GL.Begin(BeginMode.Quads); GL.TexCoord2(0.0f, 0.0f); GL.Vertex2(0.0f, 0.0f); GL.TexCoord2(s, 0.0f); GL.Vertex2(1.0, 0.0f); GL.TexCoord2(s, t); GL.Vertex2(1.0, 1.0); GL.TexCoord2(0, t); GL.Vertex2(0.0f, 1.0); GL.End(); //Draw texture if ((_currentTexture != null) && (_currentTexture._texId != 0)) { float tAspect = (float)_currentTexture.Width / _currentTexture.Height; float wAspect = (float)Width / Height; float* points = stackalloc float[8]; if (tAspect > wAspect) //Texture is wider, use horizontal fit { points[0] = points[6] = 0.0f; points[2] = points[4] = 1.0f; points[1] = points[3] = ((Height - ((float)Width / _currentTexture.Width * _currentTexture.Height))) / Height / 2.0f; points[5] = points[7] = 1.0f - points[1]; } else { points[1] = points[3] = 0.0f; points[5] = points[7] = 1.0f; points[0] = points[6] = (Width - ((float)Height / _currentTexture.Height * _currentTexture.Width)) / Width / 2.0f; points[2] = points[4] = 1.0f - points[0]; } GL.BindTexture(TextureTarget.Texture2D, _currentTexture._texId); GL.Begin(BeginMode.Quads); GL.TexCoord2(0.0f, 0.0f); GL.Vertex2(&points[0]); GL.TexCoord2(1.0f, 0.0f); GL.Vertex2(&points[2]); GL.TexCoord2(1.0f, 1.0f); GL.Vertex2(&points[4]); GL.TexCoord2(0.0f, 1.0f); GL.Vertex2(&points[6]); GL.End(); } }
public void Render(GLCamera cam, bool renderBG) { cam.LoadProjection(); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); GL.Color4(Color.White); GL.Enable(EnableCap.Texture2D); float halfW = (float)Width / 2.0f, halfH = (float)Height / 2.0f; GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); GL.MatrixMode(MatrixMode.Texture); GL.LoadIdentity(); if (renderBG) { GL.PushAttrib(AttribMask.TextureBit); GLTexture bgTex = TKContext.FindOrCreate <GLTexture>("TexBG", GLTexturePanel.CreateBG); bgTex.Bind(); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); float s = (float)Width / (float)bgTex.Width, t = (float)Height / (float)bgTex.Height; GL.Begin(BeginMode.Quads); GL.TexCoord2(0.0f, 0.0f); GL.Vertex2(-halfW, -halfH); GL.TexCoord2(s, 0.0f); GL.Vertex2(halfW, -halfH); GL.TexCoord2(s, t); GL.Vertex2(halfW, halfH); GL.TexCoord2(0.0f, t); GL.Vertex2(-halfW, halfH); GL.End(); GL.PopAttrib(); } if (Tex0 == null) { return; } Tex0.Prepare(_targetMatRef, -1); GLTexture texture = GLTex; if (texture == null || texture._texId <= 0) { return; } MDL0TextureNode.ApplyGLTextureParameters(_targetMatRef); //These are used to match up the UV overlay to the texture underneath Vector2 topLeft = new Vector2(); Vector2 bottomRight = new Vector2(); float texWidth = texture.Width; float texHeight = texture.Height; float tAspect = (float)texWidth / texHeight; float wAspect = (float)Width / Height; float[] texCoord = new float[8]; //These are used to compensate for padding added on an axis float xCorrect = 1.0f, yCorrect = 1.0f; if (tAspect > wAspect) { //Texture is wider, use horizontal fit //X touches the edges of the window, Y has top and bottom padding //X texCoord[0] = texCoord[6] = 0.0f; texCoord[2] = texCoord[4] = 1.0f; //Y texCoord[1] = texCoord[3] = (yCorrect = tAspect / wAspect) / 2.0f + 0.5f; texCoord[5] = texCoord[7] = 1.0f - texCoord[1]; bottomRight = new Vector2(halfW, (((float)Height - ((float)Width / texWidth * texHeight)) / (float)Height / 2.0f - 0.5f) * (float)Height); topLeft = new Vector2(-halfW, -bottomRight._y); } else { //Window is wider, use vertical fit //Y touches the edges of the window, X has left and right padding //Y texCoord[1] = texCoord[3] = 1.0f; texCoord[5] = texCoord[7] = 0.0f; //X texCoord[2] = texCoord[4] = (xCorrect = wAspect / tAspect) / 2.0f + 0.5f; texCoord[0] = texCoord[6] = 1.0f - texCoord[2]; bottomRight = new Vector2(1.0f - (((float)Width - ((float)Height / texHeight * texWidth)) / Width / 2.0f - 0.5f) * (float)Width, -halfH); topLeft = new Vector2(-bottomRight._x, halfH); } //Apply the texcoord bind transform first TextureFrameState state = _targetMatRef._bindState; GL.MultMatrix((float *)&state._transform); //Translate the texture coordinates to match where the user dragged the camera //Divide by width and height to convert window units (0 to w, 0 to h) to texcoord units (0 to 1) //Then multiply by the correction value if the window is bigger than the texture on an axis Vector3 point = cam.GetPoint(); GL.Translate(point._x / Width * xCorrect, -point._y / Height * yCorrect, 0); //Now to scale the texture after translating. //The scale origin is the top left of the texture on the window (not of the window itself), //so we need to translate the center of the texture to that origin, //scale it up or down, then translate it back to where it was. OpenTK.Vector3 trans = new OpenTK.Vector3(-topLeft._x / Width * xCorrect, topLeft._y / Height * yCorrect, 0.0f); GL.Translate(trans); GL.Scale((OpenTK.Vector3)cam._scale); GL.Translate(-trans); //Bind the material ref's texture GL.BindTexture(TextureTarget.Texture2D, texture._texId); //Draw a quad across the screen and render the texture with the calculated texcoords GL.Begin(BeginMode.Quads); GL.TexCoord2(texCoord[0], texCoord[1]); GL.Vertex2(-halfW, -halfH); GL.TexCoord2(texCoord[2], texCoord[3]); GL.Vertex2(halfW, -halfH); GL.TexCoord2(texCoord[4], texCoord[5]); GL.Vertex2(halfW, halfH); GL.TexCoord2(texCoord[6], texCoord[7]); GL.Vertex2(-halfW, halfH); GL.End(); GL.Disable(EnableCap.Texture2D); //Now load the camera transform and draw the UV overlay over the texture cam.LoadModelView(); //Color the lines limegreen, a bright color that probably won't be in a texture GL.Color4(Color.LimeGreen); Vector2 mdlScale = new Vector2(bottomRight._x - topLeft._x, bottomRight._y - topLeft._y); GL.Translate(topLeft._x, topLeft._y, 0.0f); GL.Scale(mdlScale._x, mdlScale._y, 1.0f); GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line); GL.LineWidth(1); //Render texture coordinates as vertex points foreach (RenderInfo info in _renderInfo) { info.PrepareStream(); } }
internal unsafe void Render(TKContext ctx, ModelPanel mainWindow) { if (!_render) { return; } if (_boneColor != Color.Transparent) { GL.Color4(_boneColor.R / 255.0f, _boneColor.G / 255.0f, _boneColor.B / 255.0f, 1.0f); } else { GL.Color4(DefaultBoneColor.R / 255.0f, DefaultBoneColor.G / 255.0f, DefaultBoneColor.B / 255.0f, 1.0f); } //GL.LineWidth(1.0f); //Draw name if selected if (mainWindow != null && _nodeColor != Color.Transparent) { Vector3 pt = _frameMatrix.GetPoint(); Vector3 v2 = mainWindow.Project(pt); mainWindow.ScreenText[Name] = new Vector3(v2._x, v2._y - 9.0f, v2._z); } Vector3 v1 = (_parent == null || !(_parent is MDL0BoneNode)) ? new Vector3(0.0f) : ((MDL0BoneNode)_parent)._frameMatrix.GetPoint(); Vector3 v = _frameMatrix.GetPoint(); GL.Begin(BeginMode.Lines); GL.Vertex3((float *)&v1); GL.Vertex3((float *)&v); GL.End(); GL.PushMatrix(); fixed(Matrix *m = &_frameMatrix) GL.MultMatrix((float *)m); //Render node GLDisplayList ndl = ctx.FindOrCreate <GLDisplayList>("BoneNodeOrb", CreateNodeOrb); if (_nodeColor != Color.Transparent) { GL.Color4(_nodeColor.R / 255.0f, _nodeColor.G / 255.0f, _nodeColor.B / 255.0f, 1.0f); } else { GL.Color4(DefaultNodeColor.R / 255.0f, DefaultNodeColor.G / 255.0f, DefaultNodeColor.B / 255.0f, 1.0f); } ndl.Call(); DrawNodeOrients(); if (BillboardSetting != 0 && mainWindow != null) { Vector3 center = _frameMatrix.GetPoint(); Vector3 cam = mainWindow._camera.GetPoint(); Matrix m2 = new Matrix(); Vector3 scale = new Vector3(1); Vector3 rot = new Vector3(); Vector3 trans = new Vector3(); if (BillboardSetting == BillboardFlags.PerspectiveSTD) { rot = center.LookatAngles(cam) * Maths._rad2degf; } m2 = Matrix.TransformMatrix(scale, rot, trans); GL.PushMatrix(); GL.MultMatrix((float *)&m2); } if (BillboardSetting != 0 && mainWindow != null) { GL.PopMatrix(); } GL.PopMatrix(); //Render children foreach (MDL0BoneNode n in Children) { n.Render(ctx, mainWindow); } }
public static unsafe void RenderBGTexture(int width, int height, GLTexture texture, ref float[] points) { GLTexture bgTex = TKContext.FindOrCreate <GLTexture>("TexBG", CreateBG); bgTex.Bind(); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); //Draw BG float s = (float)width / (float)bgTex.Width, t = (float)height / (float)bgTex.Height; GL.Begin(BeginMode.Quads); GL.TexCoord2(0.0f, 0.0f); GL.Vertex2(0.0f, 0.0f); GL.TexCoord2(s, 0.0f); GL.Vertex2(1.0, 0.0f); GL.TexCoord2(s, t); GL.Vertex2(1.0, 1.0); GL.TexCoord2(0, t); GL.Vertex2(0.0f, 1.0); GL.End(); //Draw texture if ((texture != null) && (texture._texId != 0)) { float tAspect = (float)texture.Width / texture.Height; float wAspect = (float)width / height; if (tAspect > wAspect) //Texture is wider, use horizontal fit { points[0] = points[6] = 0.0f; points[2] = points[4] = 1.0f; points[1] = points[3] = ((height - ((float)width / texture.Width * texture.Height))) / height / 2.0f; points[5] = points[7] = 1.0f - points[1]; } else { points[1] = points[3] = 0.0f; points[5] = points[7] = 1.0f; points[0] = points[6] = (width - ((float)height / texture.Height * texture.Width)) / width / 2.0f; points[2] = points[4] = 1.0f - points[0]; } GL.BindTexture(TextureTarget.Texture2D, texture._texId); GL.Begin(BeginMode.Quads); GL.TexCoord2(0.0f, 0.0f); GL.Vertex2(points[0], points[1]); GL.TexCoord2(1.0f, 0.0f); GL.Vertex2(points[2], points[3]); GL.TexCoord2(1.0f, 1.0f); GL.Vertex2(points[4], points[5]); GL.TexCoord2(0.0f, 1.0f); GL.Vertex2(points[6], points[7]); GL.End(); } }
private unsafe void modelPanel1_PreRender(object sender, TKContext ctx) { if (RenderFloor) { GLTexture _bgTex = ctx.FindOrCreate<GLTexture>("TexBG", GLTexturePanel.CreateBG); float s = 10.0f, t = 10.0f; float e = 30.0f; GL.Disable(EnableCap.CullFace); GL.Disable(EnableCap.Blend); GL.Disable(EnableCap.Lighting); GL.PolygonMode(MaterialFace.Front, PolygonMode.Line); GL.PolygonMode(MaterialFace.Back, PolygonMode.Fill); GL.Enable(EnableCap.Texture2D); _bgTex.Bind(); GL.Color4(StaticMainWindow._floorHue); GL.Begin(BeginMode.Quads); GL.TexCoord2(0.0f, 0.0f); GL.Vertex3(-e, 0.0f, -e); GL.TexCoord2(s, 0.0f); GL.Vertex3(e, 0.0f, -e); GL.TexCoord2(s, t); GL.Vertex3(e, 0.0f, e); GL.TexCoord2(0, t); GL.Vertex3(-e, 0.0f, e); GL.End(); GL.Disable(EnableCap.Texture2D); } }
internal unsafe void Render(TKContext ctx, ModelPanel mainWindow) { if (!_render) return; if (_boneColor != Color.Transparent) GL.Color4(_boneColor.R / 255.0f, _boneColor.G / 255.0f, _boneColor.B / 255.0f, 1.0f); else GL.Color4(DefaultBoneColor.R / 255.0f, DefaultBoneColor.G / 255.0f, DefaultBoneColor.B / 255.0f, 1.0f); //GL.LineWidth(1.0f); //Draw name if selected if (mainWindow != null && _nodeColor != Color.Transparent) { Vector3 pt = _frameMatrix.GetPoint(); Vector3 v2 = mainWindow.Project(pt); mainWindow.ScreenText[Name] = new Vector3(v2._x, v2._y - 9.0f, v2._z); } Vector3 v1 = (_parent == null || !(_parent is MDL0BoneNode)) ? new Vector3(0.0f) : ((MDL0BoneNode)_parent)._frameMatrix.GetPoint(); Vector3 v = _frameMatrix.GetPoint(); GL.Begin(BeginMode.Lines); GL.Vertex3((float*)&v1); GL.Vertex3((float*)&v); GL.End(); GL.PushMatrix(); fixed (Matrix* m = &_frameMatrix) GL.MultMatrix((float*)m); //Render node GLDisplayList ndl = ctx.FindOrCreate<GLDisplayList>("BoneNodeOrb", CreateNodeOrb); if (_nodeColor != Color.Transparent) GL.Color4(_nodeColor.R / 255.0f, _nodeColor.G / 255.0f, _nodeColor.B / 255.0f, 1.0f); else GL.Color4(DefaultNodeColor.R / 255.0f, DefaultNodeColor.G / 255.0f, DefaultNodeColor.B / 255.0f, 1.0f); ndl.Call(); DrawNodeOrients(); if (BillboardSetting != 0 && mainWindow != null) { Vector3 center = _frameMatrix.GetPoint(); Vector3 cam = mainWindow._camera.GetPoint(); Matrix m2 = new Matrix(); Vector3 scale = new Vector3(1); Vector3 rot = new Vector3(); Vector3 trans = new Vector3(); if (BillboardSetting == BillboardFlags.PerspectiveSTD) rot = center.LookatAngles(cam) * Maths._rad2degf; m2 = Matrix.TransformMatrix(scale, rot, trans); GL.PushMatrix(); GL.MultMatrix((float*)&m2); } if (BillboardSetting != 0 && mainWindow != null) GL.PopMatrix(); GL.PopMatrix(); //Render children foreach (MDL0BoneNode n in Children) n.Render(ctx, mainWindow); }