Пример #1
0
void main()
{
	// create a GL-enabled window
	dglWindowOpen("Simple Drawing: glDrawArrays quad example", 800, 700, false);

	// set up some vertices
	const float vertexdata[] = 
	{
		-0.8f,	-0.8f,  0.5f,		// lower left corner
		 0.8f,  -0.8f,  0.5f,		// upper left corner
		 0.8f,   0.8f,  0.5f,		// upper right corner 
		-0.8f,   0.8f,  0.5f,		// lower right corner
	};

	// begin main loop and continue till user presses escape
	while( !dglGetAsyncKeyState(DGLK_ESCAPE) )
	{
		// clear screen black before drawing
		glClear(GL_COLOR_BUFFER_BIT);

		glEnableClientState(GL_VERTEX_ARRAY);
		glVertexPointer(3, GL_FLOAT, 0, vertexdata);	// 3 coords of type float, tightly packed
		glDrawArrays(GL_QUADS, 0, 4);					// draw a quad based on the array of vertices
		
		dglSwapBuffers();								// frame is done and can be shown on the screen
	}

	// close the opened window 
	dglWindowClose();
}
Пример #2
0
void main()
{
	dglWindowOpen("Light example", 900, 750, false);    // create a GL-enabled window of given pixel size

	setupLighting();
	setupTexture();

	glEnable(GL_DEPTH_TEST);
 
	// variables to control object rotation
	float	rotAngle = 0.0f;
	unsigned long long int prevTime = dglGetCurrentTime();

	while( !dglGetAsyncKeyState(DGLK_ESCAPE) )		// begin the main loop. Keep on running until user presses escape
	{
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		gluPerspective(30, 900.0/750.0, 1.0, 100.0);
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
		gluLookAt(0, 0, 10, 0, 0, 0, 0, 1, 0);

		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);		// clear screen black before drawing

		glRotatef(rotAngle, 0, 0.2, 0.2);
		glutSolidTeapot(1.5);
		
		dglSwapBuffers();	// frame is done and can be shown on the screen
		
		rotAngle += 0.02f * (dglGetCurrentTime() - prevTime);				// rotation speed 0.02 (degrees per millisecond)
		prevTime = dglGetCurrentTime();
	}

	dglWindowClose();
}
Пример #3
0
static void gld_Flush_DX7(
	struct gl_context *ctx)
{
	GLD_context		*gld	= GLD_GET_CONTEXT(ctx);

	// TODO: Detect apps that glFlush() then SwapBuffers() ?

	if (gld->EmulateSingle) {
		// Emulating a single-buffered context.
		// [Direct3D doesn't allow rendering to front buffer]
		dglSwapBuffers(gld->hDC);
	}
}
Пример #4
0
void main()
{
	dglWindowOpen("Transform Example", 800, 700, false);

	// vertices coordinates
	const float vertexdata[] =		
	{
		-0.8f, -0.8f, 0.5f,	 // vertex #1, lower left corner
		 0.8f, -0.8f, 0.5f,  // vertex #2, upper left corner
		 0.8f,  0.8f, 0.5f,  // vertex #3, upper right corner 
		-0.8f,  0.8f, 0.5f,  // vertex #4, lower right corner
	};

	glEnableClientState(GL_VERTEX_ARRAY);
	glVertexPointer(3, GL_FLOAT, 0, vertexdata);

	// set up colors
	const float colordata[] = 
	{
		1.0f, 0.0f, 0.0f,	 // RGB color for vertex #1
		0.0f, 1.0f, 0.0f,    // RGB color for vertex #2
		1.0f, 0.0f, 0.0f,    // RGB color for vertex #3
		0.0f, 0.0f, 1.0f,    // RGB color for vertex #4
	};

	glEnableClientState(GL_COLOR_ARRAY);
	glColorPointer(3, GL_FLOAT, 0, colordata);

	// variables to control object rotation speed regardless of process wait time
	float rotAngle	  = 0.0f;
	unsigned long long prevTime = dglGetCurrentTime();

	// main loop, increment in object rotation is adjusted based on actual time to achieve constant rotation speed
	while( !dglGetAsyncKeyState(DGLK_ESCAPE) )
	{
		glLoadIdentity();              // very important!
		glClear(GL_COLOR_BUFFER_BIT);

		glRotatef(rotAngle, 0, 0, 1);
		glDrawArrays(GL_QUADS, 0, 4);
		dglSwapBuffers();

		rotAngle += 0.03f * (dglGetCurrentTime() - prevTime);				// rotation speed 0.03 degrees per millisecond wall clock time
		prevTime = dglGetCurrentTime();
	}
	dglWindowClose();
}
Пример #5
0
//------------------------------------------------------------------------
void swap_buffers(void)
{
	dglSwapBuffers();
}