Click here to Skip to main content
Click here to Skip to main content
Articles » Multimedia » OpenGL » General » Downloads
 
Add your own
alternative version

2D Drawing with an OpenGL Control

, 8 Feb 2010 CPOL
An article explaning how to create a user control for 2D shape drawing with OpenGL
GLView_Binaries_And_Demo.zip
GLView.dll
GLView Demo.exe
glview_demo_src.zip
GLView Demo
debug
GLView.dll
GLView Demo
app.ico
Debug
GLView_Source.zip
GLView
app.ico
bin
Debug
Release
GLView.vcproj.DENGE.Ozgur.user
obj
Debug
Release
Resources
GLView.GLCanvas2D.bmp
GLView.GLCanvas3D.bmp
app.ico
bin
Debug
Release
GLView Demo.vcproj.DENGE.Ozgur.user
obj
Debug
Release
glview_src.zip
debug
GLView
app.ico
Release
Resources
GLView.GLCanvas2D.bmp
release
#pragma once

using namespace System;

namespace GLView 
{
	// Forward class declarations
	ref class GLCanvas3D;
	value class Point3D;

	/// <summary>
	/// Contains methods for drawing on the canvas.
	/// </summary>
	public ref class GLGraphics3D
	{
	// Constructor/destructor
	public:
		GLGraphics3D(GLCanvas3D ^ Canvas, Drawing::Graphics ^ GDIGraphics);

	protected:
		~GLGraphics3D() { }

	private:
		float mLineWidth;
		Drawing::RectangleF mView;
		System::Drawing::Graphics ^ mGDIGraphics;
		float xmin, xmax, ymin, ymax, zmin, zmax;

	private:
		GLCanvas3D ^ mCanvas;

	public:
		/// <summary>
		/// Gets or sets the current line width.
		/// </summary>
		property float LineWidth
		{
			virtual float get(void) 
			{ 
				return mLineWidth; 
			}
			virtual void set(float value) 
			{ 
				mLineWidth = value;
				glLineWidth(value);
			}
		}
		
	private:
		/// <summary>
		/// Updates model limits.
		/// </summary>
		System::Void UpdateLimits(float x, float y, float z);
		/// <summary>
		/// Sets the raster position to given window coordinates.
		/// </summary>
		System::Void glWindowPos2f(GLfloat x, GLfloat y);

	public:
		/// <summary>
		/// Gets the origion of the model.
		/// </summary>
		Point3D ModelOrigin();
		/// <summary>
		/// Gets the size of the model.
		/// </summary>
		float ModelSize();
		/// <summary>
		/// Draws a line connecting the given points.
		/// </summary>
		System::Void DrawLine(float x1, float y1, float z1, float x2, float y2, float z2, Drawing::Color color);
		/// <summary>
		/// Draws a triangle specified by the given corner points.
		/// </summary>
		System::Void DrawTriangle(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, Drawing::Color color);
		/// <summary>
		/// Draws a quad specified by the given corner points.
		/// </summary>
		System::Void DrawQuad(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, float x4, float y4, float z4, Drawing::Color color);
		/// <summary>
		/// Draws a filled triangle specified by the given corner points.
		/// </summary>
		System::Void FillTriangle(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, Drawing::Color color);
		/// <summary>
		/// Draws a filled quad specified by the given corner points.
		/// </summary>
		System::Void FillQuad(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, float x4, float y4, float z4, Drawing::Color color);
		/// <summary>
		/// Draws a box.
		/// </summary>
		System::Void DrawBox(float x1, float y1, float z1, float x2, float y2, float z2, float width, float height, Drawing::Color color);
		/// <summary>
		/// Draws a filled box.
		/// </summary>
		System::Void FillBox(float x1, float y1, float z1, float x2, float y2, float z2, float width, float height, Drawing::Color color);
		/// <summary>
		/// Draws a sphere.
		/// </summary>
		System::Void DrawSphere(float x, float y, float z,float radius, Drawing::Color color);
		/// <summary>
		/// Draws a filled sphere.
		/// </summary>
		System::Void FillSphere(float x, float y, float z,float radius, Drawing::Color color);
		/// <summary>
		/// Draws a cylinder.
		/// </summary>
		System::Void DrawCylinder(float x1, float y1, float z1, float x2, float y2, float z2, float radius, Drawing::Color color);
		/// <summary>
		/// Draws a filled cylinder.
		/// </summary>
		System::Void FillCylinder(float x1, float y1, float z1, float x2, float y2, float z2, float radius, Drawing::Color color);
		/// <summary>
		/// Draws text at the given coordinates.
		/// </summary>
		System::Void DrawRasterText(float x, float y, float z, System::String ^ text, Drawing::Color color);
		/// <summary>
		/// Draws text at the given window coordinates.
		/// </summary>
		System::Void DrawRasterTextWindow(float x, float y, System::String ^ text, Drawing::Color color);
		/// <summary>
		/// Draws text at the given coordinates.
		/// </summary>
		System::Void DrawVectorText(float x, float y, float z, float height, System::String ^ text, Drawing::Color color);
	};

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Ozgur Ozcitak

Turkey Turkey
No Biography provided

| Advertise | Privacy | Mobile
Web04 | 2.8.141022.2 | Last Updated 8 Feb 2010
Article Copyright 2007 by Ozgur Ozcitak
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid