OpenGL ES SDK for Android
ARM Developer Center
Home
Pages
Namespaces
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
Texture.cpp
Go to the documentation of this file.
1
/* Copyright (c) 2013-2017, ARM Limited and Contributors
2
*
3
* SPDX-License-Identifier: MIT
4
*
5
* Permission is hereby granted, free of charge,
6
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
7
* to deal in the Software without restriction, including without limitation the rights to
8
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
9
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10
*
11
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
12
*
13
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
14
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
*/
20
21
/* [includeTextureDefinition] */
22
#include "
Texture.h
"
23
24
#include <GLES2/gl2ext.h>
25
#include <cstdio>
26
#include <cstdlib>
27
28
GLuint
loadSimpleTexture
()
29
{
30
/* Texture Object Handle. */
31
GLuint
textureId
;
32
33
/* 3 x 3 Image, R G B A Channels RAW Format. */
34
GLubyte
pixels
[9 * 4] =
35
{
36
18, 140, 171, 255,
/* Some Colour Bottom Left. */
37
143, 143, 143, 255,
/* Some Colour Bottom Middle. */
38
255, 255, 255, 255,
/* Some Colour Bottom Right. */
39
255, 255, 0, 255,
/* Yellow Middle Left. */
40
0, 255, 255, 255,
/* Some Colour Middle. */
41
255, 0, 255, 255,
/* Some Colour Middle Right. */
42
255, 0, 0, 255,
/* Red Top Left. */
43
0, 255, 0, 255,
/* Green Top Middle. */
44
0, 0, 255, 255,
/* Blue Top Right. */
45
};
46
/* [includeTextureDefinition] */
47
48
/* [placeTextureInMemory] */
49
/* Use tightly packed data. */
50
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
51
52
/* Generate a texture object. */
53
glGenTextures(1, &textureId);
54
55
/* Activate a texture. */
56
glActiveTexture(GL_TEXTURE0);
57
58
/* Bind the texture object. */
59
glBindTexture(GL_TEXTURE_2D, textureId);
60
61
/* Load the texture. */
62
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 3, 3, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
63
64
/* Set the filtering mode. */
65
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
66
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
67
68
return
textureId
;
69
}
70
/* [placeTextureInMemory] */
Texture.h
pixels
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum GLenum const void * pixels
Definition:
gl2ext.h:572
textureId
GLuint textureId
Definition:
Native.cpp:200
loadSimpleTexture
GLuint loadSimpleTexture()
Loads a simple 3 x 3 static texture into OpenGL ES.
Definition:
Texture.cpp:28
GLuint
typedef GLuint(GL_APIENTRYP PFNGLGETDEBUGMESSAGELOGKHRPROC)(GLuint count
samples
tutorials
TextureCube
jni
Texture.cpp
(C) ARM Ltd. 2017