Generally most of my questions seem to stem from Nehe's tutorials because, although they are nice, I think they are rather poor examples for converting into game code, simply because he never makes it easy to put them in with other stuff. Anyway.

I used tutorial number 6 to see how to draw a textured cube, then created a glCube method for accessing it. Nothing is drawn.

publicstaticvoidglCube(Stringtex, intx, inty, intz, intw, inth, intd) {//store the current model matrixGL11.glPushMatrix();GL11.glTranslatef(0, 0, 0);try {Texturetexture = BestGameEver.textureLoader.getTexture(tex);GL11.glEnable(GL11.GL_DEPTH_TEST); //Enable 3D depth testingGL11.glTranslatef(0.0f, 0.0f, -5.0f); // Move Into The Screen 5 Unitstexture.bind(); } catch (Exceptione) {e.printStackTrace();}ImageViewer.glColor(255,255,255,255);GL11.glBegin(GL11.GL_QUADS);// Front FaceGL11.glTexCoord2f(0.0f, 0.0f);GL11.glVertex3f(x,y+h,z); // Bottom Left Of The Texture and QuadGL11.glTexCoord2f(1.0f, 0.0f);GL11.glVertex3f(x+w,y+h,z); // Bottom Right Of The Texture and QuadGL11.glTexCoord2f(1.0f, 1.0f);GL11.glVertex3f(x+w,y,z); // Top Right Of The Texture and QuadGL11.glTexCoord2f(0.0f, 1.0f);GL11.glVertex3f(x,y,z); // Top Left Of The Texture and Quad// Back FaceGL11.glTexCoord2f(1.0f, 0.0f);GL11.glVertex3f(x+w,y+h,z-d); // Bottom Right Of The Texture and QuadGL11.glTexCoord2f(1.0f, 1.0f);GL11.glVertex3f(x+w,y,z-d); // Top Right Of The Texture and QuadGL11.glTexCoord2f(0.0f, 1.0f);GL11.glVertex3f(x,y,z-d); // Top Left Of The Texture and QuadGL11.glTexCoord2f(0.0f, 0.0f);GL11.glVertex3f(x,y+h,z-d); // Bottom Left Of The Texture and Quad// Top FaceGL11.glTexCoord2f(0.0f, 1.0f);GL11.glVertex3f(x,y,z-d); // Top Left Of The Texture and QuadGL11.glTexCoord2f(0.0f, 0.0f);GL11.glVertex3f(x,y,z); // Bottom Left Of The Texture and QuadGL11.glTexCoord2f(1.0f, 0.0f);GL11.glVertex3f(x+w,y,z); // Bottom Right Of The Texture and QuadGL11.glTexCoord2f(1.0f, 1.0f);GL11.glVertex3f(x+w,y,z-d); // Top Right Of The Texture and Quad// Bottom FaceGL11.glTexCoord2f(1.0f, 1.0f);GL11.glVertex3f(x+w,y+h,z-d); // Top Right Of The Texture and QuadGL11.glTexCoord2f(0.0f, 1.0f);GL11.glVertex3f(x,y+h,z-d); // Top Left Of The Texture and QuadGL11.glTexCoord2f(0.0f, 0.0f);GL11.glVertex3f(x,y+h,z); // Bottom Left Of The Texture and QuadGL11.glTexCoord2f(1.0f, 0.0f);GL11.glVertex3f(x+w,y+h,z); // Bottom Right Of The Texture and Quad// Right faceGL11.glTexCoord2f(1.0f, 0.0f);GL11.glVertex3f(x+w,y+h,z); // Bottom Right Of The Texture and QuadGL11.glTexCoord2f(1.0f, 1.0f);GL11.glVertex3f(x+w,y,z); // Top Right Of The Texture and QuadGL11.glTexCoord2f(0.0f, 1.0f);GL11.glVertex3f(x+w,y,z-d); // Top Left Of The Texture and QuadGL11.glTexCoord2f(0.0f, 0.0f);GL11.glVertex3f(x+w,y+h,z-d); // Bottom Left Of The Texture and Quad// Left FaceGL11.glTexCoord2f(0.0f, 0.0f);GL11.glVertex3f(x,y+h,z-d); // Bottom Left Of The Texture and QuadGL11.glTexCoord2f(1.0f, 0.0f);GL11.glVertex3f(x,y+h,z); // Bottom Right Of The Texture and QuadGL11.glTexCoord2f(1.0f, 1.0f);GL11.glVertex3f(x,y,z); // Top Right Of The Texture and QuadGL11.glTexCoord2f(0.0f, 1.0f);GL11.glVertex3f(x,y,z-d); // Top Left Of The Texture and QuadGL11.glEnd();

GL11.glPopMatrix(); }

