It worked! Great, thank you.
Has anyone successfully added a 3d Model?
(38 posts) (13 voices)-
Posted 1 year ago #
-
I used PatrickC's code to create 3d Cubes the problem is that only the back faces of the cube seems to be drawn,
How can i fix this?Posted 1 year ago # -
That code is a bit old and as I recall it did have a few problem with the coordinates.
If you're seeing only the backface, the most likely issue is that you're winding the vertices in the oppisite direction than needed.
vertex winding (clockwise or counter-clockwise) determines which direction the normal points, and you want the normal pointing towards viewer/camera and not the other way.
You could also play around with backface culling, but I doubt this is the problem here.
Let me know if you're unable to fix it and I'll dig around some of the old code and see if I can find something useful.
g'luckPosted 1 year ago # -
I had forgotten to enable the line:
[[CCDirector sharedDirector] setDepthBufferFormat:kDepthBuffer16];Which fixed the drawing problem.
However I don't really understand much of openGL and I can't figure out how to use the glDepthFunc properly, I have the same Hud problem as ranReloaded. Actually i'm not sure it's exactly the same problem, my HUD stuff is not drawn at all.
Posted 1 year ago # -
I have been playing around with the glDepthFunc() and looked at some other projects for a few days, but I still can't figure it out.
Any cocos2d stuff that is added with a higher z value then my 3d object is not drawn at all. The FPSLabel is also not drawn.Please help.
/ DannePosted 1 year ago # -
Hm, well you could try posting your code ;)
So you can draw 3d objects on top of cocos2d, but not cocos2d elements on top of your custom 3d drawing?
Again, I can't remember very well and I'd need to dig around old code a bit, you might want to try letting cocos2d do as much drawing as possible, and leave the 3d objects and other elements for last by calling a draw on them, in the correct order, with a glDepthFunc set to GL_ALWAYS.
It's a bit dirty I know, but it would solve the problem.Posted 1 year ago # -
So you can draw 3d objects on top of cocos2d, but not cocos2d elements on top of your custom 3d drawing?
Yes this is exactly my problem.
My 3D class is a subclassed CCNode, and i am basically using the code you posted in this thread.
But I draw multiple cubes in the same draw call rather then creating multiple instances of the class, i don't know if that is a smart thing to do but that's just the way I did it.-(void)draw { if(self.visible == YES){ //glDepthFunc(GL_ALWAYS); glColor4f(1,1,1,1); glEnable(GL_TEXTURE_2D); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glBindTexture(GL_TEXTURE_2D, texture[0]); for(int i = 0;i<numberOfCubes+1;i++){ if(drawCubeX[i] == 0){ }else{ posX = drawCubeX[i]-32; posY = drawCubeY[i]-8; width = 64; depth = 16; height = 50; if(posY < 480 && posY >0-depth){ GLfloat cubeVerticesTemp[] = { posX, posY,0.0f, width+posX, depth+posY, 0.0f, width+posX, posY, 0.0f, posX, posY, 0.0f, posX, depth+posY, 0.0f, width+posX, depth+posY, 0.0f… ...glVertexPointer(3, GL_FLOAT, 0, cubeVerticesTemp); glTexCoordPointer(2, GL_FLOAT, 0, cubeTextureCoords); glDrawArrays(GL_TRIANGLES, 0, 36); } } } //glDepthFunc(GL_LEQUAL); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisable(GL_TEXTURE_2D);…The HUD class is also a subclass of CCNode,
The glDepthFunc(GL_ALWAYS); doesn't seem to make any difference.
Right now i'm adding the HUD node under (z) the 3D node so it atleast get's drawn.@implementation HUD -(id) init { if( (self=[super init])) { } return self; } -(void)draw { glEnable(GL_DEPTH_TEST); glDepthFunc(GL_ALWAYS); [super draw]; glDepthFunc(GL_LEQUAL); } @endI tried to do what you suggested by manually calling a custom draw method for the hud and 3d classes with
the glDepthFunc(GL_ALWAYS), without any luck. Am I misunderstanding something?Thanks for your patience.
Posted 1 year ago # -
Can anyone post a solution to this? I am having the exact same issue not being able to draw any 2D elements on top of my 3D drawing. Thanks!
Dave
Posted 4 months ago #
Reply
You must log in to post.