PDA

View Full Version : Triangle drawings



pegasus09
04-17-2009, 12:31 AM
Hi,
I am new to Opengl.I am reading tutorials and programming in VC++.I am writing this dispaly func to draw triangle

void display(void)
{


glClear (GL_COLOR_BUFFER_BIT);

// glLoadIdentity();
// gluLookAt (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glColor3f (0.0, 0.0, 1.0);
drawtriangle (150.0, 125.0, 300.0, 25.0,25,25);//a macro definition

glEnable(GL_LINE_STIPPLE); /* dashed lines */
glLineStipple(1, 0xF0F0);
// glLoadIdentity();
glColor3f (1.0, 0.0, 1.0);
glTranslatef(-50.0, 0.0, 0.0);
drawtriangle (150.0, 125.0, 300.0, 25.0,25,25);


glColor3f (1.0, 0.0, .0);
glScalef(1.5, 0.5, 1.0);
drawtriangle (150.0, 125.0, 300.0, 25.0,25,25);


glFlush ();
}

When I am writing this code it is displaying 3 triangle but when i am using gluLookAt ()(which i have commented here)or glLoadIdentity()(before a triangle drawing)it is not displaying anything.Please help me if anyone knows why it is happening and how to overcome it if i want to use gluLookAt () or glLoadIdentity().

nachovall
04-17-2009, 12:51 AM
I think you problem is that you don't know what you're doing. Take a look at glulookat (http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/glu/lookat.html) spec and gluperspective (http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/glu/perspective.html). This should help you.

pegasus09
04-17-2009, 02:17 AM
Thanks for your Reply.
Yes,Actualy i am trying to get the meaning glulookat() using in a program.In the above scenario is it possible to use glulookat() and get respective result.I think the result will clear my idea about glulookat() a little bit for any scenario.would I share the whole program

todayman
04-17-2009, 02:00 PM
At some point, you should be setting up the projection matrix - something with glMatrixMode(GL_PROJECTION). What does that code look like?

pegasus09
04-19-2009, 10:11 PM
This is the code I am using.Plaese tell me how can I use glulookat() here to display triangles



#include <GL/gl.h>
#include <GL/glut.h>

#define drawtriangle(x1,y1,x2,y2,x3,y3) glBegin(GL_TRIANGLES); \
glVertex2f ((x1),(y1)); glVertex2f ((x2),(y2));glVertex2f ((x3),(y3)); glEnd();

void init(void)
{
glClearColor (1.0, 1.0, 1.0, 0.0);
glShadeModel (GL_SMOOTH);
}

void display(void)
{


glClear (GL_COLOR_BUFFER_BIT);

// glLoadIdentity();
// gluLookAt (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glColor3f (0.0, 0.0, 1.0);
drawtriangle (150.0, 125.0, 300.0, 25.0,25,25);//a macro definition

glEnable(GL_LINE_STIPPLE); /* dashed lines */
glLineStipple(1, 0xF0F0);
// glLoadIdentity();
glColor3f (1.0, 0.0, 1.0);
glTranslatef(-50.0, 0.0, 0.0);
drawtriangle (150.0, 125.0, 300.0, 25.0,25,25);


glColor3f (1.0, 0.0, .0);
glScalef(1.5, 0.5, 1.0);
drawtriangle (150.0, 125.0, 300.0, 25.0,25,25);


glFlush ();
}

void reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluOrtho2D (0.0, (GLdouble) w, 0.0, (GLdouble) h);
/* */
}
int main(int argc, char** argv)
{
glutInit(&amp;argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (400, 450);
glutInitWindowPosition (100, 100);
glutCreateWindow (argv[0]);
init ();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}