Adreno Sdk中Tutorials介绍

大家好,今天小白给大家简单介绍下,关于Adreno sdk中OpengGL ES 2.0和OpenGL ES 3.0相关的一些教程,方便大家尽快入手Adreno sdk.

一, OpengGL ES 2.0相关教程

1,教程所在路径:AdrenoSDK/Developement/Tutorials/OpenGLES/

01_CreateWindow  Shows how to use EGL to create an empty rendering window. 

02_ConfigureFrameBuffer  Shows how to configure the framebuffer for 16 and 32-bit displays. Detects the current resolution and configures the framebuffer accordingly. 

03_DrawTriangle  Shows how to render a triangle with a simple vertex and fragment shader. 

04_PortraitAndLandscape  Shows how to render geometry in landscape and portrait mode. Press the * key to change the orientation. 

05_NonInterleavedVBO  Shows how to use vertex buffer objects where each vertex attribute is stored in a seperate buffer. 

06_InterleavedVBO  Shows how to use interleaved vertex buffer objects. 

07_Transforms  Shows how to transform a 3D object with model, view, and projection matrix transforms. This program shows how to pass transforms into a shader program and use them in a vertex shader. 

08_SimpleTexture  Shows how to do simple texture mapping. 

09_CompressedTexture  Shows how to do texture mapping with the ATC compressed texture format. 

10_TextureProperties  Shows how to use various texture properties. 

11_MultiTexture  Shows how to do multi-texturing. It applies 2 textures to the object, a wood texture and a scrolling clouds texture on top of it. 

12_CubemapTexture  Shows how to use cubemap textures. 

13_CompressedVertices  Shows how to compress vertex data with 16-bit floats and the GL_INT_10_10_10_2 extension. 

14_StencilBuffer  Shows how to use the stencil buffer to limit render regions. 

15_RenderToTexture  Shows how to render to an offscreen texture using a frame buffer object. The scene is rendered to the color buffer and also to an offscreen texture. The texture is then displayed in the upper right corner. 

二, OpengGL ES 3.0相关教程

16_RenderToTexture30  Tutorial to show how to use FBOs to render to a texture using OpenGL ES 3.0. 

17_FBOTextureFormats30  Tutorial showing different texture formats when rendering to a simple texture using an FBO. 

18_InterleavedVBO-DrawArraysInstanced30  Tutorial showing how to render a simple quad using a vertex buffer object (VBO). This version uses glDrawArraysInstanced. 

19_InterleavedVBO-DrawRangeElements30  Tutorial showing how to render a simple quad using a vertex buffer object (VBO). This version uses glDrawRangeElements. 

20_Texture2DArray30  Tutorial showing how to render a simple quad using a vertex buffer object (VBO). This version uses glDrawArraysInstanced. 

21_PixelBufferObject30  Tutorial to show how to use pixel buffer objects. 

22_TransformFeedback30  Tutorial to show how to use transform feedback to return the number of rendered primitives.

23_BlitFramebuffer30  Tutorial to show how to blit from one framebuffer to another. 

24_MultisampleFramebuffer30  Tutorial showing how to use multiple framebuffers. 

25_FramebufferTextureLayer  Tutorial showing how to specify a single texture layer as the GL_COLOR_ATTACHMENT0 for a framebuffer object. 

三,03_DrawTriangle教程简介

该教程的主要目的是:演示如何使用简单的顶点和片段着色器渲染三角形,接下来看下源码:

1,选择03_DrawTriangle教程打开,里面有三个文件夹,分别是build, inc,src,其中build文件夹中是编译该例程的相关文件.2,inc文件中只有一个文件:Scene.h,类CSample的声明文件,继承自CFrmApplication,源码如下:

#ifndef SCENE_H
#define SCENE_H

