Sign in to follow this  
pheonix2468

Need help starting an fps

Recommended Posts

pheonix2468    164
OK ill be honest im not that good at codeing. Im pretty new and i want to make an fps, i know how to do quads and stuff so i can make the levels and stuff but i need help to get started on keyboard interaction (say W,S,A,D) for movement and the mouse to look around. I have experience with basic4gl wich is a bit like c++ but with some differences like (int(in c++) is dim(in basic4gl)) but i lost most of my code for that.PLZ could you guys help me as i ant to get started in fps's.

Share this post


Link to post
Share on other sites
Ademan555    361
Erm, you have no chance what so ever of creating a FPS if you are "not that good at codeing" (which is coding btw :-P)

i suggest you keep on programming, do some smaller projects just to get a feel for openGL and perfect your C++ skills, then try and tackle a FPS.

hope that helps
-Dan

Share this post


Link to post
Share on other sites
wolverine    358
I don't meen to be rough or to break down your dreams... but Ademan555 is completely right.

Doing an FPS is a complete overkill for someone working alone, and with little coding skills. Start small. Try to make small demo programs, learning something new with everyone of them... just gathering knowledge and learning.

And, by the way, ask yourself why do you want to make an FPS. If you want to make an FPS because that's the type of games you prefer, then i would point you to making mods. The advantage of making mods is that the engine already exists, you change the content of the game. And i must say that just making new contents for an already existing engine is a lot of work by itself. Now imagine making everything by yourself.
If, by the other side, you want to make an FPS because you are curious about the technology and techniques behind it, than stick to Ademan555 advice and start with small projects.

Best of lucks on whatever path that lies before you!

Share this post


Link to post
Share on other sites
pheonix2468    164
Thanks for the advice. Although before i came back to this i had a go at trying to convert an fps from another language basic4gl, it's pretty simple, a coridoor wich you can move arround in by useing the arrow keys and i changed them to W, S, A and D. But whilst converting dev c++ says that cos and sin aren't declared (i used cosd and sind for movement)like this;
if (keys['A']);
{
camx = camx + 1;
}
if (keys['D']);
{
camx = camx - 1;
}
if (keys['W']);
{
camx = camx - sin (camang) * .2;
camz = camz - cos (camang) * .2;

}
if (keys['S']);
{
camx = camx + sin (camang) * .2;
camz = camz + cos (camang) * .2;
}
is there a file that needs to be included for me to use these or does c++ use something different. You're help would be appreciated, though if i've gone about it wrong, could you tell me which direction i should be going in either carry on and look for help in the tutorials and places or should i forget about an fps and start on something alot easier.

Share this post


Link to post
Share on other sites
Ademan555    361
For the record, if your using c++, you should include cmath not math.h its the "new standard" way of doing things just like iostream over iostream.h (well kinda, since math is a carry over from the old c days, hence the cmath)

hope that helps,
-Dan

Share this post


Link to post
Share on other sites
Ademan555    361
i said cmath not cmath.h

double edit: (mispelled edit lol) edit: no disadvantages, and the advantage is being more "correct" and considering it costs you nothing more than typing a different name, you might as well do it

-Dan

Share this post


Link to post
Share on other sites
pheonix2468    164
Thanks. It compile and runs but i cant see anything never have been able to maybe its just me heres the code laugh at it all you like:



#include <windows.h>
#include <cmath>
#include <gl/glaux.h>
#include <gl/gl.h>
#include <gl/glu.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 keys[256];
int camx;
int camy;
int camz;
float camang;


int WINAPI WinMain (HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int iCmdShow)
{
WNDCLASS wc;
HWND hWnd;
HDC hDC;
HGLRC hRC;
MSG msg;
BOOL bQuit = FALSE;
float theta = 0.0f;


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);


hWnd = CreateWindow (
"GLSample", "Coridoor",
WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,
0, 0, 1024, 768,
NULL, NULL, hInstance, NULL);


EnableOpenGL (hWnd, &hDC, &hRC);


