View Full Version : ...6 pages of code? for a triange?

09-04-2001, 08:03 PM
Would someone please just reassure me that this tutorial that Downloaded that uses up 6 pages of code just to draw a white triangle onto the screen is only this big because its explanatory... Oh wait..its nothing but code, and most of this stuff doesn't make much sense. . . SO are you guys suggesting that I know Windows Proggin (i think thats called like "win32 API" or something) in order to prog in oGL?

09-04-2001, 09:21 PM
Hi !

In OpenGL:
glVertex3d( x1, y1, z1);
glVertex3d( x1, y1, z1);
glVertex3d( x1, y1, z1);

If you an old example of Direct3D code, then it might be true, drawing I triangle in the first versions of Direct3D was something like one or two pages of code...


09-04-2001, 09:23 PM
Ooops, sorry, it should of course have been x1,y1,z1 x2,y2,z2 and so on.

You do not need to now any Win32 to do OpenGL applications, if you use GLUT or SDL or other platform independent solutions.


09-04-2001, 09:24 PM
If you wanna avoid the windows code all together you can use glut. You can pick it up at http://www.xmission.com/~nate/glut.html
I'll include a what I think is a minial opengl code that will draw a quad. Hope noone minds me pasteing it here. There are probable better ways to do what I'm doing but I'm learning openGL too =)

#include <GL/glut.h> //includes all the OpenGL headers and also the windows.h header if needed

#define WINDOW_NAME "OpenGL Application" //The name that will appear in the title bar

GLfloat CLEAR_COLOR[4] ={0.0f, 0.0f, 0.0f, 0.0f};

Draws a simple quad at -2 on the z axis
void DrawQuad(void)

//sets the color of the quad, in this case purely red
//glColor3f(red, blue, green);
glColor3f(1.0f, 0.0f, 0.0f);
glBegin(GL_QUADS); //begin drawing
//glVertex3f(x-axis, y-axis, z-axis);
glVertex3f(-1.0f, 1.0f,-4.0f);
glVertex3f(-1.0f, -1.0f,-4.0f);
glVertex3f(1.0f, -1.0f,-4.0f);
glVertex3f(1.0f, 1.0f,-4.0f);
glEnd(); //end drawing the quad

DrawGL clears the buffer and then does the drawing and finall the displaying

void DrawGL(void)
glClear(GL_COLOR_BUFFER_BIT); //Clear the background
glPushMatrix(); //save the current matrix
glLoadIdentity(); //load the identity matrix
DrawQuad(); //draw the quad
glPopMatrix(); //restores the matrix

Resize is called when the window is resized.
Sets up the aspect ratio and viewing/modeling matrix
void Resize(GLsizei width, GLsizei height)
glViewport(0, 0, width, height);
gluPerspective(45.0f, (GLfloat)width/ (GLfloat)height, 0.1f, 1000.0f);

Initialized Core opengl settings
bool InitGL(void)
glShadeModel(GL_SMOOTH); //use smooth shading
//Sets the color of the background
return true;

Function to call when idle.
void Idle(void)

int main(int argc, char** argv)
glutInit(&argc, argv);
glutInitWindowSize(800, 600); //800x600 window size
glutInitWindowPosition(0,0); //sets the windows initial windows position to the
//upper left hand corner
//The window will use RGB color, double buffer, and a alpha buffer
glutCreateWindow(WINDOW_NAME); //The window's title
glutDisplayFunc(DrawGL); //The main display function, where all the drawing happens
glutReshapeFunc(Resize); //Function to call when user resizes the window
glutIdleFunc(Idle); //Function that runs with idle
glutMainLoop(); //enters the opengl main loop
return 1;

09-05-2001, 12:26 PM
What do you mean programming on OpenGL? In most cases graphics programming requires some kind of input by user (usually using mouse or keyboard). If you wanna do something like it on windows platform, you, maybe, should know WinAPI a little. Of course, you may use object wrappers like MFC or VCL(on Delphi and BCB). But its not much easier.