home dev games gallery work
Lewpen.com»Research & Development»3D Graphics»OpenGL»Reflective Sphere

Reflective Sphere

Analytical reflections in OpenGL

/ Source / Main.cpp

#include <windows.h>
#include <mmsystem.h>
#include "Pattern.h"



//--- DATA -------------------------------------------------------------------//

HINSTANCE hMainInstance;
HWND hMainWindow = NULL;

char szAppName[40] = "Lewpen's pattern generator";



//---- FUNCTION PROTOS -------------------------------------------------------//

PATTERN_A   *a1, *a2, *a3, *a4, *a5;
PATTERN_RGB *rgb1, *rgb2, *rgb3, *rgb4, *rgb5;



//---- Startup ---------------------------------------------------------------//

void Startup()
{
  Pattern_Startup();

  a1 = Pattern_Create_A();
  a2 = Pattern_Create_A();
  a3 = Pattern_Create_A();
  a4 = Pattern_Create_A();
  a5 = Pattern_Create_A();

  rgb1 = Pattern_Create_RGB();
  rgb2 = Pattern_Create_RGB();
  rgb3 = Pattern_Create_RGB();
  rgb4 = Pattern_Create_RGB();
  rgb5 = Pattern_Create_RGB();
}



//---- Redraw ----------------------------------------------------------------//

void Redraw2(HDC dc)
{
  int time = timeGetTime();

  Pattern_Fn_A_Checkers(a3);

  Pattern_Fn_A_Plasma1(a1, time/17);
  Pattern_Fn_A_Plasma2(a2, time/36);
  Pattern_Fn_A2_A2_Lookup(a4, a3, a1, a2);

  Pattern_Fn_A_Plasma3(a1, time/21);
  Pattern_Fn_A_Plasma1(a2, time/48);
  Pattern_Fn_A2_A2_Lookup(a5, a3, a1, a2);

  Pattern_Fn_RGB_Checkers(rgb2);

  Pattern_Fn_RGB2_A2_Lookup(rgb1, rgb2, a4, a5);

  Pattern_Display(dc, rgb1);
}



//---- Redraw ----------------------------------------------------------------//

void Redraw(HDC dc)
{
  int time = timeGetTime();

  Pattern_Fn_A_Plasma1(a1, time/17);
  Pattern_Fn_A_Plasma2(a2, time/36);
  Pattern_Fn_A_Plasma3(a3, time/41);

//  Pattern_Fn_RGB_A3(rgb2, a1, a1, a1);

  Pattern_Fn_RGB_Checkers(rgb2);

  Pattern_Fn_RGB2_A2_Lookup(rgb1, rgb2, a1, a2);

  Pattern_Display(dc, rgb1);
}



//---- WinProc ---------------------------------------------------------------//

LRESULT CALLBACK WinProc(HWND hwnd, UINT uiMsg, UINT wParam, LONG lParam)
{
  HDC dc;
  PAINTSTRUCT ps;

  switch(uiMsg) {

  case WM_CREATE:
    Startup();
    SetTimer(hwnd, 1, 10, NULL);
    break;

  case WM_TIMER:
    dc = GetDC(hwnd);
    Redraw(dc);
    ReleaseDC(hwnd, dc);
    return 0L;

  case WM_PAINT:
    dc = BeginPaint(hwnd, &ps);
    Redraw(dc);
    EndPaint(hwnd, &ps);
    return 0L;

  case WM_NCHITTEST:
    return HTCAPTION;

  case WM_DESTROY:
    KillTimer(hwnd, 1);
    PostQuitMessage(0);
    return 0L;

  }

  return DefWindowProc(hwnd, uiMsg, wParam, lParam);
}




//---- WinMain ---------------------------------------------------------------//

int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
  WNDCLASS wndclass;
  char cSwitch;
  MSG msg;
  RECT rc;

  hMainInstance = hInstance;

  if(hPrevInstance) return 1;

  //- Create window class

  wndclass.style         = CS_HREDRAW | CS_VREDRAW;
  wndclass.lpfnWndProc   = WinProc;
  wndclass.cbClsExtra    = 0;
  wndclass.cbWndExtra    = 0;
  wndclass.hInstance     = hInstance;
  wndclass.hIcon         = NULL;
  wndclass.hCursor       = LoadCursor(NULL, IDC_ARROW);
  wndclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
  wndclass.lpszMenuName  = NULL;
  wndclass.lpszClassName = szAppName;

  if(!RegisterClass(&wndclass)) return 1;

  //- Create main window

  hMainWindow = CreateWindowEx(
    0,
    szAppName,
    szAppName,
    WS_POPUP,
    CW_USEDEFAULT,
    CW_USEDEFAULT,
    256,
    256,
    NULL,
    NULL,
    hInstance,
    NULL
  );

  if(!hMainWindow) return 1;

  ShowWindow(hMainWindow, SW_SHOW);

  //- Message loop

  while(TRUE) {
    while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
      if (msg.message == WM_QUIT) return TRUE;
      TranslateMessage(&msg);
      DispatchMessage(&msg);
    }
    HDC dc = GetDC(hMainWindow);
    Redraw(dc);
    ReleaseDC(hMainWindow, dc);
  }

  return 0;
}



//---- END OF FILE -----------------------------------------------------------//
Related Articles

Procedural city block layout

Animated 4-dimensional objects mapped down to 3D

Simulating a cloth falling and slipping over objects

Windows C++ OpenGL example

Games

The Dodge Game
Flatspace

2-Player Games:

Quake 2D
Meteora

Puzzle Games:

Mini Tetris
Sudoku Solver

Development

3D Graphics:

3D Graphics Articles
WebGL Examples
OpenGL Examples
Flash 3D Engine
Java 3D Engine

Development:

Programming Articles
Game Development Examples

Work

Portfolio
Clients
Startups & Projects
Expertise

Links

CubeLogix Studios
PHP Charts & Graphs
Local Legends Football