public static PositionTextureVertexBuffer Create(PositionTexture[] data) { PositionTextureVertexBuffer buffer = new PositionTextureVertexBuffer(data.Length); buffer.verts = data; buffer.Unlock(); return(buffer); }
public void CleanUp() { if (vertexBuffer != null) { vertexBuffer = null; } //if (glyphCache != null) //{ // glyphCache.CleanUp(); // glyphCache = null; //} Items.Clear(); }
public void PrepareBatch() { if (glyphCache == null) { glyphCache = GlyphCache.GetCache(Height); } if (glyphCache.Ready == false) { return; } // Add All Glyphs //foreach (Text3d t3d in Items) //{ // foreach (char c in t3d.Text) // { // glyphCache.AddGlyph(c); // } //} //// Calculate Metrics TextObject.Text = ""; TextObject.FontSize = (float)Height * .50f; //System.Drawing.Font font = TextObject.Font; //StringFormat sf = new StringFormat(); //sf.Alignment = StringAlignment.Near; //Bitmap bmp = new Bitmap(20, 20); //Graphics g = Graphics.FromImage(bmp); //// Create Index Buffers List <PositionTexture> verts = new List <PositionTexture>(); foreach (Text3d t3d in Items) { String text = t3d.Text; float left = 0; float top = 0; float fntAdjust = TextObject.FontSize / 128f; float factor = .6666f; float width = 0; float height = 0; for (int i = 0; i < text.Length; i++) { GlyphItem item = glyphCache.GetGlyphItem(text.Substr(i, 1)); if (item != null) { width += (float)(item.Extents.X); height = Math.Max(item.Extents.Y, height); } } Vector2d size = Vector2d.Create(width, height); t3d.width = size.X * (float)t3d.scale * factor * fntAdjust; t3d.height = size.Y * (float)t3d.scale * factor * fntAdjust; int charsLeft = text.Length; for (int i = 0; i < charsLeft; i++) { GlyphItem item = glyphCache.GetGlyphItem(text.Substr(i, 1)); if (item != null) { Rectangle position = Rectangle.Create(left * (float)t3d.scale * factor, 0 * (float)t3d.scale * factor, item.Extents.X * fntAdjust * (float)t3d.scale * factor, item.Extents.Y * fntAdjust * (float)t3d.scale * factor); left += (float)(item.Extents.X * fntAdjust); //System.Diagnostics.Debug.WriteLine((position.Width/position1.Width).ToString() + ", " + (position.Height / position1.Height).ToString()); t3d.AddGlyphPoints(verts, item.Size, position, item.UVRect); } } } vertCount = verts.Count; vertexBuffer = new PositionTextureVertexBuffer(vertCount); PositionTexture[] vertBuf = (PositionTexture[])vertexBuffer.Lock(); // Lock the buffer (which will return our structs) for (int i = 0; i < vertCount; i++) { vertBuf[i] = verts[i]; } vertexBuffer.Unlock(); glyphVersion = glyphCache.Version; }
public void PrepareBatch() { if (glyphCache == null) { glyphCache = GlyphCache.GetCache(Height); } if (glyphCache.Ready == false) { return; } // Add All Glyphs //foreach (Text3d t3d in Items) //{ // foreach (char c in t3d.Text) // { // glyphCache.AddGlyph(c); // } //} //// Calculate Metrics TextObject.Text = ""; TextObject.FontSize = (float)Height * .50f; //System.Drawing.Font font = TextObject.Font; //StringFormat sf = new StringFormat(); //sf.Alignment = StringAlignment.Near; //Bitmap bmp = new Bitmap(20, 20); //Graphics g = Graphics.FromImage(bmp); //// Create Index Buffers List<PositionTexture> verts = new List<PositionTexture>(); foreach (Text3d t3d in Items) { String text = t3d.Text; Vector2d size = Vector2d.Create(1000,100); //g.MeasureString(text, font); float factor = .6666f; t3d.width = size.X * (float)t3d.scale * factor; t3d.height = size.Y * (float)t3d.scale * factor; float left = 0; float top = 0; float fntAdjust = TextObject.FontSize / 128f; int charsLeft = text.Length; for (int i = 0; i < charsLeft; i++) { GlyphItem item = glyphCache.GetGlyphItem(text.Substr(i,1)); Rectangle position = Rectangle.Create(left * (float)t3d.scale * factor, 0 * (float)t3d.scale * factor, item.Extents.X * fntAdjust * (float)t3d.scale * factor, item.Extents.Y * fntAdjust * (float)t3d.scale * factor); left += (float)(item.Extents.X * fntAdjust); //System.Diagnostics.Debug.WriteLine((position.Width/position1.Width).ToString() + ", " + (position.Height / position1.Height).ToString()); t3d.AddGlyphPoints(verts, item.Size, position, item.UVRect); } } vertCount = verts.Count; vertexBuffer = new PositionTextureVertexBuffer(vertCount); PositionTexture[] vertBuf = (PositionTexture[])vertexBuffer.Lock(); // Lock the buffer (which will return our structs) for (int i = 0; i < vertCount; i++) { vertBuf[i] = verts[i]; } vertexBuffer.Unlock(); glyphVersion = glyphCache.Version; }
private static void CreateGalaxyImage(RenderContext renderContext) { if (milkyWayImage == null) { milkyWayImage = Planets.LoadPlanetTexture("http://cdn.worldwidetelescope.org/webclient/images/milkywaybar.jpg"); } int subdivs = 50; double lat, lng; int index = 0; double latMin = 64; double latMax = -64; double lngMin = -64; double lngMax = 64; //// Create a vertex buffer galaxyImageVertexBuffer = new PositionTextureVertexBuffer((subdivs + 1) * (subdivs + 1)); PositionTexture[] verts = (PositionTexture[])galaxyImageVertexBuffer.Lock(); int x1, y1; double latDegrees = latMax - latMin; double lngDegrees = lngMax - lngMin; double scaleFactor = 60800000.0; double ecliptic = Coordinates.MeanObliquityOfEcliptic(SpaceTimeController.JNow) / 180.0 * Math.PI; Vector3d point; double textureStepX = 1.0f / subdivs; double textureStepY = 1.0f / subdivs; for (y1 = 0; y1 <= subdivs; y1++) { if (y1 != subdivs) { lat = latMax - (textureStepY * latDegrees * (double)y1); } else { lat = latMin; } for (x1 = 0; x1 <= subdivs; x1++) { if (x1 != subdivs) { lng = lngMin + (textureStepX * lngDegrees * (double)x1); } else { lng = lngMax; } index = y1 * (subdivs + 1) + x1; point = Vector3d.Create(lng * scaleFactor, 0, (lat - 28) * scaleFactor); point.RotateY(213.0 / 180 * Math.PI); point.RotateZ((-62.87175) / 180 * Math.PI); point.RotateY((-192.8595083) / 180 * Math.PI); point.RotateX(ecliptic); verts[index] = PositionTexture.CreatePosRaw(point, (float)(1f - x1 * textureStepX), (float)(/*1f - */ (y1 * textureStepY))); //verts[index].Position = point; //verts[index].Tu = (float)(1f - x1 * textureStepX); //verts[index].Tv = (float)(/*1f - */(y1 * textureStepY)); } } galaxyImageVertexBuffer.Unlock(); galaxyImageTriangleCount = (subdivs) * (subdivs) * 2; Uint16Array ui16array = new Uint16Array(subdivs * subdivs * 6); UInt16[] indexArray = (UInt16[])(object)ui16array; for (y1 = 0; y1 < subdivs; y1++) { for (x1 = 0; x1 < subdivs; x1++) { index = (y1 * subdivs * 6) + 6 * x1; // First triangle in quad indexArray[index] = (ushort)(y1 * (subdivs + 1) + x1); indexArray[index + 2] = (ushort)((y1 + 1) * (subdivs + 1) + x1); indexArray[index + 1] = (ushort)(y1 * (subdivs + 1) + (x1 + 1)); // Second triangle in quad indexArray[index + 3] = (ushort)(y1 * (subdivs + 1) + (x1 + 1)); indexArray[index + 5] = (ushort)((y1 + 1) * (subdivs + 1) + x1); indexArray[index + 4] = (ushort)((y1 + 1) * (subdivs + 1) + (x1 + 1)); } } galaxyImageIndexBuffer = Tile.PrepDevice.createBuffer(); Tile.PrepDevice.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, galaxyImageIndexBuffer); Tile.PrepDevice.bufferData(GL.ELEMENT_ARRAY_BUFFER, ui16array, GL.STATIC_DRAW); }