User forums > Using Code::Blocks
Setting up DirectX9 SDK or OpenGL GLUT for CB 12.11 on Windows XP
(1/1)
JohnSkywalker:
Hi,
I have big problem as I need to use one of those graphics libraries and each version I check and unpack on my computer seems to be missing some files or something.
When I try to compile example GLUT code whic is contained in CB 12.11 which is :
--- Code: ---/*
* GLUT Shapes Demo
*
* Written by Nigel Stewart November 2003
*
* This program is test harness for the sphere, cone
* and torus shapes in GLUT.
*
* Spinning wireframe and smooth shaded shapes are
* displayed until the ESC or q key is pressed. The
* number of geometry stacks and slices can be adjusted
* using the + and - keys.
*/
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#include <stdlib.h>
static int slices = 16;
static int stacks = 16;
/* GLUT callback Handlers */
static void resize(int width, int height)
{
const float ar = (float) width / (float) height;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-ar, ar, -1.0, 1.0, 2.0, 100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity() ;
}
static void display(void)
{
const double t = glutGet(GLUT_ELAPSED_TIME) / 1000.0;
const double a = t*90.0;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3d(1,0,0);
glPushMatrix();
glTranslated(-2.4,1.2,-6);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();
glPushMatrix();
glTranslated(0,1.2,-6);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidCone(1,1,slices,stacks);
glPopMatrix();
glPushMatrix();
glTranslated(2.4,1.2,-6);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidTorus(0.2,0.8,slices,stacks);
glPopMatrix();
glPushMatrix();
glTranslated(-2.4,-1.2,-6);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutWireSphere(1,slices,stacks);
glPopMatrix();
glPushMatrix();
glTranslated(0,-1.2,-6);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutWireCone(1,1,slices,stacks);
glPopMatrix();
glPushMatrix();
glTranslated(2.4,-1.2,-6);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutWireTorus(0.2,0.8,slices,stacks);
glPopMatrix();
glutSwapBuffers();
}
static void key(unsigned char key, int x, int y)
{
switch (key)
{
case 27 :
case 'q':
exit(0);
break;
case '+':
slices++;
stacks++;
break;
case '-':
if (slices>3 && stacks>3)
{
slices--;
stacks--;
}
break;
}
glutPostRedisplay();
}
static void idle(void)
{
glutPostRedisplay();
}
const GLfloat light_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
const GLfloat light_diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };
const GLfloat mat_ambient[] = { 0.7f, 0.7f, 0.7f, 1.0f };
const GLfloat mat_diffuse[] = { 0.8f, 0.8f, 0.8f, 1.0f };
const GLfloat mat_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat high_shininess[] = { 100.0f };
/* Program entry point */
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitWindowSize(640,480);
glutInitWindowPosition(10,10);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("GLUT Shapes");
glutReshapeFunc(resize);
glutDisplayFunc(display);
glutKeyboardFunc(key);
glutIdleFunc(idle);
glClearColor(1,1,1,1);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
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, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
glutMainLoop();
return EXIT_SUCCESS;
}
--- End code ---
The built messages displays lots of erroes in return
--- Code: ---||=== glut2013, Debug ===|
INCLUDE FILE\compiler needs\include\GL\glut.h|58|warning: ignoring #pragma comment [-Wunknown-pragmas]|
INCLUDE FILE\compiler needs\include\GL\glut.h|66|warning: ignoring #pragma comment [-Wunknown-pragmas]|
INCLUDE FILE\compiler needs\include\GL\glut.h|67|warning: ignoring #pragma comment [-Wunknown-pragmas]|
INCLUDE FILE\compiler needs\include\GL\glut.h|68|warning: ignoring #pragma comment [-Wunknown-pragmas]|
INCLUDE FILE\compiler needs\include\GL\glut.h|76|warning: ignoring #pragma warning [-Wunknown-pragmas]|
INCLUDE FILE\compiler needs\include\GL\glut.h|77|warning: ignoring #pragma warning [-Wunknown-pragmas]|
INCLUDE FILE\compiler needs\include\GL\glut.h|50|error: redeclaration of C++ built-in type 'wchar_t' [-fpermissive]|
INCLUDE FILE\compiler needs\include\GL\glut.h|549|warning: 'int glutCreateMenu_ATEXIT_HACK(void (__attribute__((__cdecl__)) *)(int))' defined but not used [-Wunused-function]|
||=== Build finished: 1 errors, 7 warnings (0 minutes, 0 seconds) ===|
--- End code ---
When I try to run DirectX9 example code which is:
--- Code: ---#include <d3d9.h>
#include <strsafe.h>
LPDIRECT3D9 g_pD3D = NULL; // Used to create the D3DDevice
LPDIRECT3DDEVICE9 g_pd3dDevice = NULL; // Our rendering device
HRESULT InitD3D( HWND hWnd )
{
if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
return E_FAIL;
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof( d3dpp ) );
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &g_pd3dDevice ) ) )
{
return E_FAIL;
}
return S_OK;
}
VOID Cleanup()
{
if( g_pd3dDevice != NULL )
g_pd3dDevice->Release();
if( g_pD3D != NULL )
g_pD3D->Release();
}
VOID Render()
{
if( NULL == g_pd3dDevice )
return;
// Clear the backbuffer to a blue color
g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB( 0, 0, 255 ), 1.0f, 0 );
// Begin the scene
if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
{
// Rendering of scene objects can happen here
// End the scene
g_pd3dDevice->EndScene();
}
// Present the backbuffer contents to the display
g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch( msg )
{
case WM_DESTROY:
Cleanup();
PostQuitMessage( 0 );
return 0;
case WM_PAINT:
Render();
ValidateRect( hWnd, NULL );
return 0;
}
return DefWindowProc( hWnd, msg, wParam, lParam );
}
INT WINAPI wWinMain( HINSTANCE hInst, HINSTANCE, LPWSTR, INT )
{
// Register the window class
WNDCLASSEX wc =
{
sizeof( WNDCLASSEX ), CS_CLASSDC, MsgProc, 0L, 0L,
GetModuleHandle( NULL ), NULL, NULL, NULL, NULL,
L"D3D Tutorial", NULL
};
RegisterClassEx( &wc );
// Create the application's window
HWND hWnd = CreateWindow( L"D3D Tutorial", L"D3D Tutorial 01: CreateDevice",
WS_OVERLAPPEDWINDOW, 100, 100, 300, 300,
NULL, NULL, wc.hInstance, NULL );
// Initialize Direct3D
if( SUCCEEDED( InitD3D( hWnd ) ) )
{
// Show the window
ShowWindow( hWnd, SW_SHOWDEFAULT );
UpdateWindow( hWnd );
// Enter the message loop
MSG msg;
while( GetMessage( &msg, NULL, 0, 0 ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
}
UnregisterClass( L"D3D Tutorial", wc.hInstance );
return 0;
}
--- End code ---
I get built messages :
--- Code: ---||=== directx9test, Debug ===|
F:\include\d3d9types.h|25|warning: ignoring #pragma warning [-Wunknown-pragmas]|
F:\include\d3d9types.h|2411|warning: ignoring #pragma warning [-Wunknown-pragmas]|
F:\include\d3d9.h|2025|warning: "/*" within comment [-Wcomment]|
F:\include\d3d9.h|2026|warning: "/*" within comment [-Wcomment]|
F:\Moje Dokumenty\directx9test\main.cpp|2|fatal error: strsafe.h: No such file or directory|
||=== Build finished: 1 errors, 4 warnings (0 minutes, 4 seconds) ===|
--- End code ---
Thank you in advance for helping me cause as hard as I try I can't use either glut either direct succesfully. Please don't ignore my rookie problem I have read so many tutorials how to set up both libraries and trying to do it somehow since 3 days failing all the time :/.
BlueHazzard:
I would try to search a pakage for the right compiler...
warning: ignoring #pragma comment [-Wunknown-pragmas]| seems that you are using the wrong compiler....
also this error comes from using the wrong compiler: error: redeclaration of C++ built-in type 'wchar_t' [-fpermissive]|
patchell:
I am trying to do the same thing, and have the same problem. And so far, I have not found a solution. I want to be able to build the directX apps with the MinGW compiler, but it seems that this project is not going to cooperate. I suspect I am going to have to modify the template code in order to make this compile with the gcc compiler. Am I wrong? I would sure love a little guidance as well.
patchell:
OK, well that was quick. Solved the problem myself. I made the following changes to the template code:
1. Got rid of #include "strsafe.h"
2. In several places you will find something that looks like this:
L"some string"
Well, just get rid of the L (it was a macro in the strsafe.h file).
3 Turn the winmain line to look like this:
extern "C" int WINAPI WinMain(etc.....
Lets me compile, anyway. When the program runs, I get a little window that is all blue. Hopefully, that is what the template is supposed to do.
Navigation
[0] Message Index
Go to full version