//--------------------------------------------------------------------------------------
// Name: class CSample
// Desc: The main application class for this sample
//--------------------------------------------------------------------------------------
class CSample : public CFrmApplication
{
    
public:
    virtual BOOL Initialize();
    virtual BOOL Resize();
    virtual VOID Destroy();
    virtual VOID Update();
    virtual VOID Render();

    CSample( const CHAR* strName );

private:    

    BOOL InitShaders();

    const CHAR*  g_strWindowTitle;
    UINT32 g_nWindowWidth;
    UINT32 g_nWindowHeight;
    FLOAT  g_fAspectRatio;
    GLuint       g_hShaderProgram;
    GLuint       g_VertexLoc;
    GLuint       g_ColorLoc;
    CHAR* g_strFSProgram;
    CHAR* g_strVSProgram;
    FRMMATRIX4X4       m_matProj;
};

#endif // SCENE_H

3,src目录,里面是Scene.cpp文件,主要是类CSampl中相关方法的实现,源码如下:#include <FrmPlatform.h>
#define GL_GLEXT_PROTOTYPES
#include <EGL/egl.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <FrmApplication.h>
#include <OpenGLES/FrmShader.h>
#include "Scene.h"

#if defined(__linux__)
#include <stdio.h>
#include <unistd.h>
#endif

//--------------------------------------------------------------------------------------
// Name: FrmCreateApplicationInstance()
// Desc: Global function to create the application instance
//--------------------------------------------------------------------------------------
CFrmApplication* FrmCreateApplicationInstance()
{
    return new CSample( "DrawTriangle" );
}

//--------------------------------------------------------------------------------------
// Name: CSample()
// Desc: Constructor
//--------------------------------------------------------------------------------------
CSample::CSample( const CHAR* strName ) : CFrmApplication( strName )
{
    g_strWindowTitle = strName;
    g_nWindowWidth   = 765;
    g_nWindowHeight  = 480;
    g_fAspectRatio   = (FLOAT)g_nWindowWidth / (FLOAT)g_nWindowHeight;

    g_hShaderProgram = 0;
    g_VertexLoc = 0;
    g_ColorLoc  = 1;
}

//--------------------------------------------------------------------------------------
// Name: InitShaders()
// Desc: Initialize the shaders
//--------------------------------------------------------------------------------------
BOOL CSample::InitShaders()
{
    g_strVSProgram = 
    "attribute vec4 g_vVertex;                                             \n"
    "attribute vec4 g_vColor;                                             \n"
    "varying   vec4 g_vVSColor;                                          \n"
    "                                                                     \n"
    "void main()                                                         \n"
    "{                                                                     \n"
    "    gl_Position  = vec4( g_vVertex.x, g_vVertex.y,                  \n"
    "                         g_vVertex.z, g_vVertex.w );                \n"
    "    g_vVSColor = g_vColor;                                          \n"
    "}                                                                     \n";

    g_strFSProgram = 
    "#ifdef GL_FRAGMENT_PRECISION_HIGH                                     \n"
    "   precision highp float;                                             \n"
    "#else                                                                 \n"
    "   precision mediump float;                                         \n"
    "#endif                                                                 \n"
    "                                                                     \n"
    "varying   vec4 g_vVSColor;                                          \n"
    "                                                                     \n"
    "void main()                                                         \n"
    "{                                                                     \n"
    "    gl_FragColor = g_vVSColor;                                      \n"
    "}                                                                     \n";
    
    return TRUE;
}

