27 #include <GLES3/gl3.h>
36 using namespace Skybox;
75 GL_CHECK(glShaderSource(shader, 1, &shader_source, NULL));
80 GL_CHECK(glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled));
82 if (compiled != GL_TRUE)
86 GL_CHECK(glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &info_len));
90 char* log_buffer = NULL;
94 GL_CHECK(glGetShaderInfoLog(shader, info_len, NULL, log_buffer));
95 LOGE(
"Could not compile shader 0x%x:\n%s\n", shader_type, log_buffer);
118 GL_CHECK(glAttachShader(program, vertexShader));
119 GL_CHECK(glAttachShader(program, fragmentShader));
122 GLint linkStatus = GL_FALSE;
124 GL_CHECK(glGetProgramiv(program, GL_LINK_STATUS, &linkStatus));
126 if (linkStatus != GL_TRUE)
128 GLint buf_length = 0;
130 GL_CHECK(glGetProgramiv(program, GL_INFO_LOG_LENGTH, &buf_length));
134 char* log_buffer = NULL;
137 GL_CHECK(glGetProgramInfoLog(program, buf_length, NULL, log_buffer));
138 LOGE(
"Could not link program:\n%s\n", log_buffer);
150 LOGE(
"Error creating program object.");
163 const char resource_directory[] =
"/data/data/com.arm.malideveloper.openglessdk.skybox/files/";
166 char file_name[] =
"/data/data/com.arm.malideveloper.openglessdk.skybox/files/greenhouse_skybox-0.ppm";
171 GL_TEXTURE_CUBE_MAP_POSITIVE_X,
172 GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
173 GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
174 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
175 GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
176 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
184 GL_CHECK(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
185 GL_CHECK(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
186 GL_CHECK(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
187 GL_CHECK(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
188 GL_CHECK(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE));
194 GL_CHECK(glTexStorage2D(GL_TEXTURE_CUBE_MAP,
200 for (
int n_face = 0; n_face <
sizeof(cubemap_faces) /
sizeof(cubemap_faces[0]); n_face++)
204 sprintf(file_name,
"/data/data/com.arm.malideveloper.openglessdk.skybox/files/greenhouse_skybox-%d.ppm", n_face);
209 GL_CHECK(glTexSubImage2D(cubemap_faces[n_face],
232 GL_CHECK(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
273 if (fabs(
roll) >= 360.0
f)
285 if (fabs(
pitch) >= 360.0
f)
297 if (fabs(
yaw) >= 360.0
f)
311 GL_CHECK(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
void cleanup_graphics(void)
Perform graphics clean-up actions.
void setup_graphics(int width, int height)
#define MALLOC_CHECK(ptr_type, ptr, size)
Functions for drawing text in OpenGL ES.
ImageFile load_ppm_file(const char *ppm_file_name)
GLuint load_shader(GLenum shader_type, const char *shader_source)
Create shader object and compile its source code.
void clear(void)
Removes the current string from the class.
GLint GLsizei GLsizei height
void draw(void)
Draw the text to the screen.
unsigned int window_width
const string resource_directory("/data/data/com.arm.malideveloper.openglessdk.astctextures/files/")
const char skybox_vertex_shader_source[]
Quaternion multiply_quaternions(Quaternion a, Quaternion b)
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_skybox_NativeLibrary_init(JNIEnv *, jobject, jint width, jint height)
const char skybox_fragment_shader_source[]
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_skybox_NativeLibrary_uninit(JNIEnv *, jobject)
Quaternion construct_quaternion(float x, float y, float z, float degs)
Struct representing texture image.
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_skybox_NativeLibrary_step(JNIEnv *, jobject)
float model_view_matrix[16]
void render_frame(void)
Renders a single frame.
void construct_modelview_matrix(Quaternion quaternion, float *mat)
GLuint create_program(const char *vertex_source, const char *fragment_source)
Create program object, attach vertex and fragment shader to it. Link program object and check whether...
typedef GLfloat(GL_APIENTRYP PFNGLGETPATHLENGTHNVPROC)(GLuint path
typedef GLenum(GL_APIENTRYP PFNGLGETGRAPHICSRESETSTATUSKHRPROC)(void)
unsigned int window_height
typedef GLuint(GL_APIENTRYP PFNGLGETDEBUGMESSAGELOGKHRPROC)(GLuint count
void addString(int xPosition, int yPosition, const char *string, int red, int green, int blue, int alpha)
Add a std::string to be drawn to the screen.