Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 4, 2013, 03:14 PM   #1
jackal123uk
macrumors member
 
Join Date: Jan 2007
Location: England
Combining vetrex and normal ma in GLKit

OK, firstly, I'm still a beginner - especially at openGL - so apologies for any stupid questions or if I've overlooked something simple.

I'm adding a view to my app which loads a 3D model (originally built in blender) that can be rotated, zoomed and panned. I've tried unsuccessfully with a few different methods but here's what I've got so far:

- Export .obj model from blender
- Converted .obj file to .h using obj2opengl.pl script
- substitute the above .h file into Xcode's OpenGL game template and add touch recognisers for arcball rotation etc.

Everything works fine except for it only displays a wireframe model. Looking through the code I see default model data used by the template combines vertex and normal data in a single matrix whereas the converted .h file I'm using hold them in two separate matrices - I'm guessing this is the problem and the easiest fix is to combine the data into a single matrix but I find an appropriate command to do such a thing. Is it even possible?

The other option is to load the normal data separately but this to escapes me also. Below is the code I'm using for the drawing - cvsaVerts is the vertex matrix and cvsaNormals (not used yet) is the normal matrix.

Code:
- (void)setupGL
{
    [EAGLContext setCurrentContext:self.context];
    
    [self loadShaders];
    
    self.effect = [[GLKBaseEffect alloc] init];
    self.effect.light0.enabled = GL_TRUE;
    self.effect.light0.diffuseColor = GLKVector4Make(1.0f, 0.4f, 0.4f, 1.0f);
    
    glEnable(GL_DEPTH_TEST);
    
    glGenVertexArraysOES(1, &_vertexArray);
    glBindVertexArrayOES(_vertexArray);
    
    glGenBuffers(1, &_vertexBuffer);
    glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
    
    //default data
    //glBufferData(GL_ARRAY_BUFFER, sizeof(gCubeVertexData), gCubeVertexData, GL_STATIC_DRAW);
    
    //from .h file
    glBufferData(GL_ARRAY_BUFFER, sizeof(cvsaVerts), cvsaVerts, GL_STATIC_DRAW);
    
    glEnableVertexAttribArray(GLKVertexAttribPosition);
    glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, 24, BUFFER_OFFSET(0));
    glEnableVertexAttribArray(GLKVertexAttribNormal);
    glVertexAttribPointer(GLKVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, 24, BUFFER_OFFSET(12));
    
    glBindVertexArrayOES(0);
}
jackal123uk is offline   0 Reply With Quote
Old Jan 10, 2013, 02:57 PM   #2
jackal123uk
Thread Starter
macrumors member
 
Join Date: Jan 2007
Location: England
Maybe I'm making things more difficult than it needs to be...

Does anyone know of a good tutorial (or sample) of an .obj loader/model viewer instead?
jackal123uk is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
GLKIT vs Core Animation Layers Blakeasd iPhone/iPad Programming 1 May 25, 2013 10:13 PM
Help with combining photos. hayden536 Web Design and Development 4 Nov 15, 2012 08:40 PM
need help combining js with asp sk3pt1c Web Design and Development 6 Oct 16, 2012 06:29 AM
GLKit programming reference - something good KnightWRX iPhone/iPad Programming 5 Aug 17, 2012 12:45 PM
is that normal?batteryis it normal?battery talaada101 iPhone Tips, Help and Troubleshooting 0 Jun 4, 2012 08:51 PM

Forum Jump

All times are GMT -5. The time now is 08:36 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC