//
// Massey University Screen Saver
// Compile this using the makefile and copy massey.scr to your windows directory
//
#include <stdio.h>
#include <windows.h>
#include <GL/glut.h>
#include <math.h>
#include <stdlib.h>
#include <scrnsave.h>
struct colorIndexState {
GLfloat amb[3]; /* ambient color / bottom of ramp */
GLfloat diff[3]; /* diffuse color / middle of ramp */
GLfloat spec[3]; /* specular color / top of ramp */
GLfloat ratio; /* ratio of diffuse to specular in ramp */
GLint indexes[3]; /* where ramp was placed in palette */
};
#define NUM_COLORS (sizeof(colors) / sizeof(colors[0]))
struct colorIndexState colors[] = {
{ { 94.0F/255, 94.0F/255, 94.0F/255 }, { 1.0F, 1.0F, 1.0F }, { 1.0F, 1.0F, 1.0F },
0.75F,{ 0, 0, 0 },
}
, { { 0.0F, 49.0/255, 94.0/255 }, {16.0/255, 143.0/255, 255.0/255}, { 225/255.0F, 241/255.0F, 1.0F },
0.75F, { 0, 0, 0 },
}
,
};
/* Windows globals, defines, and prototypes */
HGLRC hRC = (HGLRC) 0;
HDC hDC = (HDC) 0;
HDC hdc1;
HPALETTE hPalette = (HPALETTE) 0;
int nWndSize = 300;
// 5 vars(x,y,twist,lat,long) 3 derivs (fx,f'x,f''x) 3 values (val,max,min)
#define NVARS 5
#define NDERIV 4
int vars[NVARS][NDERIV][3]= { { {0,0,0}, {400,600, -600}, {-1,100,-100}, {0,0,0}
}
, { {0,0,0}, {200,600,-600}, {2,100,-100}, {0,0,0}
}
, { {36000,720000,-720000}, {100,500,-500}, {10,12,-12}, {1,1,-1}
}
, { {36000,720000,-720000}, {500,400,-400}, {8,10,-10}, {1,1,-1}
}
, { {36000,720000,-720000}, {500,600,-600}, {6,10,-10}, {1,1,-1}
}
,
};
UINT nTimerID = 101;
#define PI 3.1415926
#define REFSPEED 50 // screen refresh speed (ms)
void setupPixelFormat(HDC);
//GLfloat twist;
GLdouble radius;
GLvoid resize(GLsizei, GLsizei);
GLvoid initializeGL(GLsizei, GLsizei);
GLvoid drawScene(GLvoid);
void polarView( GLdouble, GLdouble, GLdouble, GLdouble);
void setupPalette(HDC hDC) {
PIXELFORMATDESCRIPTOR pfd;
LOGPALETTE* pPal;
PALETTEENTRY *pe;
int rampBase,pixelFormat,paletteSize,numRamps,rampSize,extra,diffSize,specSize;
int i, r;
pixelFormat=GetPixelFormat(hDC);
DescribePixelFormat(hDC, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
if (pfd.dwFlags & PFD_NEED_PALETTE ||
pfd.iPixelType == PFD_TYPE_COLORINDEX) {
paletteSize = 1 << pfd.cColorBits;
if (paletteSize > 4096 || paletteSize==1) {
paletteSize = 4096;
}
}
else {
return;
}
pPal = (LOGPALETTE*)
malloc(sizeof(LOGPALETTE) + paletteSize * sizeof(PALETTEENTRY));
pPal->palVersion = 0x300;
pPal->palNumEntries = paletteSize;
GetSystemPaletteEntries(hDC, 0, paletteSize, &pPal->palPalEntry[0]);
numRamps = NUM_COLORS;
rampSize = (paletteSize - 20) / numRamps;
extra = (paletteSize - 20) - (numRamps * rampSize);
for (r=0; r<numRamps; ++r) {
rampBase = r * rampSize + 10;
pe = &pPal->palPalEntry[rampBase];
diffSize = (int) (rampSize * colors[r].ratio);
specSize = rampSize - diffSize;
for (i=0; i<rampSize; ++i) {
GLfloat *c0, *c1;
GLint a;
if (i < diffSize) {
c0 = colors[r].amb;
c1 = colors[r].diff;
a = (i * 255) / (diffSize - 1);
}
else {
c0 = colors[r].diff;
c1 = colors[r].spec;
a = ((i - diffSize) * 255) / (specSize - 1);
}
pe[i].peRed = (BYTE) (a * (c1[0] - c0[0]) + 255 * c0[0]);
pe[i].peGreen = (BYTE) (a * (c1[1] - c0[1]) + 255 * c0[1]);
pe[i].peBlue = (BYTE) (a * (c1[2] - c0[2]) + 255 * c0[2]);
pe[i].peFlags = PC_NOCOLLAPSE;
}
colors[r].indexes[0] = rampBase;
colors[r].indexes[1] = rampBase + (diffSize-1);
colors[r].indexes[2] = rampBase + (rampSize-1);
}
for (i=0; i<extra; ++i) {
int index = numRamps*rampSize+10+i;
PALETTEENTRY *pe = &pPal->palPalEntry[index];
pe->peRed = (BYTE) 0;
pe->peGreen = (BYTE) 0;
pe->peBlue = (BYTE) 0;
pe->peFlags = PC_NOCOLLAPSE;
}
hPalette = CreatePalette(pPal);
free(pPal);
if (hPalette) {
SelectPalette(hDC, hPalette, FALSE);
RealizePalette(hDC);
}
}
static void initLights( void ) { // initializes light and material properties
GLfloat light_ambient[] = {1.0, 1.0, 1.0, 1.0};
GLfloat light_diffuse[] = {1.0, 1.0, 1.0, 1.0};
GLfloat light_specular[] = {1.0, 1.0, 1.0, 1.0};
GLfloat light_position[] = {.7, .7, 1.25, 1.0};
GLfloat mat_shininess[] = {30.0};
glEnable(GL_LIGHTING); // enables lighting
glEnable(GL_LIGHT0); // enables light source 0
glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE,(float[]){GL_FALSE});
glLightfv(GL_LIGHT0, GL_AMBIENT,light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE,light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR,light_specular);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);
}
LONG WINAPI ScreenSaverChildProc (HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam) {
LONG lRet = 1;
PAINTSTRUCT ps;
RECT rect;
switch (uMsg) {
case WM_CREATE:
hDC = GetDC(hWnd);
setupPixelFormat(hDC);
setupPalette(hDC);
hRC = wglCreateContext(hDC);
wglMakeCurrent(hDC, hRC);
GetClientRect(hWnd, &rect);
initializeGL(rect.right, rect.bottom);
break;
case WM_PAINT:
BeginPaint(hWnd, &ps);
drawScene();
SwapBuffers(hDC);
EndPaint(hWnd, &ps);
break;
case WM_SIZE:
resize(LOWORD(lParam), HIWORD(lParam));
break;
case WM_PALETTECHANGED:
if (hRC && hPalette && (HWND) wParam != hWnd) {
UnrealizeObject(hPalette);
SelectPalette(hDC, hPalette, FALSE);
RealizePalette(hDC);
return 0;
}
break;
case WM_QUERYNEWPALETTE:
if (hRC && hPalette) {
UnrealizeObject(hPalette);
SelectPalette(hDC, hPalette, FALSE);
RealizePalette(hDC);
return TRUE;
}
break;
case WM_DESTROY:
wglMakeCurrent(hDC, NULL);
wglDeleteContext(hRC);
ReleaseDC(hWnd,hDC);
PostQuitMessage(0);
break;
case WM_ERASEBKGND:
return 1;
break;
case WM_SYSCOMMAND:
case WM_SETCURSOR:
case WM_NCACTIVATE:
case WM_ACTIVATE:
case WM_ACTIVATEAPP:
case WM_MOUSEMOVE:
case WM_LBUTTONDOWN:
case WM_MBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_KEYDOWN:
case WM_SYSKEYDOWN:
lRet = DefScreenSaverProc(hWnd, uMsg, wParam, lParam);
DefScreenSaverProc(hMainWindow, uMsg, wParam, lParam);
return lRet;
default:
lRet = DefWindowProc (hWnd, uMsg, wParam, lParam);
break;
} return lRet;
}
LRESULT WINAPI ScreenSaverProc(HWND hWnd,UINT message, WPARAM wParam, LPARAM lParam) {
static HWND hChild = NULL;
HINSTANCE hInst = hMainInstance;
WNDCLASS wc;
int i,j,k;
switch (message) {
case WM_CREATE:
wc.style = CS_VREDRAW | CS_HREDRAW | CS_OWNDC ;
wc.lpfnWndProc = (WNDPROC) ScreenSaverChildProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInst;
wc.hIcon = NULL;
wc.hCursor = NULL;
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = "NTDEVCLASS";
RegisterClass(&wc);
if(vars[0][0][1]==0) {
RECT rect;
GetClientRect(hWnd,&rect);
h
gcc.rar_gcc
版权申诉
198 浏览量
2022-09-23
02:51:49
上传
评论
收藏 2.32MB RAR 举报
刘良运
- 粉丝: 69
- 资源: 1万+
最新资源
- c51_2_2.c
- ASCII American Standard Code for Information Interchange
- 一个chm格式的 SQL 函数手册-SQL语言手册文档
- 计算当前月份的天数和剩余天数
- 基于ARM的指令调度和延迟分支
- 基于Vue和TypeScript的极简聊天应用设计源码 - HasChat
- 基于Vue2全家桶和Zcool数据的图片收集网站设计源码 - cool-picture
- 基于C和C++的二维绘制工具设计源码 - DrawPro
- Object.defineProperty 的 IE 补丁object-defineproperty-ie-master.zip
- 整卷预览.mhtml
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0