Using Unityengine;Using System.Collections;public class Drawrectangle:monobehaviour {Public Color rectcolor = Color.green;Private Material Rectmat = null;//Draw line material does not set the system will be the current material draw line results are not controllableUse this for initializationvoid Start () {Rectmat = new Material ("Shader \" lines/colored blended\ "{" +"Subshader {Pass {" +"Blend srcalpha Oneminussrcalpha" +"Zwrite off cull off Fog {Mode off}" +"Bindchannels {" +"Bind \" vertex\
); requestwindowfeature (window. feature_no_title); // remove the title glsurfaceview glview = new glsurfaceview (this); // create a glsurfaceview mcuberenderer = new cuberenderer (); glview. setrenderer (mcuberenderer); setcontentview (glview );}}
Next, we will create a cuberenderer that inherits the Renderer interface. Renderer is an interface dedicated to 3D rendering. To inherit from it, we need to overload the following methods:
Public void ondrawframe (gl10
. This is the difference from the previous lesson. Easy! But because we need to make more colors here and the triangle vertices also become more, we need to use initbuffers to process more vertices and colors. Therefore, apart from the above changes, we also need to add the following code in the buffer to adapt to changes:
Gl. bindbuffer (GL. array_buffer, pyramidvertexpositionbuffer );
vertex coordinates to the floating point CacheTriangleVB. position (0); // read the first coordinate in the cache.}Public void draw (GL10 gl){Gl. glColor4f (0.64251875f, 0.76953125f, 0.22265625f, 0.0f); // you can specify the current color.Gl. glVertexPointer (3, GL10.GL _ FLOAT, 0, triangleVB); // set the vertexGl. glDrawArrays (GL10.
geometric images. In Android, SurfaceView is generally used to draw 2D images, while GLSurfaceView is used to display 3D OpenGL views, and 3D images are rendered through the Renderer interface. Therefore, we first establish a class that implements the Renderer interface. The Code has a detailed note: [java] public class GLRender implements Renderer {private float rotateTri; private int one = 0x10000; // a vertex of the triangle private IntBuffer triggerBuffer = BufferUtil. fBuffer (new int [] {
shader and assign the color of the Texel to the element. 3.gl.createtexture () Create a texture object to store the texture image. 4.gl.deletetexture () Use Textur to delete a texture object. If you delete a texture object that has been deleted, no error will be made and no effect will occur. 5.gl.pixelstorei (pname, param) Handles the loaded image in the way specified by PName and Param. Parameters PName: Can be one of the following. Gl. UNPACK_FLIP
members in the main window class:Private Static thread thrdraw;Then define a private class member functionPrivate void opengl_start (){While (true){This. View. Refresh ();}}Add the following in the form_load method:Code, Start thread:Threadstart start = new threadstart (opengl_start );Thrdraw = new thread (start );Thrdraw. Start ();Exit the thread in the dispose method of the Main WindowThrdraw. Abort ();
Create a class inherited from openglcontrol: myviewUsing csgl. OpenGL;
Public class myv
coordinate system. The general OpenGL program is the standard Cartesian coordinate system, that is, the lower left corner is the origin, X is horizontally right, and Y is vertically extended. Like the famous cocos2d engine, this method is used. I prefer another method of describing the origin in the upper left corner, so this set of coordinate system is used:
The Renderer of glsurfaceview provides three interfaces: drawing when the size is changed during creation. The operations we take in the
. Enable vertex Buffering
Gl. glableclientstate (GL10.GL _ VERTEX_ARRAY); // OpenGLDocs.
// Specifies the location and data format of an array of vertex
// Coordinates to use when rendering. Specify the vertex position
Gl. glVertexPointer (3, GL10.GL _ FLOAT, 0, vertexBuffer); // OpenGLDocs.
When you are done with the
rendered.How to set the texture parameters
First of all, look at the texture parameter setting method, set the texture parameters using the Texparameteri function, this function through three parameters to set the texture parameters.It is important to note that the texture parameters set here are only for textures that are bound at this point in time, while other textures in WebGL are unaffected.
Examples of use of >texparameteri
Gl.texparameteri (GL
:// Create a framebuffer var fb = gl.createframebuffer (); // bind FB as the current window Gl.bindframebuffer (GL. FRAMEBUFFER,FB);In this way, we create a new buffer that can be drawn, and it is not displayed.But will that be all right? The idea is to render the texture after the shader rendering and hand it over to the next shader, when the method is introduced framebuffertexture2d
Reference from "OpenGL ES Reference Pages about Framebuffert
compute Gl-matrix.js).
As with OpenGL, we want to initialize the usage environment and extract some of the global usage. The relevant code is as follows:
Class
var gl;//webglrenderingcontext var cubevbo;//cube buffer ID var spherevbo;//sphere vbo var sphereebo;//sphere ebo var cubetexid;//li Square Texture ID var fbobuffer;//frame cache object var glcubeprogram;//cube shader apply var glsphereprogra
(Draft only, not sorted)
Chapter 2
2 OpenGL ES running
2.1 Basic Principle of OpenGL ES
OpenGL ES (later called "Gl") is only concerned with rendering in the frame cache (and Reading saved values from the frame cache ). In some cases, peripheral devices related to graphic hardware, such as the mouse and keyboard, are not supported. Programmers must rely on other mechanisms to obtain input information, such as khronos openkodeapi.
The basic elements o
is not required for non-network graphs
Struct EdgeNode * next; // link field, pointing to the next adjacent point
} EdgeNode;
Typedef struct VertexNode {// vertex table Node
VertexType data; // vertex domain, storing vertex Information
Int in; // stores the number of vertex inputs.
EdgeNode * firstEdge; // edge header pointer
} VertexNode;
Typedef struct Edge {// Number of Edge Sets
Int u, v; // arc tail and arc H
Public class glsurfaceviewactivity extends activity {Private myglsurfaceview mglsurfaceview;/** Called when the activity is first created .*/@ OverridePublic void oncreate (bundle savedinstancestate ){Super. oncreate (savedinstancestate );Mglsurfaceview = new myglsurfaceview (this );Setcontentview (mglsurfaceview );// Setcontentview (R. layout. Main );}}Public class myglsurfaceview extends glsurfaceview {Private myglrenderer mrender;Public myglsurfaceview (context ){Super (context );// Todo auto
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.