Archived

This topic is now archived and is closed to further replies.

Beginner's question

This topic is 6359 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I''m pretty new to OpenGL programming, and I''m trying out the tutorials on basic polys and translation. I''m writing my code in Java using gl4java, because I don''t know C. (I''m a servlet/jsp/applet programmer). Actually it''s kind of nice not to have to worry about the memory issues that I see in the C programs. (I''m lazy.) The problem I''m having is a fairly stupid one, and I don''t get why it won''t work. I took the tutorial on translating basic 2d polys (the triangle and the quad), cut out the quad, and made a pyramid that translates on whatever axis. This works all well and fine, but I can''t seem to put a bottom on the damn thing. The four sides of the pyramid show up just fine (I color them differently so I can see the difference) but I can''t seem to draw the bottom. Does the bottom of the pyramid need to be a different type? I tried putting a quad on the bottom, but it acts like a separate entity. Thanks!

Share this post


Link to post
Share on other sites
I''m a newbie to OpenGL too, but I think that instead of using a quad for the bottom, couldn''t you just use 2 triangles ? Maybe it will help, maybe not. Oh, well. I tried.

Share this post


Link to post
Share on other sites
Well, I tried this and it doesn't look right. Attached is the source. Credits to Darren Hodges for the original source which I have mucked up. This is taken from lesson 4 of the java conversion:
-----------------------------------------
public void display()
{
if (glj.gljMakeCurrent(true) == false)
return;
gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
gl.glTranslatef(-0.0f, 0.0f, -8.0f);
gl.glRotatef(rtri, -10.0f, 10.0f, 0.0f);

gl.glBegin(GL_POLYGON);
//first side
gl.glColor3f(1.0f, 0.0f, 0.0f); //Set The Color To Red
gl.glVertex3f(0.0f, 0.0f, 0.0f); //Top
gl.glColor3f(0.0f, 1.0f, 0.0f); //Set The Color Green
gl.glVertex3f(1.0f, -1.0f, 1.0f); //Bottom Left
gl.glColor3f(0.0f,0.0f,1.0f); //Color To Blue
gl.glVertex3f(1.0f, -1.0f, -1.0f); //Bottom Right

//second side
gl.glColor3f(0.0f,0.0f,1.0f);
gl.glVertex3f(0.0f, 0.0f, 0.0f);
gl.glColor3f(1.0f,0.0f,0.0f);
gl.glVertex3f(-1.0f, -1.0f, 1.0f); //point 2-2
gl.glColor3f(0.0f,1.0f,1.0f);
gl.glVertex3f(-1.0f, -1.0f, -1.0f); //point 3-2

//third side
gl.glColor3f(0.0f,1.0f,0.0f);
gl.glVertex3f(0.0f, 0.0f, 0.0f);
gl.glColor3f(1.0f,0.0f,0.0f);
gl.glVertex3f(-1.0f, -1.0f, 1.0f); //point 2 -2
gl.glColor3f(0.0f,0.0f,1.0f);
gl.glVertex3f(1.0f, -1.0f, 1.0f); //point 2 -1

//fourth side
gl.glColor3f(0.0f,1.0f,0.0f);
gl.glVertex3f(0.0f, 0.0f, 0.0f);
gl.glColor3f(1.0f,0.0f,0.0f);
gl.glVertex3f(-1.0f, -1.0f, -1.0f); //point 2 -3
gl.glColor3f(0.0f,0.0f,1.0f);
gl.glVertex3f(1.0f, -1.0f, -1.0f); //point 2 -1

//Bottom side1
gl.glColor3f(0.0f,1.0f,0.0f);
gl.glVertex3f(1.0f, -1.0f, 1.0f);
gl.glColor3f(1.0f,0.0f,0.0f);
gl.glVertex3f(1.0f, -1.0f, -1.0f); //point 2 -3
gl.glColor3f(0.0f,0.0f,1.0f);
gl.glVertex3f(-1.0f, -1.0f, -1.0f); //point 2 -1

//bottom side2
gl.glColor3f(0.0f,1.0f,0.0f);
gl.glVertex3f(-1.0f, -1.0f, 1.0f);
gl.glColor3f(1.0f,0.0f,0.0f);
gl.glVertex3f(1.0f, -1.0f, 1.0f); //point 2 -3
gl.glColor3f(0.0f,0.0f,1.0f);
gl.glVertex3f(-1.0f, -1.0f, -1.0f); //point 2 -1

gl.glEnd();
gl.glLoadIdentity();
rtri += 0.2f;

glj.gljSwap();
}

----------------------------------------------

Notice bottom side1 and side2. These appear correctly when they're all by themselves as a square, like they should. If I include the other sides, what I get is a triangle thru the center of the other sides.

This looks like a triangle who's point is at the apex of the pyramid, and splits the other triangles, halving the pyramid.
Any ideas?

Edited by - borzwazie on July 18, 2000 1:22:06 AM

Share this post


Link to post
Share on other sites
You may do this, but this is c++
            glBegin(GL_TRIANGLES);

//First side

glColor3f(1.0f,0.0f,0.0f); // Red

glVertex3f( 0.0f, 1.0f, 0.0f); // Top Of Triangle (Front)
glColor3f(0.0f,1.0f,0.0f); // Green

glVertex3f(-1.0f,-1.0f, 1.0f); // Left Of Triangle (Front)
glColor3f(0.0f,0.0f,1.0f); // Blue

glVertex3f( 1.0f,-1.0f, 1.0f); // Right Of Triangle (Front)
//Second side

glColor3f(1.0f,0.0f,0.0f); // Red

glVertex3f( 0.0f, 1.0f, 0.0f); // Top Of Triangle (Right)
glColor3f(0.0f,0.0f,1.0f); // Blue

glVertex3f( 1.0f,-1.0f, 1.0f); // Left Of Triangle (Right)
glColor3f(0.0f,1.0f,0.0f); // Green

glVertex3f( 1.0f,-1.0f, -1.0f); // Right Of Triangle (Right)
//Third side

glColor3f(1.0f,0.0f,0.0f); // Red

glVertex3f( 0.0f, 1.0f, 0.0f); // Top Of Triangle (Back)
glColor3f(0.0f,1.0f,0.0f); // Green

glVertex3f( 1.0f,-1.0f, -1.0f); // Left Of Triangle (Back)
glColor3f(0.0f,0.0f,1.0f); // Blue

glVertex3f(-1.0f,-1.0f, -1.0f); // Right Of Triangle (Back)

//Fourth Side

glColor3f(1.0f,0.0f,0.0f); // Red

glVertex3f( 0.0f, 1.0f, 0.0f); // Top Of Triangle (Left)
glColor3f(0.0f,0.0f,1.0f); // Blue

glVertex3f(-1.0f,-1.0f,-1.0f); // Left Of Triangle (Left)
glColor3f(0.0f,1.0f,0.0f); // Green

glVertex3f(-1.0f,-1.0f, 1.0f); // Right Of Triangle (Left)
glEnd(); // Done Drawing The Pyramid


glBegin(GL_QUADS);//the bottom must be quad.

//your code for the quad goes here, i'm to lazy to doit

glEnd();


your problem is that you draw the triangle and the quad between the same glBegin---glEnd, and must be separate, that's all, i think Good luck



"I stole the colour of night,to get out of your sight.I am the Visionaire, follow me if you dare..."

Edited by - BlackStorm on July 18, 2000 2:15:30 AM

Edited by - BlackStorm on July 18, 2000 2:18:53 AM

Share this post


Link to post
Share on other sites