Jump to content
  • Advertisement
Sign in to follow this  
blubberbert

OpenGL texturing problem on android OpenGL ES

This topic is 2846 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi, im trying to write a simple texturing app for my android 2.2 device...
im using JNI and c++ because i dont like java ( :D )
i use hardcoded texture pixel values
because i cant get loading from file to work ;(

here is some of my code:

glGenTextures(1, &texture);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
GLubyte pixels[64] = { 255, 0, 0, 255,
255, 0, 0, 255,
255, 0, 0, 255,
255, 0, 0, 255,
0, 255, 0, 255,
0, 255, 0, 255,
0, 255, 0, 255,
0, 255, 0, 255,
0, 0, 255, 255,
0, 0, 255, 255,
0, 0, 255, 255,
0, 0, 255, 255,
255, 255, 0, 255,
255, 255, 0, 255,
255, 255, 0, 255,
255, 255, 0, 255 };
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
glBindTexture(GL_TEXTURE_2D, 0);



for texture setup and

const GLfloat vertices[] = {
-1.0f,-1.0f, 1.0f,
1.0f,-1.0f, 1.0,
1.0f, 1.0f, 1.0f,
-1.0f, 1.0f, 1.0f };
const GLfloat texCoords[] = {
0.0f, 0.0f,
1.0f, 0.0f,
1.0f, 1.0f,
0.0f, 1.0f };
const GLubyte indices[] = {
0, 1, 2,
0, 2, 3 };

void renderFrame()
{
.......

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture);

glVertexAttribPointer(positionHandle, 3, GL_FLOAT, GL_FALSE, 0, vertices);
glEnableVertexAttribArray(positionHandle);
glVertexAttribPointer(texCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, texCoords);
glEnableVertexAttribArray(texCoordHandle);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, indices);
}



for drawing.
the texture gets displayed but the colors are wrong:
instead of something like this:

RRRR
GGGG
BBBB
YYYY
(Red, Green, Blue, Yellow)
the picture looks more like this:

OYYBB
OYBGB
YBGGG
YGRRR

(Orange)

it looks like a rainbow coming from the bottom left corner...(i havent figured out how to do screen shots, and the emulator doesnt seem to be working for me
xD)

EDIT: i fixed the problem, it was some stupid thing in my shader (i normalized the texcoord-vector :P)

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!