Don´t pay too much attention to me, because I just started this stuff. But, here´s some food for thought.
Just because you can´t “move” the statue of liberty does´nt mean it´s not there.
OpenGL comes with a very rudimentary camera for the user to see inside virtual 3d space without having to set projection parameters like frustum or perspective(setting of 6 clipping planes) or viewport or matrices or gluLookAt in order to move a 3d scene back towards us at point origin(0,0,0), so that we don´t loose sight of it.
It´s a myopic camera to say the least, but, it´s there. If you place 3d object in 3d space, preferably smaller than 1.0, between +1… -1 Z axis, +1…-1 X axis and +1…-1 Y axis. The user should be able to see it, as long as it´s(the 3d object) not translated away from this “very tiny” viewing area. Place your finger right on the center of the monitor screen. That, in a way can be though of as point origin or (X 0,Y 0,Z 0), where the cmaera is. That´s where our real 3d space meets 3d “virtual space”.
But, since we are “not” inside this virtual 3d space but,rather outside of it, in our own “real” 3d space then, we must bring this virtual world towards us at (0,0,0). Otherwise, 3d objects(gun, ect.) attached to our first person or the third person object, will just go off into the distance as we translate(move) them inside virtual 3d space.
Thus we move the 3d virtual scene sort of in an inverse way to the way these 3d objects move, in order to keep a focus on them.
The example below might prove once and for all that there is a default camera at (0,0,0) origin that can see, in a very myopic way, inside 3d virtual space. Notice that there is no projection setup or viewport or matrices or gluLookAt to refine the viewing parameters. But, the pyramid can clearly be seen. Translate ir or rotate it, and it will start to be clipped out of view.
We can see it because there´s a rudimmentary viewing defaul set up. Call it a camera or not.
I think the pyramid example will complie with any C++ compiler, given the right linkers, ect.
Live long and prosper.
BeginOpenGL
/***************************************
***************************************/
/Includes/
#include <windows.h>
#include <gl/gl.h>
/**************************
**************************/
LRESULT CALLBACK WndProc (HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam);
void EnableOpenGL (HWND hWnd, HDC *hDC, HGLRC *hRC);
void DisableOpenGL (HWND hWnd, HDC hDC, HGLRC hRC);
/**************************
**************************/
int WINAPI WinMain (HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int iCmdShow)
{
WNDCLASS wc;
HWND hWnd;
HDC hDC;
HGLRC hRC;
MSG msg;
BOOL bQuit = FALSE;
/´declare the var theta, to be used as an angle in rotations/
float theta = 0.0;
/* register window class */
wc.style = CS_OWNDC;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor (NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = “GLSample”;
RegisterClass (&wc);
/* create main window */
hWnd = CreateWindow (
“GLSample”, “DEV C++ 4.9.8.0 3D Engine”,
WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,
0, 0, 1024, 768,
NULL, NULL, hInstance, NULL);
/* enable OpenGL for the window */
EnableOpenGL (hWnd, &hDC, &hRC);
/* program main loop /
while (!bQuit)
{
/ check for messages /
if (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
{
/ handle or dispatch messages /
if (msg.message == WM_QUIT)
{
bQuit = TRUE;
}
else
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
}
else
{
/ OPEN GL ANIMATION CODE FOR PRIMITIVES GOES BELOW */
/Set the Background color to black/
glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
/Clear previous frame color buffer to enable drawing of next frame/
/Clear previous frame depth buffer to enable drawing of next frame/
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
/Clear existing internal tansformations by loading identity matrix/
glLoadIdentity ();
/move all vertices(the pyramid) 1 unit forward on z axis/
glTranslatef (0, 0, -1);
/rotate(spin) pyramid around it´s vertical Y axis/
glRotatef (theta, 0, 1, 0);
/access OpenGl´s matrix stack to save transformations/
glPushMatrix ();
/Join vertex 1,2,3…1,3,4 and 1,4,5(vertice 1 is common to the rest)/
glBegin (GL_TRIANGLE_FAN);
/assign color and position in 3d space to each vertex thru its 3 coords/
glColor3f (0,.5, 1); glVertex3f ( 0, 1, 0);
glColor3f (1, .5, 0); glVertex3f (-1,-1, 1);
glColor3f (1, .3, 1); glVertex3f ( 1,-1, 1);
glColor3f (.2, 0, 1); glVertex3f ( 1,-1,-1);
glColor3f (0, 1, 0); glVertex3f (-1,-1,-1);
glColor3f (1, .7, 0); glVertex3f (-1,-1, 1);
glEnd ();
/restore OpenGl´s matrix stack transformations to continue to translatef/
glPopMatrix ();
/Make the pyramid visible/
SwapBuffers (hDC);
theta += .5;
Sleep (1);
}
}
/* shutdown OpenGL */
DisableOpenGL (hWnd, hDC, hRC);
/* destroy the window explicitly */
DestroyWindow (hWnd);
return msg.wParam;
}
/********************
********************/
LRESULT CALLBACK WndProc (HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
return 0;
case WM_CLOSE:
PostQuitMessage (0);
return 0;
case WM_DESTROY:
return 0;
case WM_KEYDOWN:
switch (wParam)
{
case VK_ESCAPE:
PostQuitMessage(0);
return 0;
}
return 0;
default:
return DefWindowProc (hWnd, message, wParam, lParam);
}
}
/*******************
*******************/
void EnableOpenGL (HWND hWnd, HDC *hDC, HGLRC *hRC)
{
PIXELFORMATDESCRIPTOR pfd;
int iFormat;
/* get the device context (DC) */
*hDC = GetDC (hWnd);
/* set the pixel format for the DC */
ZeroMemory (&pfd, sizeof (pfd));
pfd.nSize = sizeof (pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24;
pfd.cDepthBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE;
iFormat = ChoosePixelFormat (*hDC, &pfd);
SetPixelFormat (*hDC, iFormat, &pfd);
/* create and enable the render context (RC) */
*hRC = wglCreateContext( *hDC );
wglMakeCurrent( *hDC, *hRC );
}
/******************
******************/
void DisableOpenGL (HWND hWnd, HDC hDC, HGLRC hRC)
{
wglMakeCurrent (NULL, NULL);
wglDeleteContext (hRC);
ReleaseDC (hWnd, hDC);
}