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
#include "
Texture.h
"
22
23
#include <GLES2/gl2ext.h>
24
#include <cstdio>
25
#include <cstdlib>
26
#include <android/log.h>
27
28
#define LOG_TAG "libNative"
29
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
30
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
31
32
#define TEXTURE_WIDTH 256
33
#define TEXTURE_HEIGHT 256
34
#define CHANNELS_PER_PIXEL 3
35
36
GLubyte *
theTexture
;
37
38
/* [loadTexture] */
39
GLuint
loadTexture
()
40
{
41
static
GLuint
textureId
;
42
theTexture
= (GLubyte *)malloc(
sizeof
(GLubyte) *
TEXTURE_WIDTH
*
TEXTURE_HEIGHT
*
CHANNELS_PER_PIXEL
);
43
44
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
45
46
/* Generate a texture object. */
47
glGenTextures(1, &textureId);
48
49
/* Activate a texture. */
50
glActiveTexture(GL_TEXTURE0);
51
52
/* Bind the texture object. */
53
glBindTexture(GL_TEXTURE_2D, textureId);
54
55
FILE * theFile = fopen(
"/data/data/com.arm.malideveloper.openglessdk.normalmapping/files/normalMap256.raw"
,
"r"
);
56
57
if
(theFile == NULL)
58
{
59
LOGE
(
"Failure to load the texture"
);
60
return
0;
61
}
62
63
fread(
theTexture
,
TEXTURE_WIDTH
*
TEXTURE_HEIGHT
*
CHANNELS_PER_PIXEL
, 1, theFile);
64
65
/* Load the texture. */
66
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
TEXTURE_WIDTH
,
TEXTURE_HEIGHT
, 0, GL_RGB, GL_UNSIGNED_BYTE,
theTexture
);
67
68
/* Set the filtering mode. */
69
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
70
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
71
72
free(
theTexture
);
73
74
return
textureId
;
75
}
76
/* [loadTexture] */
TEXTURE_HEIGHT
#define TEXTURE_HEIGHT
Definition:
Texture.cpp:33
TEXTURE_WIDTH
#define TEXTURE_WIDTH
Definition:
Texture.cpp:32
loadTexture
void loadTexture(const char *texture, unsigned int level, unsigned int width, unsigned int height)
Loads a desired texture into memory at an appropriate mipmap level.
Definition:
Texture.cpp:35
theTexture
GLubyte * theTexture
Definition:
Texture.cpp:36
Texture.h
textureId
GLuint textureId
Definition:
Native.cpp:200
LOGE
#define LOGE(...)
Definition:
Texture.cpp:30
CHANNELS_PER_PIXEL
#define CHANNELS_PER_PIXEL
Definition:
Texture.cpp:34
GLuint
typedef GLuint(GL_APIENTRYP PFNGLGETDEBUGMESSAGELOGKHRPROC)(GLuint count
samples
tutorials
NormalMapping
jni
Texture.cpp
(C) ARM Ltd. 2017