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

Basic Curves And Surfaces Modeler

, 18 Apr 2012 CPOL
A basic demo of modeling curves and surfaces in OpenGL.
cadsurfexe.zip
CadSurfexe
CadSurf.exe
VKGeom.dll
VKGraphic.dll
cadsurf_demo.zip
CadSurf.exe
cadsurf_src.zip
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_VS2008.zip
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
/*
 * OpenGL Font Support Functions from Chapter 7.
 *
 * Written by Michael Sweet.
 */

/*
 * Include necessary headers.
 */

#include "stdafx.h"

#include "font.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>


/*
 * Limits...
 */

#define MAX_STRING	1024


/*
 * 'FontCreate()' - Load Windows font bitmaps into OpenGL display lists.
 */

_GLFONT *                         /* O - Font data */
FontCreate(HDC        hdc,       /* I - Device Context */
           const char *typeface, /* I - Font specification */
           int        height,    /* I - Font height/size in pixels */
	   int        weight,    /* I - Weight of font (bold, etc) */
	   DWORD      italic)    /* I - Text is italic */
    {
    _GLFONT *font;                /* Font data pointer */
    HFONT  fontid;               /* Windows font ID */
    int    charset;              /* Character set code */

    /* Allocate memory */
    if ((font = (_GLFONT*)calloc(1, sizeof(_GLFONT))) == (_GLFONT *)0)
        return ((_GLFONT *)0);
 
    /* Allocate display lists */
    if ((font->base = glGenLists(256)) == 0)
        {
        free(font);
        return (0);
        }

    /* Select a character set */
    if (_stricmp(typeface, "symbol") == 0)
        charset = SYMBOL_CHARSET;
    else
        charset = ANSI_CHARSET;

    /* Load the font */
    fontid = CreateFont(height, 0, 0, 0, weight, italic, FALSE, FALSE,
                        charset, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS,
                        DRAFT_QUALITY, DEFAULT_PITCH, typeface);

    SelectObject(hdc, fontid);

    /* Create bitmaps for each character */
    wglUseFontBitmaps(hdc, 0, 256, font->base);

    /* Get the width and height information for each character */
    GetCharWidth(hdc, 0, 255, font->widths);
    font->height = height;

    return (font);
    }

/*
 * 'FontDestroy()' - Delete the specified font.
 */

void
FontDelete(_GLFONT *font) /* I - Font to delete */
    {
    if (font == (_GLFONT *)0)
        return;

    glDeleteLists(font->base, 256);
    free(font);
    }


/*
 * 'FontPuts()' - Display a string using the specified font.
 */

void
FontPuts(_GLFONT     *font, /* I - Font to use */
         const char *s)    /* I - String to display */
    {
    if (font == (_GLFONT *)0 || s == NULL)
        return;

    glPushAttrib(GL_LIST_BIT);
    glListBase(font->base);
    glCallLists(strlen(s), GL_UNSIGNED_BYTE, s);
    glPopAttrib();
    }


/*
 * 'FontPrintf()' - Display a formatted string using the specified font.
 */

void
FontPrintf(_GLFONT     *font,   /* I - Font to use */
           int        align,   /* I - Alignment to use */
           const char *format, /* I - printf() style format string */
           ...)                /* I - Other arguments as necessary */
    {
    va_list       ap;          /* Argument pointer */
    char s[1024],     /* Output string */
                  *ptr;        /* Pointer into string */
    float           width;       /* Width of string in pixels */

    if (font == (_GLFONT *)0 || format == (char *)0)
        return;

    /* Format the string */
    va_start(ap, format);
    vsprintf_s((char *)s, 1024, format, ap);
    va_end(ap);

    /* Figure out the width of the string in pixels... */
    for (ptr = s, width = 0; *ptr; ptr ++)
        width += font->widths[*ptr];

    /* Adjust the bitmap position as needed to justify the text */
    if (align < 0)
        glBitmap(0, 0, 0, 0, -width, 0, NULL);
    else if (align == 0)
        glBitmap(0, 0, 0, 0, -width / 2, 0, NULL);

    /* Draw the string */
    FontPuts(font, s);
    }

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.

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