// Gingerbread Man
//
// A dot constellation that is generated procedurally by an
// Iterated function system (IFS).
//
// The IFS:
// x = R(1 + 2S) - old_y + abs(old_x - SR)
// y = old_x
//
// The pattern is familiar with the chaos theory as it is
// a form of a strange attractor
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
HGLRC hRC=NULL; // Permanent Rendering Context
HDC hDC=NULL; // Private GDI Device Context
HWND hWnd=NULL; // Holds Our Window Handle
HINSTANCE hInstance; // Holds The Instance Of The Application
bool keys[256]; // Array Used For The Keyboard Routine
bool active=TRUE; // Window Active Flag Set To TRUE By Default
bool fullscreen=TRUE; // Fullscreen Flag Set To Fullscreen Mode By Default
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration For WndProc
GLvoid ReSizeGLScene(GLsizei width, GLsizei height) // Resize And Initialize The GL Window
{
if (height==0) // Prevent A Divide By Zero By
{
height=1; // Making Height Equal One
}
glViewport(0, 0, width, height); // Reset The Current Viewport
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix
// Calculate The Aspect Ratio Of The Window
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix
}
int InitGL(GLvoid) // All Setup For OpenGL Goes Here
{
glShadeModel(GL_SMOOTH); // Enables Smooth Shading
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background
glColor3f(1,1,1); // White colour for points
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Test To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear screen to background colour
glPointSize(1.0); // Set the point size to 3 pixels
return TRUE; // Initialization Went OK
}
int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing
{
// Don't bother clearing screen
glLoadIdentity();
glTranslatef(-30,-30,-90); // Translate out a so we can see the image and adjust image to middle of screen
glScaled(0.15, 0.15, 0.15); // Fit image on screen
float x, y; // x/y of point to draw
static float old_x=115, old_y=121; // Previous point
static float R=40, S=3; // Constant Values
glBegin(GL_POINTS);
for (int i=0; i<1000; i++) // Draw 1000 points per render
{
x = R*(1 + 2*S) - old_y + abs(int(old_x - S*R));// The IFS for x
y = old_x; // and for y
old_x = x;
old_y = y;
glVertex2f(x,y); // Output that magic vertex
}
glEnd();
glFlush(); // Flush the OpenGL pipe
return TRUE; // Everything Went OK
}
GLvoid KillGLWindow(GLvoid) // Properly Kill The Window
{
if (fullscreen) // Are We In Fullscreen Mode?
{
ChangeDisplaySettings(NULL,0); // If So Switch Back To The Desktop
ShowCursor(TRUE); // Show Mouse Pointer
}
if (hRC) // Do We Have A Rendering Context?
{
if (!wglMakeCurrent(NULL,NULL)) // Are We Able To Release The DC And RC Contexts?
{
MessageBox(NULL,"Release Of DC And RC Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
}
if (!wglDeleteContext(hRC)) // Are We Able To Delete The RC?
{
MessageBox(NULL,"Release Rendering Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
}
hRC=NULL; // Set RC To NULL
}
if (hDC && !ReleaseDC(hWnd,hDC)) // Are We Able To Release The DC
{
MessageBox(NULL,"Release Device Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
hDC=NULL; // Set DC To NULL
}
if (hWnd && !DestroyWindow(hWnd)) // Are We Able To Destroy The Window?
{
MessageBox(NULL,"Could Not Release hWnd.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
hWnd=NULL; // Set hWnd To NULL
}
if (!UnregisterClass("OpenGL",hInstance)) // Are We Able To Unregister Class
{
MessageBox(NULL,"Could Not Unregister Class.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
hInstance=NULL; // Set hInstance To NULL
}
}
BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag)
{
GLuint PixelFormat; // Holds The Results After Searching For A Match
WNDCLASS wc; // Windows Class Structure
DWORD dwExStyle; // Window Extended Style
DWORD dwStyle; // Window Style
RECT WindowRect; // Grabs Rectangle Upper Left / Lower Right Values
WindowRect.left=(long)0; // Set Left Value To 0
WindowRect.right=(long)width; // Set Right Value To Requested Width
WindowRect.top=(long)0; // Set Top Value To 0
WindowRect.bottom=(long)height; // Set Bottom Value To Requested Height
fullscreen=fullscreenflag; // Set The Global Fullscreen Flag
hInstance = GetModuleHandle(NULL); // Grab An Instance For Our Window
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraw On Move, And Own DC For Window
wc.lpfnWndProc = (WNDPROC) WndProc; // WndProc Handles Messages
wc.cbClsExtra = 0; // No Extra Window Data
wc.cbWndExtra = 0; // No Extra Window Data
wc.hInstance = hInstance; // Set The Instance
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); // Load The Default Icon
wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Load The Arrow Pointer
wc.hbrBackground = NULL; // No Background Required For GL
wc.lpszMenuName = NULL; // We Don't Want A Menu
wc.lpszClassName = "OpenGL"; // Set The Class Name
if (!RegisterClass(&wc)) // Attempt To Register The Window Class
{
MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Exit And Return FALSE
}
if (fullscreen) // Attempt Fullscreen Mode?
{
DEVMODE dmScreenSettings; // Device Mode
memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); // Makes Sure Memory's Cleared
dmScreenSettings.dmSize=sizeof(dmScreenSettings); // Size Of The Devmode Structure
dmScreenSettings.dmPelsWidth = width; // Selected Screen Width
dmScreenSettings.dmPelsHeight = height; // Selected Screen Height
dmScreenSettings.dmBitsPerPel = bits; // Selected Bits Per Pixel
dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
// Try To Set Selected Mode And Get Results. NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar.
if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL)
{
// If The Mode Fails, Offer Two Options. Quit Or Run In A Window.
if (MessageBox(NULL,"The Requested Fullscreen Mode Is Not Supported By\nYour Video Card. Use Windowed Mode Instead?","NeHe GL",MB_YESNO|MB_ICONEXCLAMATION)==IDYES)
{
fullscreen=FALSE; // Select Windowed Mode (Fullscreen=FALSE)
}
else
{
// Pop Up A Message Box Letting User Know The Program Is Closing.
MessageBox(NULL,"Program Will Now Close.","ERROR",MB_OK|MB_ICONSTOP);
return FALSE; // Exit And Return FALSE
}
}
}
if (fullscreen) // Are We Still In Fullscreen Mode?
{
dwExStyle=WS_EX_APPWINDOW; // Window Extended Style
dwStyle=WS_POPUP; // Windows Style
ShowCursor(FALSE); // Hide Mouse Pointer
}
else
{
dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Window Extended Style
dwStyle=WS_OVERLAPPEDWINDOW; // Windows Style
}
AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);
没有合适的资源?快使用搜索试试~ 我知道了~
计算机图形学opengl源码
共88个文件
pdb:14个
cpp:8个
exe:7个
需积分: 13 35 下载量 24 浏览量
2009-11-08
19:25:34
上传
评论
收藏 7.5MB ZIP 举报
温馨提示
计算机图形学OpenGL版 第3版 第2章源码
资源推荐
资源详情
资源评论
收起资源包目录
ch2source.zip (88个子文件)
ch2
c_plus_plus_book_first_program
c_plus_plus_book_first_program.opt 48KB
main.cpp 192B
c_plus_plus_book_first_program.dsw 585B
c_plus_plus_book_first_program.dsp 4KB
Debug
vc60.pdb 60KB
vc60.idb 41KB
c_plus_plus_book_first_program.pch 186KB
c_plus_plus_book_first_program.ilk 234KB
main.obj 6KB
c_plus_plus_book_first_program.exe 200KB
c_plus_plus_book_first_program.pdb 489KB
c_plus_plus_book_first_program.ncb 33KB
c_plus_plus_book_first_program.plg 978B
2.41-RubberRect
rubberrect.cpp 2KB
rubberrect.ncb 49KB
Debug
rubberrect.pch 3.59MB
vc60.pdb 76KB
rubberrect.exe 184KB
vc60.idb 145KB
rubberrect.ilk 209KB
rubberrect.pdb 457KB
rubberrect.obj 17KB
rubberrect.plg 760B
rubberrect.dsw 545B
rubberrect.dsp 3KB
rubberrect.opt 49KB
2.44-GlutMenus
version1.opt 48KB
version1.dsw 541B
version1.plg 784B
version1.dsp 3KB
Debug
vc60.pdb 44KB
version1.exe 184KB
vc60.idb 33KB
version1.obj 9KB
version1.ilk 211KB
version1.pdb 441KB
version1.pch 315KB
version1.cpp 1KB
version1.ncb 41KB
Gingerbread Man
Gingerbread Man.exe 32KB
Gingerbread Man.opt 48KB
Gingerbread Man.cpp 15KB
Debug
vc60.pdb 76KB
vc60.idb 129KB
Gingerbread Man.pch 3.57MB
Gingerbread Man.obj 29KB
Gingerbread Man.pdb 25KB
Gingerbread Man.ncb 33KB
Gingerbread Man.plg 3KB
Gingerbread Man.dsw 555B
Gingerbread Man.dsp 4KB
2.11-threeDots
main.cpp 2KB
threedots.plg 891B
Debug
threedots.pdb 361KB
vc60.pdb 76KB
vc60.idb 137KB
threedots.pch 3.6MB
threedots.ilk 202KB
main.obj 15KB
threedots.exe 184KB
threedots.dsp 4KB
2.17-DotPlot
dotoplt.dsp 3KB
dotoplt.opt 48KB
dotoplt.cpp 2KB
Debug
vc60.pdb 76KB
dotoplt.pch 3.61MB
vc60.idb 137KB
dotoplt.exe 208KB
dotoplt.pdb 369KB
dotoplt.ilk 225KB
dotoplt.obj 16KB
dotoplt.plg 745B
dotoplt.dsw 539B
dotoplt.ncb 49KB
mouseDots
main.cpp 1KB
mouseDots.dsw 543B
mouseDots.ncb 41KB
mouseDots.dsp 4KB
Debug
vc60.pdb 76KB
vc60.idb 137KB
mouseDots.ilk 207KB
main.obj 16KB
mouseDots.exe 184KB
mouseDots.pch 3.59MB
mouseDots.pdb 449KB
mouseDots.plg 1KB
mouseDots.opt 48KB
myKeyboard.CPP 2KB
共 88 条
- 1
资源评论
huanziling
- 粉丝: 0
- 资源: 14
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功