// testopengl.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "stdio.h"
#include "Wingdi.h"
#include "glut.h"
//////////////////////////////////////////////////////////////
// Window has changed size. Reset to match window coordinates
void ChangeSize(GLsizei w, GLsizei h)
{
GLfloat nRange = 100.0f;
GLfloat fAspect;
// Prevent a divide by zero
if(h == 0) h = 1;
fAspect = (GLfloat)w/(GLfloat)h;
// Set Viewport to window dimensions
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,400, 400, 0);
// Viewing transformation
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
///////////////////////////////////////////////////
// Set up. Use a Windows font to create the bitmaps
void SetupRC(HDC hDC)
{
// Set up the Font characteristics
HFONT hFont;
LOGFONT logfont;
logfont.lfHeight = -20;
logfont.lfWidth = 0;
logfont.lfEscapement = 0;
logfont.lfOrientation = 0;
logfont.lfWeight = FW_BOLD;
logfont.lfItalic = FALSE;
logfont.lfUnderline = FALSE;
logfont.lfStrikeOut = FALSE;
logfont.lfCharSet = ANSI_CHARSET;
logfont.lfOutPrecision = OUT_DEFAULT_PRECIS;
logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
logfont.lfQuality = DEFAULT_QUALITY;
logfont.lfPitchAndFamily = DEFAULT_PITCH;
strcpy(logfont.lfFaceName,"Arial");
// Create the font and display list
hFont = CreateFontIndirect(&logfont);
SelectObject (hDC, hFont);
// Create display lists for glyphs 0 through 128
nFontList = glGenLists(128);
wglUseFontBitmaps(hDC, 0, 128, nFontList);
DeleteObject(hFont); // Don’t need original font anymore
// Black Background
glClearColor(0.0f, 0.0f, 0.0f, 1.0f );
}
//////////////////////////////////////////////////
// Draw everything (just the text)
void RenderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT);
// Blue 3D Text - Note color is set before the raster position
glColor3f(1.0f, 1.0f, 1.0f);
glRasterPos2i(0, 200);
glListBase(nFontList);
glCallLists (13, GL_UNSIGNED_BYTE, "OpenGL Rocks!");
}
//void main(void)
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
glutCreateWindow("Simple");
glutDisplayFunc(RenderScene);
glutReshapeFunc(ChangeSize);
SetupRC();
glutMainLoop();
return 0;
}