while (!bQuit)
{

if (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
{

if (msg.message == WM_QUIT)
{
bQuit = TRUE;
}
else
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
}
else
{

glMatrixMode (GL_PROJECTION);
glLoadIdentity();
glMatrixMode (GL_MODELVIEW);
glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
glClear (GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
glLoadIdentity ();
glRotatef (-camang, 0, 1, 0);
glTranslatef (-camx, -camy, -camz);
glPushMatrix ();

// left wall
glBegin (GL_QUADS);
glColor3f(0, 0, 1); glVertex3f( -5, 0, 0);
glColor3f(0, 0, 1); glVertex3f( -5, 10, 0);
glColor3f(0, 0, 1); glVertex3f( -5, 10,-50);
glColor3f(0, 0, 1); glVertex3f( -5, 0,-50);
glEnd ();
//Top wall
glBegin (GL_QUADS);
glColor3f ( 1, 0, 0); glVertex3f ( 5, 0, 0);
glColor3f ( 1, 0, 0); glVertex3f ( 5, 10, 0);
glColor3f ( 1, 0, 0); glVertex3f ( 5, 10,-50);
glColor3f ( 1, 0, 0); glVertex3f ( 5, 0,-50);
glEnd ();
// Floor
glBegin (GL_QUADS);
glColor3f ( 0, 1, 0); glVertex3f ( 5, 0, 0);
glColor3f ( 0, 1, 0); glVertex3f ( -5, 0, 0);
glColor3f ( 0, 1, 0); glVertex3f ( -5, 0,-50);
glColor3f ( 0, 1, 0); glVertex3f ( 5, 0,-50);
glEnd ();
// ceiling
glBegin (GL_QUADS);
glColor3f ( 1, 0, 0); glVertex3f ( 5, 10, 0);
glColor3f ( 0, 1, 0); glVertex3f ( -5, 10, 0);
glColor3f ( 0, 0, 1); glVertex3f ( -5, 10,-50);
glColor3f ( 0, 1, 0); glVertex3f ( 5, 10,-50);
glEnd ();
glPopMatrix ();

// Move camera

if (keys['A']);
{
camx = camx + 1;
}
if (keys['D']);
{
camx = camx - 1;
}
if (keys['W']);
{
camx = camx - sin (camang) * 0.2;
camz = camz - cos (camang) * 0.2;

}
if (keys['S']);
{
camx = camx + sin (camang) * .2;
camz = camz + cos (camang) * .2;
}
camx = 0;
camy = 2;
camz = 0;
SwapBuffers (hDC);
Sleep (1);
}
}


DisableOpenGL (hWnd, hDC, hRC);

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;


*hDC = GetDC (hWnd);


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);


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

}




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

Share this post


Link to post
Share on other sites
Ademan555    361
The first thing you need to do is add [_source_] [/_source_] tags (without the underscores) to that code, people dont like code the way youve pasted it, plus it preserves tabs and is syntax highlighted, once you add the source tags people will be more likely to take a look at it

hope that helps
-Dan

Share this post


Link to post
Share on other sites
pheonix2468    164
ok



#include <windows.h>
#include <cmath>
#include <gl/glaux.h>
#include <gl/gl.h>
#include <gl/glu.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 keys[256];
int camx;
int camy;
int camz;
float camang;


int WINAPI WinMain (HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int iCmdShow)
{
WNDCLASS wc;
HWND hWnd;
HDC hDC;
HGLRC hRC;
MSG msg;
BOOL bQuit = FALSE;
float theta = 0.0f;


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);


hWnd = CreateWindow (
"GLSample", "Coridoor",
WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,
0, 0, 1024, 768,
NULL, NULL, hInstance, NULL);


EnableOpenGL (hWnd, &hDC, &hRC);


while (!bQuit)
{

if (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
{

if (msg.message == WM_QUIT)
{
bQuit = TRUE;
}
else
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
}
else
{

glMatrixMode (GL_PROJECTION);
glLoadIdentity();
glMatrixMode (GL_MODELVIEW);
glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
glClear (GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
glLoadIdentity ();
glRotatef (-camang, 0, 1, 0);
glTranslatef (-camx, -camy, -camz);
glPushMatrix ();

// left wall
glBegin (GL_QUADS);
glColor3f(0, 0, 1); glVertex3f( -5, 0, 0);
glColor3f(0, 0, 1); glVertex3f( -5, 10, 0);
glColor3f(0, 0, 1); glVertex3f( -5, 10,-50);
glColor3f(0, 0, 1); glVertex3f( -5, 0,-50);
glEnd ();
//Top wall
glBegin (GL_QUADS);
glColor3f ( 1, 0, 0); glVertex3f ( 5, 0, 0);
glColor3f ( 1, 0, 0); glVertex3f ( 5, 10, 0);
glColor3f ( 1, 0, 0); glVertex3f ( 5, 10,-50);
glColor3f ( 1, 0, 0); glVertex3f ( 5, 0,-50);
glEnd ();
// Floor
glBegin (GL_QUADS);
glColor3f ( 0, 1, 0); glVertex3f ( 5, 0, 0);
glColor3f ( 0, 1, 0); glVertex3f ( -5, 0, 0);
glColor3f ( 0, 1, 0); glVertex3f ( -5, 0,-50);
glColor3f ( 0, 1, 0); glVertex3f ( 5, 0,-50);
glEnd ();
// ceiling
glBegin (GL_QUADS);
glColor3f ( 1, 0, 0); glVertex3f ( 5, 10, 0);
glColor3f ( 0, 1, 0); glVertex3f ( -5, 10, 0);
glColor3f ( 0, 0, 1); glVertex3f ( -5, 10,-50);
glColor3f ( 0, 1, 0); glVertex3f ( 5, 10,-50);
glEnd ();
glPopMatrix ();

// Move camera

if (keys['A']);
{
camx = camx + 1;
}
if (keys['D']);
{
camx = camx - 1;
}
if (keys['W']);
{
camx = camx - sin (camang) * 0.2;
camz = camz - cos (camang) * 0.2;

}
if (keys['S']);
{
camx = camx + sin (camang) * .2;
camz = camz + cos (camang) * .2;
}
camx = 0;
camy = 2;
camz = 0;
SwapBuffers (hDC);
Sleep (1);
}
}


DisableOpenGL (hWnd, hDC, hRC);

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;


*hDC = GetDC (hWnd);


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);


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

}




void DisableOpenGL (HWND hWnd, HDC hDC, HGLRC hRC)
{
wglMakeCurrent (NULL, NULL);
wglDeleteContext (hRC);
ReleaseDC (hWnd, hDC);
}
[\source]

Share this post


Link to post
Share on other sites
Ademan555    361
Well, first of all, I may have missed it, but where do you set your viewport? or your projection matrix? the identity matrix isnt going to cut it. First you need to call glViewport() somewhere it should look like glViewport(0, 0, Width, Height); replace Width and Height with whatever the window width and height are for your program, then you need to make sure you have actually set the projection matrix to something useful, the identity matrix isnt all you need, call gluPerspective() should look something like this: gluPerspective(45, Width / Height, 1.0f, 1000.0f) the last two parameters are the near and far plane distances, and the first parameter is half of the fov or field of view, the second parameter is the aspect ratio, simply the width divided by the height

(for the record this is a great reference http://rush3d.com/reference/opengl-bluebook-1.0/

but in all seriousness, it doesnt sount like your very familiar with openGL, get familiar with it before you try and do something like this, even if you had done a simple triangle program you wouldnt have this problem

hope that helps
-Dan

Share this post


Link to post
Share on other sites
pheonix2468    164
Thanks i'll get on it. I may have overlooked glveiwport and gluperspective as this is the first program i have made from without copying and pasteing someone else's code and the last language i used set up the window and everything for you.Ill keep trying and maybe eventually ill get it. You lot have been great though.
see ya when i get it together.
-Pheonix2468-

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
if (keys['A']);
{
camx = camx + 1;
}

this will not work as expected. throw away semicolons from every of your if (keys.. lines

Share this post


Link to post
Share on other sites
wolverine    358
Quote:
Original post by pheonix2468
Would it be ok if i used nehe's lesson 10 as a base and use different textures and change the map??


As a basic start, yes! I even recomend that you do so. That's the advantage of having the map on a text file and loading it, instead of hardcoding everything in code! The format nehe uses is very simple, being good for experiment.

The main question that will pop into your mind after a while is how do you change the map without using notepad, i.e having some sort of level editor for it. That's because, for a while, it will be *mighty cool* to have a map loaded from file that you can just change over in notepad and see the changes in your graphic engine. But you'll get bored after a while and want to make more complex examples for your maps and using notepad for it is just out of the question. But i think i'm talking too much... when (and if) that times comes, you'll deal with it. Until you get there, go ahead.

Share this post


Link to post
Share on other sites
pheonix2468    164
Ive got started and it ok but how do you strafe. ive got the arrow keys to look up and down left and right and ive got w and s to move forward and backward and ive sort of got it to use a and d to strafe but it only works when im faceing a certain way. Could you help??

if (!keys['F'])
{
fp=FALSE;
}

if (keys[VK_UP])
{
z-=0.02f;
}

if (keys[VK_DOWN])
{
z+=0.02f;
}

if (keys['W'])
{

xpos -= (float)sin(heading*piover180) * 0.05f;
zpos -= (float)cos(heading*piover180) * 0.05f;
if (walkbiasangle >= 350.0f)
{
walkbiasangle = 200.0f;
}
else
{
walkbiasangle+= 10;
}
walkbias = (float)sin(walkbiasangle * piover180)/20.0f;
}

if (keys['S'])
{
xpos += (float)sin(heading*piover180) * 0.05f;
zpos += (float)cos(heading*piover180) * 0.05f;
if (walkbiasangle <= 1.0f)
{
walkbiasangle = 200.0f;
}
else
{
walkbiasangle-= 10;
}
walkbias = (float)sin(walkbiasangle * piover180)/20.0f;
}

if (keys['A'])
{
xpos -= (float)cos(heading*piover180) * 0.05f;
}

if (keys['D'])
{
xpos += (float)cos(heading*piover180) * 0.05f;
}

if (keys[VK_RIGHT])
{
heading -= 3.0f;
yrot = heading;
}

if (keys[VK_LEFT])
{
heading += 3.0f;
yrot = heading;
}

if (keys[VK_UP])
{
lookupdown-= 3.0f;
}

if (keys[VK_DOWN])
{
lookupdown+= 3.0f;
}

Share this post


Link to post
Share on other sites
wolverine    358

if (keys['A'])
{
xpos -= (float)cos(heading*piover180) * 0.05f;
}

if (keys['D'])
{
xpos += (float)cos(heading*piover180) * 0.05f;
}



That's because this formulas for strafing are wrong! Think about it... when you stafe, you must change both your x and y positions (or x and z, depending on the coord system). You only chage your x position and don't change your y position (like in your code) only in the special case where the direction you are heading is the same direction as the y axis.

The case you programmed is only a special case... you need to include info about moving on y as well. It's almost like walking forward and backward....

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this