...6 pages of code? for a triange?

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?

Hi !

In OpenGL:
glBegin( GL_TRIANGLES);
glVertex3d( x1, y1, z1);
glVertex3d( x1, y1, z1);
glVertex3d( x1, y1, z1);
glEnd();

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…

Mikael

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.

Mikael

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
glFlush();
glutSwapBuffers();
}

/*
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);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, (GLfloat)width/ (GLfloat)height, 0.1f, 1000.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

/*
Initialized Core opengl settings
*/
bool InitGL(void)
{
glShadeModel(GL_SMOOTH); //use smooth shading
//Sets the color of the background
glClearColor(CLEAR_COLOR[0], CLEAR_COLOR[1], CLEAR_COLOR[2], CLEAR_COLOR[3] );
return true;
}

/*
Function to call when idle.
*/
void Idle(void)
{
glutPostRedisplay();
}

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
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_ALPHA);
glutCreateWindow(WINDOW_NAME); //The window’s title
InitGL();
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;
}

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.