Working on simple Engine

This is a discussion on Working on simple Engine within the Game Programming forums, part of the General Programming Boards category; This is so far what I got for Bastnagel Engine. I need help with somethings, cause theres some stuff that ...

  1. #1
    Registered User
    Join Date
    Nov 2004
    Posts
    69

    Talking Working on simple Engine

    This is so far what I got for Bastnagel Engine. I need help with somethings, cause theres some stuff that I don't know how to approach, like making an in game console. This is my first attempt at making Interactive 3D with texture sound, and input all together. Im going to continue this project, im the only one working on it now . Hopefully I can make a simple game engine out of this. I work on this off and on, havent worked on it in a while. My header files ect are kinda disorganized. I also need some tips.


    Anyways here's the link. It includes the Executable, and the Source Code
    BastnagelEngine02.rar

    FPS BUG -
    For some reason the FPS moves with everything else. Don't really know why, prolly something really simple I missed.

    MUSIC BUG -
    Sometimes the music doesn't start up at the begining. It only happens when you start it up, and your taskbar is still showing.

    Controls -
    W, or UP ARROW - Move lines outward
    S, or DOWN ARROW - Move lines inward
    A, or LEFT ARROW - Move "-" rotation
    D, or RIGHT ARROW - Move "+" rotation
    F - Show FPS
    G - Hide FPS
    Z - Start Music
    X - Stop Music

    Tell me what you think, and if you can help.

  2. #2
    ---
    Join Date
    May 2004
    Posts
    1,379
    This link is a bit outdated but it might help you
    http://www.gamedev.net/reference/art...rticle1008.asp

  3. #3
    Registered User
    Join Date
    Nov 2004
    Posts
    69
    Quote Originally Posted by sand_man
    This link is a bit outdated but it might help you
    http://www.gamedev.net/reference/art...rticle1008.asp

    Thanks, but only one problem. Im using OpenGL. Mainly because its easier.

  4. #4
    ---
    Join Date
    May 2004
    Posts
    1,379
    Well if anyone was still using DirectDraw I would slap them upside the head. Without reading it myself I thought there might have been some generic information for you in the article.

  5. #5
    mov.w #$1337,D0 Jeremy G's Avatar
    Join Date
    Nov 2001
    Posts
    704
    Mainly, functions go in .cpp files and other stuff - like definitions goes in .h files.

    I think a little project organization would go a long way in improving your project readability.

    EDIT: After looking through your project more thoroughly I would suggest this format:

    .cpp files
    .....winMain.cpp (this is your windows code)
    .....main.cpp (initialize, and render main function, clean up)
    .....media.cpp (things like loading textures, music etc)
    .....utility.cpp (useful functions, wrap(), fps(), 3dprintf() etc.)
    .h files
    .....global.h (global variables, and function prototypes, all includes)
    .....media.h (media related variables only used in media.cpp)
    .....utility.h (structure definitions, and prototypes)


    Heres an example of my global header file
    Code:
    #include <windows.h>
    #include <gl\gl.h>        
    #include <gl\glu.h>         
    #include <gl\glaux.h>  
    #include <gl\glext.h>
    #include <iostream.h> 
    #include <fstream.h> 
    #include <string>
    #include <math.h>
    #include <stdio.h>
    #include "MediaLoader.h"
    #include "music.h"
    
    typedef struct {
    	bool down;
    	long time;
    } key;
    
    #ifdef MAIN_CPP
    HGLRC           hRC=NULL;		// Permanent Rendering Context
    HDC             hDC=NULL;		// Private GDI Device Context
    HWND            hWnd=NULL;		// Holds Our Window Handle
    HINSTANCE       hInstance;		// Holds The Instance Of The Application
    
    key 	keys[256];				// Array Used For The Keyboard Routine
    bool	active=TRUE;			// Window Active Flag Set To TRUE By Default
    bool	fullscreen=false;		// Fullscreen Flag Set To Fullscreen Mode By Default
    int    g_winWidth = 480;
    int	   g_winHeight = 320;
    char * g_WindowTitle = "Space Pong";
    long	startTime = 0;
    
    float		g_FrameRate=0;
    __int64 g_Frequency=0;
    int		g_FrameCount=0;
    
    #else
    extern g_winWidth;
    extern g_winHeight;
    extern HGLRC hRC;
    extern HDC hDC;
    extern float g_FrameRate;
    extern __int64 g_Frequency;
    extern int g_FrameCount;
    extern long startTime;
    extern key 	keys[256];
    #endif
    
    
    #include "font.h"
    
    #ifdef GAME_CPP
    
    GLFONT *fSystem = 0;
    GLFONT *fMenu = 0;
    
    PFNGLACTIVETEXTUREARBPROC       glActiveTextureARB       = NULL;
    PFNGLMULTITEXCOORD2FARBPROC     glMultiTexCoord2fARB     = NULL;
    PFNGLCLIENTACTIVETEXTUREARBPROC glClientActiveTextureARB = NULL;
    
    #else
    
    #endif
    
    
    
    // prototypes
    // game.cpp
    void gameInit();
    void splashScreen();
    void MainLoop();
    int menuSystem();
    
    // main.cpp
    GLvoid ReSizeGLSceneOrtho(int w, int h);
    GLvoid ReSizeGLScene(GLsizei width, GLsizei height);
    
    // utility.cpp
    int cinstr(char * haystack, char *needle);
    int  wrap(int min, int max, int val);
    float  wrap(float min, float max, float val);
    float deg2rad(float deg);
    float timeScale(int ideal);
    HRESULT InitTiming();
    void Pause( int Milliseconds );
    void FrameCount();

    Pointers aside from project management -
    Time based movement - I run your program at about 1700 fps, and spinning the box becomes rather sloppy because it spins way too fast. This code can solve that problem
    Code:
    ////////////////////////////////
    // frames per second modifier //
    float timeScale(int ideal) {
    	return (ideal/(float)g_FrameRate);
    
    } 
    
    // some where in your render function
    if(keydown)
         rotationVariable += 0.01 * timeScale(60); // 60 FPS ideal
    // other...
    if(movePlayer)
         playerPos += 5 * timeScale(60); // etc.
    Any time you incriment a variable, you should modify it based on an ideal FPS timing.


    Also, you are using NeHe's keys[] boolean array, this is nice but I found altering the array type to be rather helpful - I've turned it into a struct
    Code:
    typdef struct {
         bool down;
         long int time;
    } keystate;
    During your WM_KEYDOWN case, you should assign the GetTickCount() to the time, and only allow down state changes based on an amount of time. ie:
    Code:
    			if(GetTickCount() - keys[wParam].time > 100) {
    				keys[wParam].down = TRUE;					// If So, Mark It As TRUE
    				keys[wParam].time = GetTickCount();
    			}
    Any way, maybe that can help you out some how.
    Last edited by Jeremy G; 05-21-2005 at 03:44 AM.
    c++->visualc++->directx->opengl->c++;
    (it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)

  6. #6
    ---
    Join Date
    May 2004
    Posts
    1,379
    At first the download wouldn;t work for me. I just looked at it then and it is quite a mess. If you organize things the way Jeremy G suggested it will make development easier.

    >>For some reason the FPS moves with everything else. Don't really know why, prolly something really simple I missed.

    You need to go into a orthographic prjection before drawing the fps
    glOrtho()

    eg:
    Code:
    void glEnable2D(void)
    {
       int vPort[4];
       glGetIntegerv(GL_VIEWPORT, vPort);
       glMatrixMode(GL_PROJECTION);
       glPushMatrix();
          glLoadIdentity();
          glOrtho(0,vPort[2],0,vPort[3], -1, 1);
          glMatrixMode(GL_MODELVIEW);
          glPushMatrix();
             glLoadIdentity();
    }
    
    void glDisable2D(void)
    {
             glMatrixMode(GL_PROJECTION);
          glPopMatrix();   
          glMatrixMode(GL_MODELVIEW);
       glPopMatrix();	
    }

  7. #7
    mov.w #$1337,D0 Jeremy G's Avatar
    Join Date
    Nov 2001
    Posts
    704
    Also, along with what sandman said - you dont particularly need glOrtho especially if you want to maintain a 3d placement of the text. The key is knowing how the position translation and rotation works with openGL.

    With out going into a giant explination of all that I'll simply show you a couple functions you can add -
    Code:
    // in render () 
    translate3f(0.5, 10.0, 20.0);
    glPushMatrix(); // sets up local coordinate system
        glVertex3f(0, 0, 0); // while the vertex is located at 0, 0, 0 this is only LOCALY, in reality
        // the vertex is at 0.5, 10.0, 20.0
    glPopMatrix(); // re-enter reguler coordinate system (global in this case)
    // push and pop are embedable with each other, key for complicated orbiting/rotation systems
    glLoadIdenty(); // resets the global coordinate system
    glTranslate3f(x,y,z); // move to where ever you want the text (3d wise)
    printTextMethodHere(); // display your text
    Basically, you just have to manage where your coordinate system currently is when you draw your text. use glLoadIdentity() to reset, but try to group all text together so you don't call it unecessarily often.


    edit:
    Consider your coordinate system your camera - glRotate, glTranslate move the coordinate system around the camera. While glVertex(x,y,z) moves the object around the coordinate system.
    Last edited by Jeremy G; 05-21-2005 at 04:44 AM.
    c++->visualc++->directx->opengl->c++;
    (it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)

  8. #8
    Registered User
    Join Date
    Nov 2004
    Posts
    69
    Quote Originally Posted by Jeremy G
    Mainly, functions go in .cpp files and other stuff - like definitions goes in .h files.

    I think a little project organization would go a long way in improving your project readability.

    EDIT: After looking through your project more thoroughly I would suggest this format:

    .cpp files
    .....winMain.cpp (this is your windows code)
    .....main.cpp (initialize, and render main function, clean up)
    .....media.cpp (things like loading textures, music etc)
    .....utility.cpp (useful functions, wrap(), fps(), 3dprintf() etc.)
    .h files
    .....global.h (global variables, and function prototypes, all includes)
    .....media.h (media related variables only used in media.cpp)
    .....utility.h (structure definitions, and prototypes)


    Heres an example of my global header file
    Code:
    #include <windows.h>
    #include <gl\gl.h>        
    #include <gl\glu.h>         
    #include <gl\glaux.h>  
    #include <gl\glext.h>
    #include <iostream.h> 
    #include <fstream.h> 
    #include <string>
    #include <math.h>
    #include <stdio.h>
    #include "MediaLoader.h"
    #include "music.h"
    
    typedef struct {
    	bool down;
    	long time;
    } key;
    
    #ifdef MAIN_CPP
    HGLRC           hRC=NULL;		// Permanent Rendering Context
    HDC             hDC=NULL;		// Private GDI Device Context
    HWND            hWnd=NULL;		// Holds Our Window Handle
    HINSTANCE       hInstance;		// Holds The Instance Of The Application
    
    key 	keys[256];				// Array Used For The Keyboard Routine
    bool	active=TRUE;			// Window Active Flag Set To TRUE By Default
    bool	fullscreen=false;		// Fullscreen Flag Set To Fullscreen Mode By Default
    int    g_winWidth = 480;
    int	   g_winHeight = 320;
    char * g_WindowTitle = "Space Pong";
    long	startTime = 0;
    
    float		g_FrameRate=0;
    __int64 g_Frequency=0;
    int		g_FrameCount=0;
    
    #else
    extern g_winWidth;
    extern g_winHeight;
    extern HGLRC hRC;
    extern HDC hDC;
    extern float g_FrameRate;
    extern __int64 g_Frequency;
    extern int g_FrameCount;
    extern long startTime;
    extern key 	keys[256];
    #endif
    
    
    #include "font.h"
    
    #ifdef GAME_CPP
    
    GLFONT *fSystem = 0;
    GLFONT *fMenu = 0;
    
    PFNGLACTIVETEXTUREARBPROC       glActiveTextureARB       = NULL;
    PFNGLMULTITEXCOORD2FARBPROC     glMultiTexCoord2fARB     = NULL;
    PFNGLCLIENTACTIVETEXTUREARBPROC glClientActiveTextureARB = NULL;
    
    #else
    
    #endif
    
    
    
    // prototypes
    // game.cpp
    void gameInit();
    void splashScreen();
    void MainLoop();
    int menuSystem();
    
    // main.cpp
    GLvoid ReSizeGLSceneOrtho(int w, int h);
    GLvoid ReSizeGLScene(GLsizei width, GLsizei height);
    
    // utility.cpp
    int cinstr(char * haystack, char *needle);
    int  wrap(int min, int max, int val);
    float  wrap(float min, float max, float val);
    float deg2rad(float deg);
    float timeScale(int ideal);
    HRESULT InitTiming();
    void Pause( int Milliseconds );
    void FrameCount();

    Pointers aside from project management -
    Time based movement - I run your program at about 1700 fps, and spinning the box becomes rather sloppy because it spins way too fast. This code can solve that problem
    Code:
    ////////////////////////////////
    // frames per second modifier //
    float timeScale(int ideal) {
    	return (ideal/(float)g_FrameRate);
    
    } 
    
    // some where in your render function
    if(keydown)
         rotationVariable += 0.01 * timeScale(60); // 60 FPS ideal
    // other...
    if(movePlayer)
         playerPos += 5 * timeScale(60); // etc.
    Any time you incriment a variable, you should modify it based on an ideal FPS timing.


    Also, you are using NeHe's keys[] boolean array, this is nice but I found altering the array type to be rather helpful - I've turned it into a struct
    Code:
    typdef struct {
         bool down;
         long int time;
    } keystate;
    During your WM_KEYDOWN case, you should assign the GetTickCount() to the time, and only allow down state changes based on an amount of time. ie:
    Code:
    			if(GetTickCount() - keys[wParam].time > 100) {
    				keys[wParam].down = TRUE;					// If So, Mark It As TRUE
    				keys[wParam].time = GetTickCount();
    			}
    Any way, maybe that can help you out some how.


    Thanks, but I think im gonna have to redo alot of it, but I am going to do what you said with the organization, as for everything else Ill do once its organized.

  9. #9
    Registered User
    Join Date
    Nov 2004
    Posts
    69
    You know what. Im just gonna restart this whole project, moving everything would be more work then redoing it.

  10. #10
    ---
    Join Date
    May 2004
    Posts
    1,379
    Good idea

  11. #11
    Registered User
    Join Date
    Nov 2004
    Posts
    69
    Gotta work on the multitexturing, since im using BMP fonts.

  12. #12
    Registered User
    Join Date
    Nov 2004
    Posts
    69
    Ok, so I re-did the engine except its different now. I don't exactly have a camera Class right now I just got it set to change the gluLookAt vars. Ok well I have run into a problem. When the console is down and you move around, for somereason it flickers, and dissapears, I thought this was because object where going through it, but when I move out of the cubes it still did it. Does anyone have any idea why?

    http://www.eltrahost.com/BastnagelEngineRedone.rar

    That is the executable. If it doesnt run stick glut32.dll in system32 which is in the DLL's folder. If you could please gimmie any ideas on how to get it so it always shows up then that would be great. The button to activate the console is F.
    Last edited by bladerunner627; 05-24-2005 at 08:07 PM.

  13. #13
    mov.w #$1337,D0 Jeremy G's Avatar
    Join Date
    Nov 2001
    Posts
    704
    No way to diagnose your problem really with out source.
    c++->visualc++->directx->opengl->c++;
    (it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)

  14. #14
    Registered User
    Join Date
    Nov 2004
    Posts
    69
    Quote Originally Posted by Jeremy G
    No way to diagnose your problem really with out source.
    Ok the source is http://www.eltrahost.com/BastnagelEngineSource.rar

  15. #15
    mov.w #$1337,D0 Jeremy G's Avatar
    Join Date
    Nov 2001
    Posts
    704
    In the top of drawConsole put
    glLoadIdentity(); // restart coordinate system
    glDisable(GL_DEPTH_TEST); // i believe draws ontop of existing rendered stuff

    // draw textured quad here
    // preferably in glOrthoMode which you haven't implimented yet
    c++->visualc++->directx->opengl->c++;
    (it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. simple but not working
    By Dave++ in forum C++ Programming
    Replies: 22
    Last Post: 06-27-2007, 11:42 AM
  2. One now owns an automobile!
    By cboard_member in forum A Brief History of Cprogramming.com
    Replies: 26
    Last Post: 04-22-2007, 05:34 PM
  3. Game structure, any thoughts?
    By Vorok in forum Game Programming
    Replies: 2
    Last Post: 06-07-2003, 01:47 PM
  4. Replies: 5
    Last Post: 02-02-2003, 09:56 AM
  5. simple program not working
    By Unregistered in forum Windows Programming
    Replies: 2
    Last Post: 03-04-2002, 10:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21