User avatar
panik
Posts: 369
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands

Re: Creating 3D characters and making textures

Mon Oct 15, 2012 10:13 pm

Thank you, Narishma.

And correction: you'll need a [number_of_triangles*3*3] array of GLfloats. Three GLfloats (x,y,z) for each vertex, and three vertices for each triangle. Rookie mistake. Sorry about that.

Hardcheese
Posts: 36
Joined: Sat Sep 01, 2012 12:25 pm

Re: Creating 3D characters and making textures

Tue Oct 16, 2012 6:29 pm

I'm not sure whether you should see something immediately when you draw the vertices but I can't see anything at the moment. Here is the code I have been using:

Code: Select all

void draw_object(char *name, SHADER_T *shader)
{
char *memory = NULL;
size_t bytes = ObjLoadFile("enemy.obj", &memory); //Load the file into the memory specified.

ObjModel *model = ObjLoadModel(memory, bytes);
GLfloat *vertices = (GLfloat *)malloc(model->nTriangle * 3 * sizeof(GLfloat));

int index = 0;
while(index != model->nTriangle*3)
{
vertices[index] = (GLfloat)model->TriangleArray[index].Vertex[0]; index++;
vertices[index] = (GLfloat)model->TriangleArray[index].Vertex[1]; index++;
vertices[index] = (GLfloat)model->TriangleArray[index].Vertex[2]; index++;
}

shader_select(shader);
GLsizei count = model->nTriangle * 3;
glVertexAttribPointer(0, count, GL_FLOAT, GL_FALSE, 0, vertices);
glDrawArrays( GL_TRIANGLES, 0, count );

obj_free_resources(model); //Free the objects resources. 
}
All the vertices seem to load into the single array okay but there must be something going wrong because I can't see anything when I run the program.

User avatar
panik
Posts: 369
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands

Re: Creating 3D characters and making textures

Tue Oct 16, 2012 7:19 pm

Hard to say without knowing how you have set up the EGL context etcetera.

The example in /opt/vc/src/hello_pi/hello_triangle/hello_triangle.c is the simplest OpenGL ES 1 example I found of this. Mind: I'm not saying the example is simple, I'm only saying I haven't seen an example simpler than that. I'd love to be proven wrong on this, though.

You'll want to consider reading the .obj file from disk only once, and send the resulting array(s) to a draw-function to draw the model every frame. It looks like you're loading it in and throwing it away every frame now.

User avatar
hexelpdkk
Posts: 177
Joined: Fri Feb 24, 2012 4:40 pm

Re: Creating 3D characters and making textures

Tue Oct 16, 2012 7:25 pm

panik wrote: You'll want to consider reading the .obj from file from disk only once, and send the resulting array(s) to a draw-function to draw the model every frame. It looks like you're loading it in and throwing it away every frame now.
Even better, if possible, is to hold the data as a vbo on the gpu side, and just draw it every frame.

Hardcheese
Posts: 36
Joined: Sat Sep 01, 2012 12:25 pm

Re: Creating 3D characters and making textures

Tue Oct 16, 2012 7:29 pm

If you want to see my EGL set up then just download the Penguins Puzzle source I copied the EGL code from there. I'm not even sure whether I should be seeing something yet as I haven't dealt with textures yet (That'll be another complicated adventure). I modified part of the loop so all the data was stored in the array correctly. Thanks for all your replies. I hope I gain some ground on this problem eventually.

User avatar
panik
Posts: 369
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands

Re: Creating 3D characters and making textures

Tue Oct 16, 2012 7:36 pm

hexelpdkk wrote:Even better, if possible, is to hold the data as a vbo on the gpu side, and just draw it every frame.
That sounds great. I will move "look into vbo's" higher up in my priority list. Thanks!

@Hardcheese: You don't need textures initially. I think you can safely rule that out as being the problem. Good luck!

Return to “OpenGLES”