--- a/src/glplane.cpp 2013-12-07 13:57:26.410103736 +0100 +++ b/src/glplane.cpp 2013-12-18 18:46:33.193693194 +0100 @@ -8,20 +8,12 @@ "{ \n" " gl_FragColor = texture2D(sampler2d,myTexCoord); \n" "} \n";*/ - "#ifdef GL_FRAGMENT_PRECISION_HIGH \n" - " precision highp float; \n" - "#else \n" - " precision mediump float; \n" - "#endif \n" - " \n" "uniform sampler2D s_texture; \n" - "varying vec3 g_vVSColor; \n" - "varying vec2 g_vVSTexCoord; \n" + "varying mediump vec2 g_vVSTexCoord; \n" " \n" "void main() \n" "{ \n" - " gl_FragColor = texture2D(s_texture,g_vVSTexCoord.xy); \n" - + " gl_FragColor = texture2D(s_texture,g_vVSTexCoord); \n" "} \n"; @@ -44,17 +36,13 @@ "uniform mat4 g_matProj; \n" " \n" "attribute vec4 g_vPosition; \n" - "attribute vec3 g_vColor; \n" "attribute vec2 g_vTexCoord; \n" " \n" - "varying vec3 g_vVSColor; \n" "varying vec2 g_vVSTexCoord; \n" " \n" "void main() \n" "{ \n" - " vec4 vPositionES = g_matModelView * g_vPosition; \n" - " gl_Position = g_matProj * vPositionES; \n" - " g_vVSColor = g_vColor; \n" + " gl_Position = g_matProj * g_matModelView * g_vPosition;\n" " g_vVSTexCoord = g_vTexCoord; \n" "} \n"; @@ -392,10 +380,10 @@ //-------------------------------------------------------------------------------------- void GLPlane::PlaneSetTexBuf (uint8_t *texture_data, int w, int h) { + glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, _texture); - //glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, texture_data); glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, texture_data); - + glUniform1i(_s_texture_location, 0); } //-------------------------------------------------------------------------------------- @@ -470,24 +458,12 @@ // Pass the texture coordinates data glVertexAttribPointer (PLANE_TEXCOORD_ARRAY, 2, GL_FLOAT, 0, 0, texcoords); glEnableVertexAttribArray (PLANE_TEXCOORD_ARRAY); - - // enable depth test - glEnable (GL_DEPTH_TEST); - glDepthFunc (GL_LEQUAL); - glDepthMask (GL_TRUE); - - // cull backside of polygons - //glEnable(GL_CULL_FACE); - //glCullFace (GL_BACK); - glDisable(GL_CULL_FACE); - - // Binds this texture handle so we can load the data into it - //glBindTexture(GL_TEXTURE_2D, _texture); - /* Select Our Texture */ - glActiveTexture(GL_TEXTURE0); - //Select eglImage - glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, g_imgHandle); - + + + + + + glDrawArrays (GL_TRIANGLES, 0, 6); @@ -632,6 +608,7 @@ //-------------------------------------------------------------------------------------- GLuint GLPlane::GenTextures (void) { +#if 0 GLuint texture_id = 0; // Use tightly packed data @@ -639,8 +616,38 @@ // Allocates one texture handle glGenTextures (1, &texture_id); +#endif + + // Texture object handle + GLuint textureId; + + // 2x2 Image, 3 bytes per pixel (R, G, B) + GLubyte pixels[4 * 3] = + { + 255, 0, 0, // Red + 0, 255, 0, // Green + 0, 0, 255, // Blue + 255, 255, 0 // Yellow + }; + + // Use tightly packed data + glPixelStorei ( GL_UNPACK_ALIGNMENT, 1 ); + + // Generate a texture object + glGenTextures ( 1, &textureId ); + + // Bind the texture object + glBindTexture ( GL_TEXTURE_2D, textureId ); + + // Load the texture + glTexImage2D ( GL_TEXTURE_2D, 0, GL_RGB, 2, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels ); + + // Set the filtering mode + glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); + glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); + - return texture_id; + return textureId; } //-------------------------------------------------------------------------------------- @@ -654,10 +661,10 @@ _texture_h = texture_h; _texture = GenTextures (); - +#if 0 glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - +#endif return; } @@ -765,7 +772,7 @@ // Get uniform locations _modelview_location = glGetUniformLocation (_shader_program, "g_matModelView"); _projview_location = glGetUniformLocation (_shader_program, "g_matProj"); - + _s_texture_location = glGetUniformLocation (_shader_program, "s_texture"); return true; }