Path: blob/main_old/samples/gles1/SimpleTexture2D.cpp
2580 views
//1// Copyright 2018 The ANGLE Project Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4//56// Based on Simple_Texture2D.c from7// Book: OpenGL(R) ES 2.0 Programming Guide8// Authors: Aaftab Munshi, Dan Ginsburg, Dave Shreiner9// ISBN-10: 032150279510// ISBN-13: 978032150279711// Publisher: Addison-Wesley Professional12// URLs: http://safari.informit.com/978032156383513// http://www.opengles-book.com1415#include "SampleApplication.h"1617#include "texture_utils.h"18#include "util/gles_loader_autogen.h"19#include "util/shader_utils.h"2021class GLES1SimpleTexture2DSample : public SampleApplication22{23public:24GLES1SimpleTexture2DSample(int argc, char **argv)25: SampleApplication("GLES1SimpleTexture2D", argc, argv, 1, 0)26{}2728bool initialize() override29{30// Load the texture31mTexture = CreateSimpleTexture2D();3233glClearColor(0.0f, 0.0f, 0.0f, 0.0f);34glEnable(GL_TEXTURE_2D);3536return true;37}3839void destroy() override { glDeleteTextures(1, &mTexture); }4041void draw() override42{43GLfloat vertices[] = {44-0.5f, 0.5f, 0.0f, // Position 0450.0f, 0.0f, // TexCoord 046-0.5f, -0.5f, 0.0f, // Position 1470.0f, 1.0f, // TexCoord 1480.5f, -0.5f, 0.0f, // Position 2491.0f, 1.0f, // TexCoord 2500.5f, 0.5f, 0.0f, // Position 3511.0f, 0.0f // TexCoord 352};53GLushort indices[] = {0, 1, 2, 0, 2, 3};5455// Set the viewport56glViewport(0, 0, getWindow()->getWidth(), getWindow()->getHeight());5758// Clear the color buffer59glClear(GL_COLOR_BUFFER_BIT);6061// Load the vertex position62glVertexPointer(3, GL_FLOAT, 5 * sizeof(GLfloat), vertices);63// Load the texture coordinate64glTexCoordPointer(2, GL_FLOAT, 5 * sizeof(GLfloat), vertices + 3);6566glEnableClientState(GL_VERTEX_ARRAY);67glEnableClientState(GL_TEXTURE_COORD_ARRAY);6869// Bind the texture70glActiveTexture(GL_TEXTURE0);71glBindTexture(GL_TEXTURE_2D, mTexture);7273glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);74}7576private:77// Texture handle78GLuint mTexture = 0;79};8081int main(int argc, char **argv)82{83GLES1SimpleTexture2DSample app(argc, argv);84return app.run();85}868788