Mapping texture to one side of cube

Problems with Canvas, OpenGL, etc...

Mapping texture to one side of cube

Postby Ghost » Fri Jul 08, 2011 9:27 pm

Hi,
sorry if I missed it, but I couldn't find any related topic, so I created this thread.
I want to create a black cube with texture on only one side.

Here's my current data:
Code: Select all
   // Board vertices.
   private float[] vertices = {
         -3.0f, 0.1f, 2.0f, // 0
         -3.0f, -0.1f, 2.0f, // 1
         3.0f, -0.1f, 2.0f, // 2
         3.0f, 0.1f, 2.0f, // 3
         3.0f, -0.1f, -2.0f, // 4
         3.0f, 0.1f, -2.0f, // 5
         -3.0f, -0.1f, -2.0f, // 6
         -3.0f, 0.1f, -2.0f, // 7
   };
   
   // Board indices.
   private short[] indices = {
         0, 1, 2,
         0, 2, 3,
         3, 2, 4,
         3, 4, 5,
         5, 4, 6,
         5, 6, 7,
         7, 1, 0,
         7, 6, 1,
         7, 0, 3,
         7, 3, 5,
         6, 2, 1,
         6, 4, 2,
   };
   // UV coordinates.
   private float[] uvCoordinates = {
         0.0f, 1.0f, // 0
         0.0f, 0.0f, // 1
         0.0f, 0.0f, // 2
         1.0f, 1.0f, // 3
         0.0f, 0.0f, // 4
         1.0f, 0.0f, // 5
         0.0f, 0.0f, // 6
         0.0f, 0.0f, // 7
   };

As you can see, I have exact same amount of UV coordinates as I have vertices.
Currently this renders texture where I want it to, but also renders some garbage around cube.
Can anyone tell me if there's some other way around?
Figured that creating different plane would require more resources, which I already lack :?
Ghost
Developer
Developer
 
Posts: 26
Joined: Fri Feb 11, 2011 2:50 pm

Top

Re: Mapping texture to one side of cube

Postby theRet » Sun Jul 10, 2011 8:59 pm

My knowledge of OGL is somewhat limited but

4 indices per side of a cube x 8 sides of a cube = 32 incidies
I counted 36.

If the additional 4 are indices for the mesh than I think you need to make a separate array or constrain your indexing.

Hope this helps.
theRet
Freshman
Freshman
 
Posts: 6
Joined: Sun Jul 10, 2011 8:53 pm

Re: Mapping texture to one side of cube

Postby Ghost » Mon Jul 11, 2011 6:05 pm

theRet wrote:My knowledge of OGL is somewhat limited but

4 indices per side of a cube x 8 sides of a cube = 32 incidies
I counted 36.

If the additional 4 are indices for the mesh than I think you need to make a separate array or constrain your indexing.

Hope this helps.

I'm a little confused. Cube has x6 sides, 8 vertices. To have one side I need to use 6 indices, so 6x6 equals 36.
How do I make this array smaller?

There's nothing additional, only cube.

What does it mean to constrain my indexing? And how should I go implementing separate array?
I'm new to openGL, so these things you mentioned are very interesting, I would really like to know more.
BTW, thanks for the post, because I started to think that everyone on this forum went on vacation :D
Ghost
Developer
Developer
 
Posts: 26
Joined: Fri Feb 11, 2011 2:50 pm

Re: Mapping texture to one side of cube

Postby theRet » Tue Jul 12, 2011 4:17 am

I apologize for the mistake on the number of sides of a cube, but what I was working at was something similar to whats laid out in http://www.songho.ca/opengl/gl_vertexarray.html.

You have eight vertices, but use them 36 times in your indices array (which I am assuming you pass to be rendered. At most you need to use [4 corners] x [6 sides] indices. = 24 indices needed. (I apologize for the hasty side counting)

By constraining your array I meant something like do not pass the whole thing (however one would go about implementing that, but there are ways I'm sure)

That's the extent of what I can really conclude w/ my limited experience in OpenGL (and 3d programming in general) without seeing more of your code. I hope that helps.

PS. I just found this board the other day, and am getting an Optimus M this weekend (100bucks at "Big Buy" ;) I am going to be visiting here as much as I can. Hope to get a developer blog running at some point w/ some coding tutorials and practical advice with what little I do have to offer. Cya round the boards :)
theRet
Freshman
Freshman
 
Posts: 6
Joined: Sun Jul 10, 2011 8:53 pm

Re: Mapping texture to one side of cube

Postby Ghost » Wed Jul 13, 2011 7:36 am

I would like to read your tuts, fill me in, when they ar ready ;)
BTW, from the page you showed I can see, that the code uses Begin() and End(). I'm not sure if android supports it.
Also, in the code, they draw quads, instead of triangles, so on one quad they need only 4 indices (openGL does the rest), but on android there are no such calls, so you havo to use whole buffer and thus 6 indices for one quad.
Please correct me if I am wrong, because I'm new to openGL and might be misunderstanding things. :)
Ghost
Developer
Developer
 
Posts: 26
Joined: Fri Feb 11, 2011 2:50 pm

Re: Mapping texture to one side of cube

Postby theRet » Wed Jul 13, 2011 8:18 am

Hi Ghost. I apologize for my shortsightedness. I know so little about OpenGL ES that I assumed it rendered much as PC platforms do.

I have yet to dive into the OpenGL ES documentation because I wont have my Optimus for a few days yet (and I've been avoiding the emulator like the plague) but once I do I hope I can port some of my knowledge of matrix transforms and other 3-d based stuff to the Andriod development community at large.

As it stands there appears to be a lack in hobby-enthusiasm regarding Opengl ES (as evident by the lack of people that frequent this particular sub-forum). =( But we're gonna change that!
theRet
Freshman
Freshman
 
Posts: 6
Joined: Sun Jul 10, 2011 8:53 pm

Top

Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: No registered users and 4 guests