• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

Archived

This topic is now archived and is closed to further replies.

Gladiator

3D Rotating Cube

8 posts in this topic

Hello guys, I am just getting into OpenGL and am having some problems. I get access violation errors and my computer freezes when I try to draw a cube on the screen. At the moment I just want to display the cube without rotating it. The following is my Update() function that is being executed in the message loop of my program.
  

BOOL MAIN_Update( void )
{
	if ( keys[ VK_ESCAPE ] )
		return FALSE;

	glClear( GL_COLOR_BUFFER_BIT );
	glLoadIdentity();

	glBegin( GL_QUADS );
		// face 1 (front)

		glColor3f( 1, 0, 0 );
		glVertex3f( 1, 1, 1 );
		glVertex3f( 1, -1, 1 );
		glVertex3f( -1, -1, 1 );
		glVertex3f( -1, 1, 1 );

		// face 2 (left)

		glColor3f( 0, 1, 0 );
		glVertex3f( -1, 1, 1 );
		glVertex3f( -1, -1, 1 );
		glVertex3f( -1, -1, -1 );
		glVertex3f( -1, 1, -1 );

		// face 3 (back)

		glColor3f( 0, 0, 1 );
		glVertex3f( 1, 1, -1 );
		glVertex3f( 1, -1, -1 );
		glVertex3f( -1, -1, -1 );
		glVertex3f( -1, 1, -1 );

		// face 4 (right)

		glColor3f( 1, 0, 0 );
		glVertex3f( 1, 1, 1 );
		glVertex3f( 1, -1, 1 );
		glVertex3f( 1, -1, -1 );
		glVertex3f( 1, 1, -1 );

		// face 5 (top)

		glColor3f( 1, 1, 0 );
		glVertex3f( 1, 1, 1 );
		glVertex3f( -1, 1, 1 );
		glVertex3f( -1, 1, -1 );
		glVertex3f( 1, 1, -1 );

		// face 6 (bottom)

		glColor3f( 0, 1, 1 );
		glVertex3f( 1, -1, 1 );
		glVertex3f( -1, -1, 1 );
		glVertex3f( -1, -1, -1 );
		glVertex3f( 1, -1, -1 );
	glEnd();
			
	SwapBuffers( hDC );

	return TRUE;
}

  
If anyone knows what I did wrong please let me know. ------------------------------- Did someone say "banana"?
..-=gLaDiAtOr=-..
0

Share this post


Link to post
Share on other sites
Yes, other programs run fine. So you are saying that the below code is correct?

hmm... well, here''s the functions I use to enable/disable OGL.

  

///////////////////////////////////////

// opengl.h

#ifndef __OPENGL_H
#define __OPENGL_H

#include "window.h" // this is my windows init stuff
#include <gl/gl.h>


#define COLORBITS 24
#define DEPTHBITS 16

void enableOpenGL( HWND, HDC *, HGLRC * );
void disableOpenGL( HWND, HDC, HGLRC );

#endif

///////////////////////////////////////////////


#include "opengl.h"

// opengl.cpp - my own file (is there another file in lib named the same?... i also have opengl.h


// Enable OpenGL

void enableOpenGL( HWND hWnd, HDC *hDC, HGLRC *hRC )
{
PIXELFORMATDESCRIPTOR pfd;
int format;

// 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 = COLORBITS;
pfd.cDepthBits = DEPTHBITS;
pfd.iLayerType = PFD_MAIN_PLANE;
format = ChoosePixelFormat( *hDC, &pfd );
SetPixelFormat( *hDC, format, &pfd );

// create and enable the render context (RC)

*hRC = wglCreateContext( *hDC );
wglMakeCurrent( *hDC, *hRC );

}

// Disable OpenGL

void disableOpenGL( HWND hWnd, HDC hDC, HGLRC hRC )
{
wglMakeCurrent( NULL, NULL );
wglDeleteContext( hRC );
ReleaseDC( hWnd, hDC );
}

///////////////////////////////

// main.cpp

#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif

//---------------------------------------------------------------------

// INCLUDES

//---------------------------------------------------------------------

#include "window.h"
#include "logger.h"
#include "opengl.h"

//---------------------------------------------------------------------

// GLOBALS

//---------------------------------------------------------------------

HDC hDC;
HGLRC hRC;

//---------------------------------------------------------------------

// PROTOTYPES

//---------------------------------------------------------------------


BOOL MAIN_Init( void );
BOOL MAIN_Update( void );
void MAIN_Release( void );

//---------------------------------------------------------------------

// IMPLEMENTATION

//---------------------------------------------------------------------


//=====================================================================

// WinMain() - Main Program

//=====================================================================

int WINAPI WinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow )
{
MSG msg;

if ( MAIN_Init() == FALSE )
{
MAIN_Release();
return FALSE;
}

while ( TRUE )
{
if ( PeekMessage( &msg, 0, 0, 0, PM_REMOVE ) == TRUE )
{
if ( msg.message == WM_QUIT )
break;
TranslateMessage( &msg );
DispatchMessage( &msg );
}

if ( MAIN_Update() == FALSE )
break;
}

MAIN_Release();

return msg.wParam;
}

//=====================================================================

// MAIN_Init() - Does some initializations before the main part starts

//=====================================================================

BOOL MAIN_Init( void )
{
if ( LOGGER_Open( "log.txt" ) == FALSE )
return FALSE;

if ( WINDOW_Init( GetModuleHandle( NULL ), WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE, SW_SHOW ) == FALSE )
{
LOGGER_Write( "WINDOW_Init() error" );
return FALSE;
}

enableOpenGL( hMainWnd, &hDC, &hRC );

return TRUE;
}

//=====================================================================

// MAIN_Update() - The main part of the program

//=====================================================================

BOOL MAIN_Update( void )
{
if ( keys[ VK_ESCAPE ] )
return FALSE;

glClear( GL_COLOR_BUFFER_BIT ); // Clear The Screen And The Depth Buffer

glLoadIdentity();

glBegin( GL_QUADS );
// face 1 (front)

glColor3f( 1, 0, 0 );
glVertex3f( 1, 1, 1 );
glVertex3f( 1, -1, 1 );
glVertex3f( -1, -1, 1 );
glVertex3f( -1, 1, 1 );

// face 2 (left)

glColor3f( 0, 1, 0 );
glVertex3f( -1, 1, 1 );
glVertex3f( -1, -1, 1 );
glVertex3f( -1, -1, -1 );
glVertex3f( -1, 1, -1 );

// face 3 (back)

glColor3f( 0, 0, 1 );
glVertex3f( 1, 1, -1 );
glVertex3f( 1, -1, -1 );
glVertex3f( -1, -1, -1 );
glVertex3f( -1, 1, -1 );

// face 4 (right)

glColor3f( 1, 0, 0 );
glVertex3f( 1, 1, 1 );
glVertex3f( 1, -1, 1 );
glVertex3f( 1, -1, -1 );
glVertex3f( 1, 1, -1 );

// face 5 (top)

glColor3f( 1, 1, 0 );
glVertex3f( 1, 1, 1 );
glVertex3f( -1, 1, 1 );
glVertex3f( -1, 1, -1 );
glVertex3f( 1, 1, -1 );

// face 6 (bottom)

glColor3f( 0, 1, 1 );
glVertex3f( 1, -1, 1 );
glVertex3f( -1, -1, 1 );
glVertex3f( -1, -1, -1 );
glVertex3f( 1, -1, -1 );
glEnd();

SwapBuffers( hDC );

return TRUE;
}

//=====================================================================

// MAIN_Release() - Releases all the subsystems

//=====================================================================

void MAIN_Release( void )
{
disableOpenGL( hMainWnd, hDC, hRC );
LOGGER_Close();
}



anything look suspicious? can anyone help me now?

-------------------------------
Did someone say "banana"?

..-=gLaDiAtOr=-..
0

Share this post


Link to post
Share on other sites
hmm i didnt get a reply and i thought this was everyone''s first project? im sorry if im wrong... can anyone post the easiest way to accomplish a 3D rotating cube in similar manner to the way im trying to do it? post your code pls.. im sure ill find mistake after i see your code

Thanks,
Gladiator

-------------------------------
Did someone say "banana"?

..-=gLaDiAtOr=-..
0

Share this post


Link to post
Share on other sites
I am not sure, but I dont think there is an anyways, I think it is not sure. I could be wrong.
0

Share this post


Link to post
Share on other sites
  
glRotatef(angle, x, y, z)


This is what you need to rotate the cube

so you have this variable angle defined as global

and in your update functions you put:

  

bool MAIN_UPDATE (void)
{

// after glLoadIdentity you place this functions to rotate the cube round the x, y and z axis


glRotatef(angle, 1.0f, 1.0f, 1.0f);

// Now you draw your cube

// After that you place the following line


angle++;
}



And that''s it !

0

Share this post


Link to post
Share on other sites
aight..tnx so far.... what if i just wanna display the cube (before i start coding the rotation part)?? i cant get that to work...

-------------------------------
Did someone say "banana"?

..-=gLaDiAtOr=-..
0

Share this post


Link to post
Share on other sites
I don''t have a direct answer for you, but if you seriously want to get through learning OpenGL with the minimum frustration level, head over to nehe.gamedev.net.

For the rotating cube problem, try this:
http://nehe.gamedev.net/tutorials/lesson05.asp

That''s exactly what you''re asking about, and it walks you through it one step at a time.

~Thek
0

Share this post


Link to post
Share on other sites