One thing to note what I am trying to do specifically. The entirety of the game is 2D, so depth testing is most of the time disabled. When you start a dialogue or open an item window, however, the window is a 3D one that gently bobbles left and right slightly. Therefore, as you can see, I need to enable depth testing and then pop it back to the old matrix. The BestGameEver.textureLoader references the game's TextureLoader, which is pretty much exactly Kev's class from Space Invaders, aside from a few additions.

Nothing is drawn, and the texture is definitely found because the exact same image path is drawn correctly somewhere else.

In Nehe's original source, he uses 0.0f or 1.0f or -1.0f in the coords, whereas I use actual points. This could be some problem. In any case, it woud be great if someone could point me in the right direction.

Your second command moves the modelview matrix by 0,0,0, a NO-OP. However below I see you moving the matrix by -5 z each frame, which will push your matrix right off into the distance over time (unless you are clearing the matrix somewhere else).

Perhaps this command was supposed to be GL11.glLoadIdentity()?

Other than that everything looks fine to me. You might make sure that1. you've cleared the depth buffer2. lighting is off3. your projection matrix and or viewport is not fubar

Hmm... or not. I can see something now, but there's still a couple things that don't work.

a) For some reason to texture on the front draws from the top left to about 50 pixels away from the bottom right, leaving black space there. Why won't it fill the entire thing with my texture?

b) I cannot move it past -1 or 1 on the z axis without it going MIA, how do I fix that?

c) Chaning the z doesn't seem to do anything I can notice.

d) Using GL11.glRotatef(xDir, 1.0f, 0.0f, 0.0f); to rotate the cube does nothing unless I remove GL11.glLoadIdentity(), ending up with what appears to be the texture moving up and down along the cube face, leaving gaps in between.

Hmm.. that's a lot of issues. Any ideas what may be up, or what GL11 things I need to set before drawing this correctly? I'm pretty sure I've got them all...

Exception in thread "main" org.lwjgl.opengl.OpenGLException: Stack underflow (1284) at org.lwjgl.opengl.Util.checkGLError(Util.java:56) at org.lwjgl.opengl.Display.update(Display.java:549) at Panel.paint(Panel.java:208) at Panel.mainLoop(Panel.java:58) at Panel.<init>(Panel.java:35) at BestGameEver.run(BestGameEver.java:93) at BestGameEver.main(BestGameEver.java:31)

After commenting some stuff out I isolated it as the glMatrixMode that breaks it. If I have only gluPerspective then instead of seeing a weird messed up line skewing like I had I see nothing.

Well obviously something is going hunky-dory between me trying to have everything be 2D except this single cube. I must be forgetting to switch some stuff back to 2D.

After adding in

1 2

GL11.glMatrixMode(GL11.GL_MODELVIEW);GL11.glLoadIdentity();

before glPopMatrix() I don't get the exception anymore, which after reading through my Java book stems from this line, which makes sense because it says there is a stack problem. Anyway, after doing this, it continues to run, however, the entire screen turns white. I think I'm probably forgetting to set something back to the 2D settings, although I believe am setting ortho mode manually before every drawing... or not. I'll try re-enabling ortho mode after the cube is drawn...

Well, well. Setting it back to ortho mode, along with changing the matrix mode to modelview, "fixes" everything. No freezes, no crashes, everything is drawn. BUT. There is absolutely no cube drawn at all.