//--------------------------------------------------------------------------------------
// Name: Initialize()
// Desc: 
//--------------------------------------------------------------------------------------
BOOL CSample::Initialize()
{

    InitShaders();

    // Create the shader program needed to render the texture
    {
        // Compile the shaders
        GLuint hVertexShader = glCreateShader( GL_VERTEX_SHADER );
        glShaderSource( hVertexShader, 1, &g_strVSProgram, NULL );
        glCompileShader( hVertexShader );

        GLuint hFragmentShader = glCreateShader( GL_FRAGMENT_SHADER );
        glShaderSource( hFragmentShader, 1, &g_strFSProgram, NULL );
        glCompileShader( hFragmentShader );

        // Check for compile success
        GLint nCompileResult = 0;
        glGetShaderiv(hFragmentShader, GL_COMPILE_STATUS, &nCompileResult);
        if (!nCompileResult)
        {
            CHAR Log[1024];
            GLint nLength;
            glGetShaderInfoLog(hFragmentShader, 1024, &nLength, Log);
            return FALSE;
        }

        // Attach the individual shaders to the common shader program
        g_hShaderProgram = glCreateProgram();
        glAttachShader( g_hShaderProgram, hVertexShader );
        glAttachShader( g_hShaderProgram, hFragmentShader );

        // Init attributes BEFORE linking
        glBindAttribLocation(g_hShaderProgram, g_VertexLoc, "g_vVertex");
        glBindAttribLocation(g_hShaderProgram, g_ColorLoc, "g_vColor");

        // Link the vertex shader and fragment shader together
        glLinkProgram( g_hShaderProgram );

        // Check for link success
        GLint nLinkResult = 0;
        glGetProgramiv(g_hShaderProgram, GL_LINK_STATUS, &nLinkResult);
        if (!nLinkResult)
        {
            CHAR Log[1024];
            GLint nLength;
            glGetProgramInfoLog(g_hShaderProgram, 1024, &nLength, Log);
            return FALSE;
        }

        glDeleteShader( hVertexShader );
        glDeleteShader( hFragmentShader );
    }

    return TRUE;
}

//--------------------------------------------------------------------------------------
// Name: Resize()
// Desc: 
//--------------------------------------------------------------------------------------
BOOL CSample::Resize()
{
    return TRUE;
}

//--------------------------------------------------------------------------------------
// Name: Destroy()
// Desc: 
//--------------------------------------------------------------------------------------
VOID CSample::Destroy()
{
    glDeleteProgram( g_hShaderProgram );
}

//--------------------------------------------------------------------------------------
// Name: Update()
// Desc: 
//--------------------------------------------------------------------------------------
VOID CSample::Update()
{
   return;
}

//--------------------------------------------------------------------------------------
// Name: Render()
// Desc: 
//--------------------------------------------------------------------------------------
VOID CSample::Render()
{
    FLOAT fSize = 0.5f;
    FLOAT VertexPositions[] =
    {
         0.0f,  +fSize*g_fAspectRatio, 0.0f, 1.0f,
        -fSize, -fSize*g_fAspectRatio, 0.0f, 1.0f,
        +fSize, -fSize*g_fAspectRatio, 0.0f, 1.0f,
    };

    FLOAT VertexColors[] = {1.0f, 0.0f, 0.0f, 1.0f,
                            0.0f, 1.0f, 0.0f, 1.0f,
                            0.0f, 0.0f, 1.0f, 1.0f
                           };

    // Clear the backbuffer and depth-buffer
    glClearColor( 0.0f, 0.0f, 0.5f, 1.0f );
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    // Set the shader program and the texture
    glUseProgram( g_hShaderProgram );

    // Draw the colored triangle
    glVertexAttribPointer( g_VertexLoc, 4, GL_FLOAT, 0, 0, VertexPositions );
    glEnableVertexAttribArray( g_VertexLoc );

    glVertexAttribPointer( g_ColorLoc, 4, GL_FLOAT, 0, 0, VertexColors);
    glEnableVertexAttribArray( g_ColorLoc );

    glDrawArrays( GL_TRIANGLE_STRIP, 0, 3 );

    glDisableVertexAttribArray( g_VertexLoc );
    glDisableVertexAttribArray( g_ColorLoc );

四,总结

本篇主要是简单介绍下Adreno sdk中OpenGL ES2.0/3.9相关的教程,以及03_DrawTriangle例程,欢迎一起交流学习.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值