Archived

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

sebnem_a

where is the problem?

Recommended Posts

I ve written a code about creating an object from a file which includes coordinates.it works when I create it in windows.But when it is in forms (in borland) there is a problem. when I write the same function in my first program it works but in the second it doesnt.. for (int loop_m = 0; loop_m < totaltri; loop_m++) { glBegin(GL_TRIANGLES); glVertex3f(n[t[loop_m].node1].x,n[t[loop_m].node1].y,n[t[loop_m].node1].z); glColor3f(0.0f,0.0f,1.0f); glVertex3f(n[t[loop_m].node2].x,n[t[loop_m].node2].y,n[t[loop_m].node2].z); glColor3f(0.0f,1.0f,0.0f); glVertex3f(n[t[loop_m].node3].x,n[t[loop_m].node3].y,n[t[loop_m].node3].z); glColor3f(1.0f,0.0f,0.0f); glEnd(); } glLoadIdentity(); glEnd(); when I debug my second program the same function loops only once.. why? can it be about the forms that I ve create and give each forms a pointer?

Share this post


Link to post
Share on other sites
Your code is not correctly written ...

The glBegin and glEnd must never be in the loop.
So, assuming that your arrays are correctly, just try :


glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clean the screen and the depth buffer

glLoadIdentity(); // Reset The Projection Matrix

glBegin(GL_TRIANGLES);
for (int loop_m = 0; loop_m < totaltri; loop_m++)
{
glVertex3f(n[t[loop_m].node1].x,n[t[loop_m].node1].y,n[t[loop_m].node1].z);
glColor3f(0.0f,0.0f,1.0f);

glVertex3f(n[t[loop_m].node2].x,n[t[loop_m].node2].y,n[t[loop_m].node2].z);
glColor3f(0.0f,1.0f,0.0f);

glVertex3f(n[t[loop_m].node3].x,n[t[loop_m].node3].y,n[t[loop_m].node3].z);
glColor3f(1.0f,0.0f,0.0f);
}
glEnd();


========================
Leyder Dylan (dylan.leyder@slug-production.be.tf
http://www.slug-production.be.tf/

Share this post


Link to post
Share on other sites
Hi
I tried but didnt work.. Is the following function true?
void __fastcall TForm2::FormResize(TObject *Sender)
{
glViewport(0, 0, ClientWidth, ClientHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

if(ClientHeight == 0)
ClientHeight = 1;

gluPerspective(45.0f,(GLfloat)ClientWidth/(GLfloat)ClientHeight,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

Is this problem about this function because when I write the following function it works but the object seems so big.

glBegin(GL_TRIANGLES); // Drawing Pyramid
glColor3f(0.0f,1.0f,1.0f);

glVertex3f( 0.0f, 1.0f, 0.0f);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f(-1.0f,-1.0f, 1.0f);
glColor3f(0.0f,0.0f,1.0f);
glVertex3f( 1.0f,-1.0f, 1.0f); glColor3f(0.0f,1.0f,1.0f);
glVertex3f( 0.0f, 1.0f, 0.0f);
glColor3f(0.0f,0.0f,1.0f);
glVertex3f( 1.0f,-1.0f, 1.0f);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f( 1.0f,-1.0f, -1.0f);


glColor3f(0.0f,1.0f,1.0f);
glVertex3f( 0.0f, 1.0f, 0.0f);
glColor3f(0.0f,0.0f,1.0f);
glVertex3f( 1.0f,-1.0f, -1.0f);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f( -1.0f,-1.0f, -1.0f);


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

glVertex3f( 0.0f, 1.0f, 0.0f);
glColor3f(0.0f,0.0f,1.0f);
glVertex3f(-1.0f,-1.0f,-1.0f);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f(-1.0f,-1.0f, 1.0f);




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

glVertex3f( -1.0f, -1.0f,-1.0f);
glVertex3f(-1.0f, -1.0f,1.0f);
glVertex3f(1.0f, -1.0f, 1.0f);

glColor3f(0.0f,0.0f,1.0f);
glVertex3f( -1.0f, -1.0f,-1.0f);
glVertex3f(1.0f, -1.0f,1.0f);
glVertex3f(1.0f, -1.0f, -1.0f);
glLoadIdentity();
glEnd();

Share this post


Link to post
Share on other sites