publicstaticvoidglCube(Stringtex, intx, inty, intz, intw, inth, intd) {//store the current model matrixGL11.glPushMatrix();//GL11.glTranslatef(0, 0, 0);//GL11.glLoadIdentity();try {Texturetexture = BestGameEver.textureLoader.getTexture(tex);GL11.glEnable(GL11.GL_DEPTH_TEST); //Enable 3D depth testingGL11.glMatrixMode(GL11.GL_PROJECTION); // Select The Projection MatrixGL11.glLoadIdentity();GLU.gluPerspective(45.0f, (float)800/(float)600, 0.1f, 1000.0f);texture.bind(); } catch (Exceptione) {e.printStackTrace();}ImageViewer.glColor(255,255,255,255);GL11.glBegin(GL11.GL_QUADS);// Front FaceGL11.glTexCoord2f(0.0f, 0.0f);GL11.glVertex3f(x,y+h,z); // Bottom Left Of The Texture and QuadGL11.glTexCoord2f(1.0f, 0.0f);GL11.glVertex3f(x+w,y+h,z); // Bottom Right Of The Texture and QuadGL11.glTexCoord2f(1.0f, 1.0f);GL11.glVertex3f(x+w,y,z); // Top Right Of The Texture and QuadGL11.glTexCoord2f(0.0f, 1.0f);GL11.glVertex3f(x,y,z); // Top Left Of The Texture and Quad// Back FaceGL11.glTexCoord2f(1.0f, 0.0f);GL11.glVertex3f(x+w,y+h,z-d); // Bottom Right Of The Texture and QuadGL11.glTexCoord2f(1.0f, 1.0f);GL11.glVertex3f(x+w,y,z-d); // Top Right Of The Texture and QuadGL11.glTexCoord2f(0.0f, 1.0f);GL11.glVertex3f(x,y,z-d); // Top Left Of The Texture and QuadGL11.glTexCoord2f(0.0f, 0.0f);GL11.glVertex3f(x,y+h,z-d); // Bottom Left Of The Texture and Quad// Top FaceGL11.glTexCoord2f(0.0f, 1.0f);GL11.glVertex3f(x,y,z-d); // Top Left Of The Texture and QuadGL11.glTexCoord2f(0.0f, 0.0f);GL11.glVertex3f(x,y,z); // Bottom Left Of The Texture and QuadGL11.glTexCoord2f(1.0f, 0.0f);GL11.glVertex3f(x+w,y,z); // Bottom Right Of The Texture and QuadGL11.glTexCoord2f(1.0f, 1.0f);GL11.glVertex3f(x+w,y,z-d); // Top Right Of The Texture and Quad// Bottom FaceGL11.glTexCoord2f(1.0f, 1.0f);GL11.glVertex3f(x+w,y+h,z-d); // Top Right Of The Texture and QuadGL11.glTexCoord2f(0.0f, 1.0f);GL11.glVertex3f(x,y+h,z-d); // Top Left Of The Texture and QuadGL11.glTexCoord2f(0.0f, 0.0f);GL11.glVertex3f(x,y+h,z); // Bottom Left Of The Texture and QuadGL11.glTexCoord2f(1.0f, 0.0f);GL11.glVertex3f(x+w,y+h,z); // Bottom Right Of The Texture and Quad// Right faceGL11.glTexCoord2f(1.0f, 0.0f);GL11.glVertex3f(x+w,y+h,z); // Bottom Right Of The Texture and QuadGL11.glTexCoord2f(1.0f, 1.0f);GL11.glVertex3f(x+w,y,z); // Top Right Of The Texture and QuadGL11.glTexCoord2f(0.0f, 1.0f);GL11.glVertex3f(x+w,y,z-d); // Top Left Of The Texture and QuadGL11.glTexCoord2f(0.0f, 0.0f);GL11.glVertex3f(x+w,y+h,z-d); // Bottom Left Of The Texture and Quad// Left FaceGL11.glTexCoord2f(0.0f, 0.0f);GL11.glVertex3f(x,y+h,z-d); // Bottom Left Of The Texture and QuadGL11.glTexCoord2f(1.0f, 0.0f);GL11.glVertex3f(x,y+h,z); // Bottom Right Of The Texture and QuadGL11.glTexCoord2f(1.0f, 1.0f);GL11.glVertex3f(x,y,z); // Top Right Of The Texture and QuadGL11.glTexCoord2f(0.0f, 1.0f);GL11.glVertex3f(x,y,z-d); // Top Left Of The Texture and QuadGL11.glEnd();

... only needs to be done once when you initialize everything. Also is the cube the only thing that you're drawing? If it is then you shouldn't need the push pop matrix stuff at all. Is there a place in your code where you do a glTranslate() into the screen? If not then the box is being drawn around the camera and you would be looking at the "other" side of the quads that you're drawing and therefore see through them.

publicstaticvoidglCube(Stringtex, intx, inty, intz, intw, inth, intd) {GL11.glBegin(GL11.GL_QUADS);// Front FaceGL11.glVertex3f(x,y+h,z); // Bottom Left Of The Texture and QuadGL11.glVertex3f(x+w,y+h,z); // Bottom Right Of The Texture and QuadGL11.glVertex3f(x+w,y,z); // Top Right Of The Texture and QuadGL11.glVertex3f(x,y,z); // Top Left Of The Texture and Quad// Back FaceGL11.glVertex3f(x+w,y+h,z-d); // Bottom Right Of The Texture and QuadGL11.glVertex3f(x+w,y,z-d); // Top Right Of The Texture and QuadGL11.glVertex3f(x,y,z-d); // Top Left Of The Texture and QuadGL11.glVertex3f(x,y+h,z-d); // Bottom Left Of The Texture and Quad// Top FaceGL11.glVertex3f(x,y,z-d); // Top Left Of The Texture and QuadGL11.glVertex3f(x,y,z); // Bottom Left Of The Texture and QuadGL11.glVertex3f(x+w,y,z); // Bottom Right Of The Texture and QuadGL11.glVertex3f(x+w,y,z-d); // Top Right Of The Texture and Quad// Bottom FaceGL11.glVertex3f(x+w,y+h,z-d); // Top Right Of The Texture and QuadGL11.glVertex3f(x,y+h,z-d); // Top Left Of The Texture and QuadGL11.glVertex3f(x,y+h,z); // Bottom Left Of The Texture and QuadGL11.glVertex3f(x+w,y+h,z); // Bottom Right Of The Texture and Quad// Right faceGL11.glVertex3f(x+w,y+h,z); // Bottom Right Of The Texture and QuadGL11.glVertex3f(x+w,y,z); // Top Right Of The Texture and QuadGL11.glVertex3f(x+w,y,z-d); // Top Left Of The Texture and QuadGL11.glVertex3f(x+w,y+h,z-d); // Bottom Left Of The Texture and Quad// Left FaceGL11.glVertex3f(x,y+h,z-d); // Bottom Left Of The Texture and QuadGL11.glVertex3f(x,y+h,z); // Bottom Right Of The Texture and QuadGL11.glVertex3f(x,y,z); // Top Right Of The Texture and QuadGL11.glVertex3f(x,y,z-d); // Top Left Of The Texture and QuadGL11.glEnd(); }

My big problem, however, is that I am not only drawing a cube. What I have right now is an entire 2D game drawn out. I simply trying to change the dialogue window that pops when you talk to a character from a 2D rectangle to a 3D cube that gently rotates back and forth. I am having some issues actively converting it between these drawing methods.

The 2D stuff is drawn in ortho mode with depth testing off, no z axis, etc. The cube obviously needs some perspective to be drawn correctly.

I'll try to use your code to change my initializers in here somewhere.

It should also be known that I am not plugging in dumb values like -1, 1, etc. into the coords for drawing my cube, which could very well be the problem. I am trying to put in flat out x, y coordinates. Say the window is like this:

The coordinates of the actual display are 0,0 as the top left corner and 800,600 as the bottom right. The window itself is drawn at about 100,10 as top left to 500,210 as the bottom right. These are the coordinates I am plugging into the cube method, whereas yours are very small values, and if I put in small values I can actually see something drawn even within my game. I like glOrtho because it turns it all to this display-like format, which is useful for drawing sprites and the like. How can I have cube drawing work the same way?

I felt like I should edit this and post that I do in fact have a spinning cube in there now, the only problem is trying to translate it into that sort of coordinate use. It may not be possible, it occurs to me, but that's fine. I'll figure it out.

Also, for some off reason whenever I map textures in this way they only fill up a part of the quad, leaving black space on the edges for no reason. Any ideas why? I can "stretch" textures to fit, but then I need to tailor it for every texture that crosses my path, something I don't want to do.

elias4444 has some code in his ScreenManager class that calculates the proper z-value to make each unit a pixel on the screen. I have not looked too far into it, but you may appeal to him for help on that front. I am a little at a loss for what you are trying to do in the big picture though. You have a cube with text on it that oscillates back and forth? Is the player seeing the edge of the cube or the side? (i.e. could it be a single quad?) elias4444 also has a very handy text class that you may be able to get some good stuff from!

I do need a cube because of the perspective angle. You can see the sides of it, even though the front face is the really important part. On the left side of the cube a texture for the current talker's portrait is drawn, then on the right side the text will (theoretically) be drawn. I already have text working on a 2D level, I'm just going to extend points into 3D, that should work.

All in all, thanks for everyone's help, now I finally can figure (most of) this stuff out by myself.

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org