• 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.

LittleTaz

unknown problem (no drawing)

9 posts in this topic

Hi everybody! 2 days i ago, i bought this OGL Game Programming book ! i really like it. but: when i finished coding the simpliest OGL app (drawing a triangle), it simple displays anything !!! i downloaded the source for this chapter from the webpage, compiled it and it worked. i''ve been searching for the problem for one day ... i didn''t find any. this is where you come in. i hope you can tell me where the problem is. the code isn''t documentated at all, but easy to understand (hopefully), and pretty "short". would be great if you can help me !
  

#define WIN32_LEAN_AND_MEAN

#include <windows.h>

#include <gl/gl.h>
#include <gl/glu.h>

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

// defines


#define MY_APPLICATION_NAME		"GLTest1"
#define SCREEN_WIDTH			800
#define SCREEN_HEIGHT			600
#define SCREEN_BPP				32


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

// globals:

HDC		g_hDC;
bool	fullscreen = false;


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

// prototypes:

void RenderScene();


void ChangeResolution()
{

	DEVMODE	devModeScreen;

	memset(&devModeScreen,0,sizeof(devModeScreen));
	devModeScreen.dmSize = sizeof(devModeScreen);
	devModeScreen.dmPelsHeight = SCREEN_HEIGHT;
	devModeScreen.dmPelsWidth = SCREEN_WIDTH;
	devModeScreen.dmBitsPerPel = SCREEN_BPP;
	devModeScreen.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL;

	if(ChangeDisplaySettings(&devModeScreen, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
		fullscreen = false;

}


void SetupPixelFormat()
{

	int nPixelFormat;

	static PIXELFORMATDESCRIPTOR pfd = {
		sizeof(PIXELFORMATDESCRIPTOR),
		1,
		PFD_DRAW_TO_WINDOW |
		PFD_SUPPORT_OPENGL |
		PFD_DOUBLEBUFFER,
		PFD_TYPE_RGBA,
		SCREEN_BPP,
		0, 0, 0, 0, 0, 0,
		0,
		0,
		0,
		0, 0, 0, 0,
		16,
		0,
		0,
		PFD_MAIN_PLANE,
		0,
		0, 0, 0 };

	nPixelFormat = ChoosePixelFormat(g_hDC,&pfd);

	SetPixelFormat(g_hDC,nPixelFormat,&pfd);

}


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

// WindowProcedure

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{

	static HGLRC		hRC;

	int width, height;

	switch(message)
	{
	case WM_CREATE:
		g_hDC = GetDC(hwnd);
		SetupPixelFormat();

		hRC = wglCreateContext(g_hDC);
		wglMakeCurrent(g_hDC,hRC);
		return 0;

		break;


	case WM_CLOSE:
		wglMakeCurrent(g_hDC,NULL);
		wglDeleteContext(hRC);
		ReleaseDC(hwnd,g_hDC);

		PostQuitMessage(0);
		return 0;
		break;

	case WM_SIZE:
		height = HIWORD(lParam);
		width = LOWORD(wParam);

		if(height==0)
		{
			height=1;
		}

		glViewport(0,0,width,height);
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();

		gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,1.0f,1000.0f);

		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();

		return 0;
		break;

	default:
		break;
	}

	return DefWindowProc(hwnd,message,wParam,lParam);

}

void InitGLStates()
{
	// enable the depth buffer and backface culling

	glEnable(GL_DEPTH_TEST);
	glEnable(GL_CULL_FACE);

	// use smooth shading

	glShadeModel(GL_SMOOTH);

	// Clear background to black

	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
}


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

// WinMain

// Entrypoint

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{

	WNDCLASSEX		windowClass;
	HWND			hWnd;
	MSG				msg;
	bool			done;
	DWORD			exWindowStyle, windowStyle;
	RECT			windowRect;

	if(fullscreen)
		ChangeResolution();

	windowClass.cbClsExtra = 0;
	windowClass.cbSize = sizeof(WNDCLASSEX);
	windowClass.cbWndExtra = 0;
	windowClass.hbrBackground = NULL;
	windowClass.hCursor = LoadCursor(NULL,IDC_ARROW);
	windowClass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
	windowClass.hIconSm = LoadIcon(NULL,IDI_APPLICATION);
	windowClass.hInstance = hInstance;
	windowClass.lpfnWndProc = (WNDPROC)WndProc;
	windowClass.lpszClassName = MY_APPLICATION_NAME;
	windowClass.lpszMenuName = NULL;
	windowClass.style = CS_HREDRAW | CS_VREDRAW;

	if(!RegisterClassEx(&windowClass))
	{
		MessageBox(NULL,"Error: WindowCreation failure","Error",MB_OK);
		return 0;
	}

	if(fullscreen)
	{
		exWindowStyle = WS_EX_APPWINDOW;
		windowStyle = WS_POPUP;
	}
	else
	{
		exWindowStyle = NULL;
		windowStyle = WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_SYSMENU |
			WS_CLIPCHILDREN | WS_CLIPSIBLINGS;

		windowRect.top = 0;
		windowRect.left = 0;
		windowRect.bottom = SCREEN_HEIGHT;
		windowRect.right = SCREEN_WIDTH;
	}

	AdjustWindowRectEx(&windowRect,windowStyle,NULL,exWindowStyle);

	hWnd = CreateWindowEx(exWindowStyle,
						MY_APPLICATION_NAME,MY_APPLICATION_NAME,
						windowStyle,
						0,0,
						windowRect.right,windowRect.bottom,
						NULL,
						NULL,
						hInstance,
						NULL);

	if(!hWnd)
	{
		MessageBox(NULL,"Error: WindowCreation failure","Error",MB_OK);
		return 0;
	}

	ShowWindow(hWnd,SW_SHOWNORMAL);
	UpdateWindow(hWnd);

	done=false;

	// finally initiate the GLStates:

	InitGLStates();

	while(!done)
	{
		PeekMessage(&msg,hWnd,NULL,NULL,PM_REMOVE);

		if(msg.message == WM_QUIT)
		{
			done = true;
		}
		else
		{

			RenderScene();
			
			TranslateMessage(&msg);
			DispatchMessage(&msg);

		}
	}

	// get back to normal desktop size:

	if(fullscreen)
		ChangeDisplaySettings(NULL,0);

	return msg.wParam;
}






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

// Render function

void RenderScene()
{

	// clear screen and depth buffer

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);										
	glLoadIdentity();

	// move back 15 units

	glTranslatef(0.0f, 0.0f, -50.0f);

	// draw our smooth shaded triangle

	glBegin(GL_TRIANGLES);
		glColor3f(1.0f, 0.0f, 0.0f);				// red vertex

		glVertex3f(-10.0f, -10.0f, -5.0f);			
		glColor3f(0.0f, 1.0f, 0.0f);				// green vertex

		glVertex3f(20.0f, -10.0f, -5.0f);
		glColor3f(0.0f, 0.0f, 1.0f);				// blue vertex

		glVertex3f(-10.0f, 20.0f, -5.0f);
	glEnd();


	glFlush();
	SwapBuffers(g_hDC);			// bring backbuffer to foreground


}
  
