SHARPGL Study Notes (17) stereoscopic text and flat text

Source: Internet
Author: User

Before writing about the subject of the text, the author read a few books on the relevant chapters, study a few days without fruit.

Xu Mingliang, "OpenGL Game Programming" describes "bitmap fonts", that is, the font is rasterized, and then drawn. According to the VC code in the book translated into C #, suddenly stuck in a Windows API, Wglusefontbitmpas () above, this function to pass to a DC, miserable, do not know how to engage.

Another book on the text-related chapters introduced similar to the picture map, loading the text texture picture, because its code used a game frame, as I need to study the whole framework is how to work, try it is not easy to understand, so two days to consume in.

Today, suddenly think of reading the SHARPGL of the demo, suddenly found that the text output so simple, do not understand the above two books on how to make so complex!

What's going on? Is OpenGL a new version of the function that provides support for text? Or is SHARPGL's unique support?

I feel like the following method is enough to fix all the text-related applications, it is still to save some energy, skip the text chapters of the book!

However, it is a bit regrettable that the following code does not support Chinese, which may be a problem. Later know how to make Chinese, the author will continue to write a post.

Text Demo Code:

1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.ComponentModel;4 usingSystem.Data;5 usingSystem.Drawing;6 usingSystem.Linq;7 usingSystem.Text;8 usingSystem.Windows.Forms;9 usingSHARPGL;Ten usingSystem.Runtime.InteropServices; One  A namespaceSharpGLWinformsApplication1 - { -// the      Public Partial classSharpglform:form -     { -         Private floatrotation =0.0f; -         +          PublicSharpglform () -         { + InitializeComponent (); A         } at  -         Private voidOpenglcontrol_opengldraw (Objectsender, PaintEventArgs e) -         { -OpenGL gl =Openglcontrol.opengl; -Gl. Clear (Opengl.gl_color_buffer_bit |opengl.gl_depth_buffer_bit); - GL. Loadidentity (); in  -Gl. Translate ( -1f,0.0f, 0f); toGl. Rotate (rotation, 1f, 0f,0.0f); +  -Gl. Drawtext3d ("Arial", +,0,0.3f,"hello!"); the  *Rotation-=3.0f; $ Panax NotoginsengGl. DrawText ( -, -,1, -                 1,1,"Courier New", A, the                 "This is a test text."); + GL. Flush (); A         } the  +         Private voidOpenglcontrol_openglinitialized (Objectsender, EventArgs e) -         { $OpenGL gl =Openglcontrol.opengl; $  -             float[] Global_ambient =New float[] {0.5f,0.5f,0.5f,1.0f }; -             float[] Light0pos =New float[] {0.0f,0.0f,10.0f,1.0f }; the             float[] Light0ambient =New float[] {0.2f,0.2f,0.2f,1.0f }; -             float[] Light0diffuse =New float[] {0.9f,0.9f,0.3f,1.0f };Wuyi             float[] Light0specular =New float[] {0.8f,0.8f,0.8f,1.0f }; the  -             float[] Lmodel_ambient =New float[] {0.2f,0.2f,0.2f,1.0f }; Wu GL. Lightmodel (Opengl.gl_light_model_ambient, lmodel_ambient); -  About GL. Lightmodel (Opengl.gl_light_model_ambient, global_ambient); $ GL. Light (Opengl.gl_light0, opengl.gl_position, light0pos); - GL. Light (Opengl.gl_light0, opengl.gl_ambient, light0ambient); - GL. Light (Opengl.gl_light0, Opengl.gl_diffuse, light0diffuse); - GL. Light (Opengl.gl_light0, opengl.gl_specular, light0specular); A GL. Enable (opengl.gl_lighting); + GL. Enable (opengl.gl_light0); the  - GL.        Shademodel (Opengl.gl_smooth);  $Gl. Clearcolor (0,0,0,0); the         } the  the         Private voidOpenglcontrol_resized (Objectsender, EventArgs e) the         { -OpenGL gl =Openglcontrol.opengl; in GL. Matrixmode (opengl.gl_projection); the GL. Loadidentity (); theGl. Perspective (60.0f, (Double) Width/(Double) Height,0.01,100.0); AboutGl. LookAt (0,0,3,0,0,0,0,1,0); the GL. Matrixmode (Opengl.gl_modelview); the         } the  +  -     } the Bayi}

Effects such as:

The three-dimensional text is "hello!", the flat text is "The is a Test text"

Put GL. Drawtext3d ("Arial", 0, 0.3f, "hello!"); In the 0.3 to 0, you can get a depth of 0 text, equivalent to a slice.

Flat text is used to output hint text, it cannot be rotated, and the output is positioned in pixels.

The example is very simple, let the author unexpectedly so quickly end the topic of text.

This section source code download

Original article, from "Blog Park, pig awareness can ' s blog": http://www.cnblogs.com/hackpig/

SHARPGL Study Notes (17) stereoscopic text and flat text

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.