It worked! Great, thank you.
Has anyone successfully added a 3d Model?
(41 posts) (16 voices)-
Posted 3 years 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 2 years 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 2 years 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 2 years 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 2 years 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 2 years 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 2 years 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 1 year ago # -
Has anyone tried this with Cocos2d v2.0? As Cocos2d 2.0 is using OpenGL ES 2.0 it has a lot of "behind-the-scenes" 3d code .. projections, fragment/vertex shader programs, cameras etc.
I have been playing around with this for some time but so far I have had no real luck with getting it to work. My biggest problem (I think) is that I am not sure what I am doing wrong. I have made a few OpenGL 2.0 projects with simple spinning cubes that works perfectly fine but when doing the same using Cocos2d 2.0 I do not get any on-screen changes.My guess is that it is because I do not fully understand how Cocos2d 2.0 handles the GL context and that I might be missing some things.
Anyhow, I will continue my efforts and hopefully I will get something going soon. But any pointers at all would be highly appreciated :)
Posted 1 year ago # -
Same question and same issue: unable to draw 2d elements on top of 3d. Is anybody have solution?
Posted 6 months ago # -
You can use cocos3d and add 2D elements on CC3Layer
Posted 6 months ago #
Reply
You must log in to post.