thnx in advance for any suggestions ! Have a nice day !
Grimmm Games - Game Developer"
0

Share this post


Link to post
Share on other sites
no replies ?

tell me please, has someone tried this code yet ?
has someone looked over it, and tried to find an error ?


please post, if u looked, but couldn''t find any errors !
P L E A S E !

Have a nice day !
Grimmm Games - Game Developer
0

Share this post


Link to post
Share on other sites
try to replate that:

while(!done)
{ PeekMessage(&msg,hWnd,NULL,NULL,PM_REMOVE); if(msg.message == WM_QUIT)
{
done = true;
}
else
{
RenderScene();
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

with something like:

while(!done)
{ if(PeekMessage(&msg,hWnd,NULL,NULL,PM_REMOVE))
{
if(msg.message == WM_QUIT)
done = true;
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
else
RenderScene();
}
}


but i have not tried if this is the only problem...
0

Share this post


Link to post
Share on other sites
thnx for replying.
but your suggestion doesn''t work, sadly

maybe someone other found a solution !?
i hope so ! i can''t imagine where the problem could be. i compared the downloaded source with mine, but there is no really difference between them ...

the downloaded source, draws the triangle, but mine doesn''t

i really need your help !!!!

Have a nice day !
Grimmm Games - Game Developer
0

Share this post


Link to post
Share on other sites
I would check out your code but cutting and pasting from here into MSVC just isnt happening. lol All the newlines disappear when the code is within the source tags.

If you send the code to me via email I will be happy to check it out for you.

toasted2k@yahoo.com

Seeya
Krippy
0

Share this post


Link to post
Share on other sites
You are missing the viewport and projection matrix settings.

Put this at the begining of render scene :

  
//this will define how much of the window will be used for

//drawing. Here we ask for the full window

glViewport( 0, 0,SCREEN_WIDTH, SCREEN_HEIGHT );

glMatrixMode( GL_PROJECTION );
glLoadIdentity();


for the projection matrix, you have 2 choices :
Perpective (object farther from the viewpoint are smaller)
or orthogonal (object look the same size even if they are far
away from the viewpoint)


to see your triangles, the coordinates should fit in the
projection definition

Just put one of the following 2 function calls.

  
//for ortho:

glOrtho( 50, -50, -50, 50, 50, -50 );

//for perspective :

glFrustum( -5, 5, -5, 5, 1, 100 );
0

Share this post


Link to post
Share on other sites
eh.. i got it to work for you.. but i ended up completely re-writing EVERYTHING. Oh well, kept my mind off work =)
0

Share this post


Link to post
Share on other sites
Actually he had the proper code to setup his perspective and viewport. It is in WndProc on WM_SIZE.

I already emailed him about this, but his problem was just a typo really. Just for reference here is the problem:

  
case WM_SIZE:
height = HIWORD(lParam);
width = LOWORD(wParam);


wParam is wrong on the width assignment it should be lParam. The LOWORD of wParam was equating to 0 so he was getting a width of 0 on his viewport.

Julio: Thanks! I knew there had to be a way. lol

Seeya
Krippy
0

Share this post


Link to post
Share on other sites
THANKS TO ALL OF YOU!!!
the code of krippy2k works !!! it''s great, thnx for all your solutions !!
THANX
thats amazing !
really great, i am so happy :]]]

THANKS A LOT !!!

(is that a bit too much "thanks" ?)

Have a nice day !
Grimmm Games - Game Developer
0

Share this post


Link to post
Share on other sites