How do I show and control a cube in this opengl example?
Hello.
I have the following that works with XP 32 bit and CodeBlocks 17.12 and minGW.
In the following, where it says, "OpenGL animation code goes here", how do I place a cube there that I can zoom in and out and move up, down, left, right via my program code and via the keyboard?
I do not want sound and other stuff. Just a very very simple example.
>>>>> please! No Visual Studio please! <<<<<
Thank you.
This uses gl.h which I did not include since it has 1,476 lines. If you need it, I can post it. -
// main.cpp
-
-
using namespace std;
-
-
#include <windows.h>
-
#include "gl.h"
-
-
LRESULT CALLBACK WindowProc(HWND, UINT, WPARAM, LPARAM);
-
-
void EnableOpenGL(HWND hwnd, HDC*, HGLRC*);
-
-
void DisableOpenGL(HWND, HDC, HGLRC);
-
-
-
int WINAPI WinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
-
{
-
WNDCLASSEX wcex;
-
HWND hwnd;
-
HDC hDC;
-
HGLRC hRC;
-
MSG msg;
-
BOOL bQuit = FALSE;
-
float theta = 0.0f;
-
-
/* register window class */
-
wcex.cbSize = sizeof(WNDCLASSEX);
-
wcex.style = CS_OWNDC;
-
wcex.lpfnWndProc = WindowProc;
-
wcex.cbClsExtra = 0;
-
wcex.cbWndExtra = 0;
-
wcex.hInstance = hInstance;
-
wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
-
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
-
wcex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
-
wcex.lpszMenuName = NULL;
-
wcex.lpszClassName = "GLSample";
-
wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);;
-
-
-
if (!RegisterClassEx(&wcex))
-
{
-
return 0;
-
}
-
-
/* create main window */
-
hwnd = CreateWindowEx(0,
-
"GLSample",
-
"OpenGL Sample",
-
WS_OVERLAPPEDWINDOW,
-
CW_USEDEFAULT,
-
CW_USEDEFAULT,
-
256,
-
256,
-
NULL,
-
NULL,
-
hInstance,
-
NULL);
-
-
ShowWindow(hwnd, nCmdShow);
-
-
/* 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
-
{
-
/* OpenGL animation code goes here */
-
-
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
-
glClear(GL_COLOR_BUFFER_BIT);
-
-
glPushMatrix();
-
glRotatef(theta, 0.0f, 0.0f, 1.0f);
-
//glRotatef(theta, 1.0f, 1.0f, 1.0f);
-
-
glBegin(GL_TRIANGLES);
-
-
glColor3f(1.0f, 0.0f, 0.0f); glVertex2f(0.0f, 1.0f);
-
glColor3f(0.0f, 1.0f, 0.0f); glVertex2f(0.87f, -0.5f);
-
glColor3f(0.0f, 0.0f, 1.0f); glVertex2f(-0.87f, -0.5f);
-
-
glEnd();
-
-
glPopMatrix();
-
-
SwapBuffers(hDC);
-
-
theta += 1.0f;
-
Sleep (1);
-
}
-
}
-
-
/* shutdown OpenGL */
-
DisableOpenGL(hwnd, hDC, hRC);
-
-
/* destroy the window explicitly */
-
DestroyWindow(hwnd);
-
-
return msg.wParam;
-
}
-
-
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
-
{
-
switch (uMsg)
-
{
-
case WM_CLOSE:
-
{
-
PostQuitMessage(0);
-
}
-
break;
-
-
case WM_DESTROY:
-
{
-
return 0;
-
}
-
-
case WM_KEYDOWN:
-
{
-
switch (wParam)
-
{
-
case VK_ESCAPE:
-
{
-
PostQuitMessage(0);
-
}
-
break;
-
}
-
}
-
break;
-
-
default:
-
{
-
return DefWindowProc(hwnd, uMsg, wParam, lParam);
-
}
-
}
-
-
return 0;
-
}
-
-
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);
-
}
-
-
0 5066 Sign in to post your reply or Sign up for a free account.
Similar topics
by: Supra |
last post by:
in IE explorer......what control is this...it is toolbar? that had
round button...similar to netscape and firefox..
does ne 1 knows?
regards,
supra
|
by: Efkas |
last post by:
I have a full custom application with some widged extending Controls
like Label and PictureBox. I build a menu with these widgets. When
I click on one of them, it calls a function to display...
|
by: Erick T |
last post by:
Hello,
I am looking for a Web UI Control, either commercial or free. I don't
know exactly what to call it, so I will describe what I need it to do.
In a nutshell, it's a control to visually...
|
by: Stan |
last post by:
I cannot make the link buttons fire ItemCommand from
repeater control.
Here is the code:
<asp:repeater id=rptLetters runat="server">
<itemtemplate>
<asp:linkbutton id="lnkLetter"...
|
by: Max |
last post by:
Take a look at this screenshot that I've made:
http://www.subdir.net/myFiles/line_ss.jpg
I've circled the two lines that separate different sections of the form.
Does anybody know how to make...
|
by: jm |
last post by:
I was reading about the provider model and found that providers have a
definition, the contract, that all provider implementations must have.
Is this an example of polymorphic behavior because...
|
by: Milsnips |
last post by:
Hi there,
i have 2 pages: default.aspx and getTime.aspx
1. getTime.aspx has one line: "response.write(datetime.now())"
2. default.aspx has the following html code: "<script...
|
by: =?Utf-8?B?bGpsZXZlbmQy?= |
last post by:
I need to show a custom control in the DropDown of a
Windows.Forms.ToolStripMenuItem (e.g., similar to the Font Color menu item in
Word except that the control is specific to my application). I...
|
by: =?Utf-8?B?TWlrZTE5NDI=?= |
last post by:
This is an example that is supposed to work in VB
http://support.microsoft.com/kb/175512/en-us
After spending a couple of hours downloading and installing VB Express 2008
after someone told me it...
|
by: Code Bug |
last post by:
Basically, I want to connect the tip of each plane to the other. So I thought I might try creating a variable specifically for the points I want to connect: The tip of each plane.
Then, for each...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |