Click here to Skip to main content
12,455,701 members (94,858 online)
Click here to Skip to main content
Articles » Multimedia » OpenGL » General » Downloads

Stats

188.8K views
14.6K downloads
114 bookmarked
Posted

Basic Curves And Surfaces Modeler

, 18 Apr 2012 CPOL
A basic demo of modeling curves and surfaces in OpenGL.
CadSurfexe
CadSurf.exe
VKGeom.dll
VKGraphic.dll
CadSurf.exe
CadSurf_src
VKernel
VKGraphic
VKGraphic.dsp
VKGraphic.dsw
VKGraphic.plg
VKGeom
VKGeom.dsp
VKGeom.dsw
cadsurf
CadSurf.clw
CadSurf.dsp
cadsurf.dsw
Thumbs.db
res
bmp00001.bmp
cadsurf.ico
CADSURFDOC.ICO
new_splash.bmp
new_splash.PNG
new_splash_small.bmp
tb_geom.bmp
Thumbs.db
toolbar.bmp
toolbar1.bmp
untitled.bmp
XPStyle.manifest
CadSurf
cadsurf
CadSurf.suo
res
bmp00001.bmp
cadsurf.ico
CADSURFDOC.ICO
new_splash.bmp
new_splash.PNG
new_splash_small.bmp
tb_geom.bmp
Thumbs.db
toolbar.bmp
toolbar1.bmp
untitled.bmp
VKernel
VKGeom
VKGraphic
VKGraphic.plg
// GLPoint.cpp: implementation of the CGLPoint class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"

#include "GLPoint.h"
#include "MMath.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CGLPoint::CGLPoint(const CPoint3D& P, const GLPointMarker& M) : itsPoint(P), itsMarker(M)
{
	glObjType = GLPOINT;
	glObjID = (int)glObjType + CGLObject::GetCount();
	itsRed = 255;
	itsGreen = 99;
	itsBlue = 25;
	ComputeBoundLimits();
}

CGLPoint::~CGLPoint()
{
}

CGLObject* CGLPoint::Copy() const
{
	CGLPoint* P = new CGLPoint(itsPoint, itsMarker);
	P->SetColor(itsRed, itsGreen ,itsBlue);
	P->glObjID = glObjID;
	return P;
}

CGeometry* CGLPoint::Geometry() const
{
	CPoint3D* pnt = new CPoint3D(itsPoint.GetX(), itsPoint.GetY(), itsPoint.GetZ());
	return pnt;
}

void CGLPoint::DefineDisplay()
{
	glPushAttrib(GL_COLOR_BUFFER_BIT);
	glColor3ub(itsRed, itsGreen, itsBlue);
	glDisable(GL_LIGHTING);
	glEnable (GL_POINT_SMOOTH);
	glEnable (GL_BLEND);
	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glHint (GL_POINT_SMOOTH_HINT, GL_NICEST);
	glPointSize (8);

	if(itsMarker == MARKER_POINT)
	{
		glBegin(GL_POINTS);
			glVertex3d(itsPoint.GetX(), itsPoint.GetY(), itsPoint.GetZ());
		glEnd();
	}
	else
		DrawMarker();

	glDisable (GL_POINT_SMOOTH);
	glPointSize (1);
	glDisable (GL_BLEND);
	glPopAttrib();
}

void CGLPoint::Display(const GLDisplayMode&)
{
	DefineDisplay();
}

void CGLPoint::Hilight(const GLDisplayMode&)
{
	itsRed = 0; itsGreen = 255; itsBlue = 255;
	DefineDisplay();
}

void CGLPoint::ComputeBoundLimits()
{
	CPoint3D p = itsPoint;
	itsBox.SetLimits(p.GetX()-1, p.GetX()+1, p.GetY()-1, p.GetY()+1, p.GetZ()-1, p.GetZ()+1);
}

void CGLPoint::DrawMarker()
{
	/*glDisable(GL_LIGHTING);
	glDisable(GL_COLOR_MATERIAL);
	glDisable(GL_DEPTH_TEST);

	HDC hdc = wglGetCurrentDC();
	HFONT  fontid;                     // Windows font ID
    int    charset;                    // Character set code

	unsigned char *ptr;        // Pointer into string
    int           width;       // Width of string in pixels

	char* str;
	if(itsMarker == MARKER_PLUS)
		str = "+";
	if(itsMarker == MARKER_CROSS)
		str = "x";
	if(itsMarker == MARKER_STAR)
		str = "*";
	if(itsMarker == MARKER_CIRCLE)
		str = "o";

	LPCTSTR typface;
	if(itsMarker == MARKER_STAR)
		typface = "MS Mincho";
	else
		typface = "Courier";

	fheight = 24;

	// Allocate display lists
    base = glGenLists(256);

    charset = ANSI_CHARSET;

    // Load the font
    fontid = CreateFont(fheight, 0, 0, 0, 0, 0, FALSE, FALSE,
                        charset, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS,
                        ANTIALIASED_QUALITY , DEFAULT_PITCH, typface);

    SelectObject(hdc, fontid);

    // Create bitmaps for each character
    wglUseFontBitmaps(hdc, 0, 256, base);


    // Get the width and height information for each character
    GetCharWidth(hdc, 0, 255, fwidths);

	// Figure out the width of the string in pixels....
    for (ptr = (unsigned char*)str, width = 0; *ptr; ptr ++)
        width += fwidths[*ptr];

	//Set Font Color;
	glColor3ub(itsRed, itsGreen, itsBlue);
	glRasterPos3d(itsPoint.GetX(), itsPoint.GetY(), itsPoint.GetZ());
	// Adjust the bitmap position as needed to justify the text
    glBitmap(0, 0, 0, 0, -width / 2, -fheight/4, NULL);
    // Draw the string
	glPushAttrib(GL_LIST_BIT);
    glListBase(base);
    glCallLists(strlen(str), GL_UNSIGNED_BYTE, str);
    glPopAttrib();
	glDeleteLists(base, 256);*/
}

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

Sharjith
Engineer Tata Technologies Ltd
India India
Sharjith is a Mechanical Engineer with strong passion for Automobiles, Aircrafts and Software development.

You may also be interested in...

Pro
Pro
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160826.1 | Last Updated 18 Apr 2012
Article Copyright 2003 by Sharjith
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid