Path: blob/main_old/samples/gles1/DrawTexture.cpp
2578 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"16#include "texture_utils.h"17#include "util/shader_utils.h"18#include "util/test_utils.h"1920#include <GLES/gl.h>21#include <GLES/glext.h>2223class GLES1DrawTextureSample : public SampleApplication24{25public:26GLES1DrawTextureSample(int argc, char **argv)27: SampleApplication("GLES1DrawTexture", argc, argv, 1, 0, 1280, 800)28{}2930bool initialize() override31{32// Load the texture33mTexture = CreateSimpleTexture2D();3435glClearColor(0.0f, 0.0f, 0.0f, 0.0f);36glActiveTexture(GL_TEXTURE0);37glEnable(GL_TEXTURE_2D);3839glActiveTexture(GL_TEXTURE0);40glEnable(GL_TEXTURE_2D);41glBindTexture(GL_TEXTURE_2D, mTexture);4243GLint crop[4] = {0, 0, 2, 2};44glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);45glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);4647glViewport(0, 0, getWindow()->getWidth(), getWindow()->getHeight());4849return true;50}5152void destroy() override { glDeleteTextures(1, &mTexture); }5354void draw() override55{56glClear(GL_COLOR_BUFFER_BIT);5758GLint windowWidth = getWindow()->getWidth();59GLint windowHeight = getWindow()->getHeight();6061glDrawTexiOES(mX, mY, 0, mWidth, mHeight);62glDrawTexiOES(windowWidth - mX, mY, 0, mWidth, mHeight);63glDrawTexiOES(mX, windowHeight - mY, 0, mWidth, mHeight);64glDrawTexiOES(windowWidth - mX, windowHeight - mY, 0, mWidth, mHeight);6566mX += mReverseX ? -1 : 1;67mY += mReverseY ? -1 : 1;6869if (mX + mWidth >= windowWidth)70mReverseX = true;71if (mX < 0)72mReverseX = false;7374if (mY + mHeight >= windowHeight)75mReverseY = true;76if (mY < 0)77mReverseY = false;7879++mWidth;80++mHeight;81if (mWidth >= windowWidth)82mWidth = 0;83if (mHeight >= windowHeight)84mHeight = 0;8586angle::Sleep(16);87}8889private:90// Texture handle91GLuint mTexture = 0;9293// Draw texture coordinates and dimensions to loop through94GLint mX = 0;95GLint mY = 0;96GLint mWidth = 0;97GLint mHeight = 0;9899bool mReverseX = false;100bool mReverseY = false;101};102103int main(int argc, char **argv)104{105GLES1DrawTextureSample app(argc, argv);106return app.run();107}108109110