Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

138 Neutral

About Vero

  • Rank
  1. Hi all, I've been doing a few things with ioctl and in this one case the call is trying to open an event. in this case it alters the handle you pass in as a pointer in the parameter from the kernal side I can see the GetLastError is 2 aka a file not found error but I need this error code to float up to the user space. Any ideas on how to do this?
  2. Ok that worked perfectly, and I understand now what slicing is but I don't quite understand why the solution works. lets see if I can figure it out. MObject** is a pointer to an array of pointers so it's allocates a slot to each pointer but doesn't allocate them a type yet? so now that they have not be allocated a type we can use new to allocate them to the correct class?
  3. So, I haven't been able to find a good explanation on this. I want a dynamic size to my array, basically then I read in the level it tells me how many objects I need so I do the following: MObject *objects = new MObject[num_of_obj]; after I find out how many I need through the text file I created that's reading in the level, I find out what KIND of MObjects they are so one of them is a SpeedBoost obj (inherits MOBject) *(object+obj_counter)= SpeedBoost(args...); for simplicity sake objcounter is 0 for now MObject has virtual Draw(); SpeedBoost has Draw(); when I attempt to run through a list of objects and call: objects[loop1].Draw(); the SpeedBoost::Draw() is never called only the MObject::Draw() is called. I need it to call the implementation of the Draw for the class that it is not the base class draw. I'm know that implementing a linked list would probably work but that's added complexity for something that an array should hopefully be able to do.
  4. So, I've come to the point in my game were I feel I need to come past this hurtle before I move on to more complex features. I'm more or a programmer than an artist but I'm learning a few techniques for pixel/ 8bit style art. (btw what's your recommended program for making art? I'm mostly fiddling with it in MSpaint right now) anyway here's run down of questions I have. Whats the best way to creating a sprite in openGL, right now I would simply load a series of textures and when moving as time passes the textures would be rotated over the GL_QUAD to look like walking, Is there a better/ cleaner way to implement this in a 2d environment? How would I go about creating transparency on parts of the texture? I've tried to implement a few examples of Masking but so far I haven't had any success, would I need to use something other than .bmps for this, e.g. .png Thanks for any advice you can offer.
  5. Hi Everyone, I've been coding a simple game in C++ with OpenGL. I'm pretty new to creating games and though I've had a lot of college experience in coding with C++ and Java and .Net I've never really developed anything professionally on this large a scale. The thing is I'm worried things will become more and more disorganized as I progress in making the game. So far the game is a maze where you load the maze data from a text file and then you have to navigate to the goal. It will progress from there but I want to go over how I'm implementing it. the Game Loop: Level1= new Grid("data/Testlvl.txt",20,70); max_fps=2; //TODO may need to incorporate a file load or mabye just play game from start to finish int fcount=0; //frame counter long long fps_sum=0LL; //sum of frame rate long long start=milliseconds_now(); //intialise player speed Level1->player->Velocity.x=40; //40 pixels per second Level1->player->Velocity.y=40; while(!done) //Game LOOOP! { if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) //is there a message? { //peek will not halt program while it looks for a message if(msg.message==WM_QUIT) // have we received a quit message? { done=TRUE; } else{ //if not deal with the window messages TranslateMessage(&msg); //Translate the Message DispatchMessage(&msg); //Dispatch the Message } } else{ // if there are no messages // Draw the Scene. Watch for ESC Key and Quit Messages From DrawGLScene() if((active && !DrawGLScene())|| keys[VK_ESCAPE]) { done=TRUE; // ESC Signalled a Quit } else{ //not time to quit, update screen //drew scene in the if statement while(FPS(start,milliseconds_now())>max_fps) {/*wait*/} if(fcount < 60) { fps_sum=fps_sum+FPS(start,milliseconds_now()); ++fcount; } else { fps=fps_sum/fcount; fcount=0; fps_sum=0LL; } start=milliseconds_now(); SwapBuffers(hDC); //SwapBuffers (double buffering) } } } if (!gameover && active) // If Game Isn't Over And Programs Active Move Objects { if (keys[VK_RIGHT]) { Level1->MovePlayer(M_RIGHT); } if (keys[VK_LEFT]) { Level1->MovePlayer(M_LEFT); } if (keys[VK_DOWN]) { Level1->MovePlayer(M_DOWN); } if (keys[VK_UP]) { Level1->MovePlayer(M_UP); } Level1->Step(start);// what happens next? } //outside of live play: if(keys['A'] && !ap) { ap=TRUE; max_fps++; } if (!keys['A']) // If 'A' Key Has Been Released { ap=FALSE; // ap Becomes FALSE } if(keys['Z'] && !zp && max_fps>2) { zp=TRUE; max_fps--; } if (!keys['Z']) // If 'A' Key Has Been Released { zp=FALSE; // ap Becomes FALSE } //*********update scene**************** /// Beat first Level Snippet if(Level1->player->isTouching(*Level1->goal)) levelend=true; ///end of snippet } So right now inorder to switch scenes in the game loop I set global flags to true and false ( good or bed way to do it) and the DrawGLScene() will check the flags and determine which scene to draw, After declaring a few setup variables I move everything along via time, I even force a max frame rate so that i can control the FPS. (I did this starting out just because I could and now I'm thinking about turning the FPS into something like a reward system collect items increase the FPS makes for smooth gameplay) All my classes are contained within the Grid Class, the Grid Class will contain a player and a List of objects (coins enemies and such all will inherit the MObject class which has a bunch of virtual functions so I can iterate through the list and call Step() and Draw() functions. Step basically updates all the objects positions and other such statuses given that point in time. everything goes through Grid so when the user enters any key commands the Grid can determine what information flows to what objects it's managing. I keep most things public right now but I hope to eventually makes the objects private and get implement public functions to keep things from getting confuzzled. so kind of breaking it down to the flow so far psuedo codeish: GameLoop: DrawScene: [chooses what scene to draw based on flags] assuming game is running Draw header() Grid->Draw() Draws grid Draws Players Draws Goal todo: draw enemies todo: draw items Isgamerunning? Check for input Move player, enemies Step grid.Step() update animated items, players enemies, Are game changingg conditions met progress game I'd really appreciate constructive criticism and how to make it better, methods to keep things organized, what your own ways to coding the loop are. I hope my post makes some sense too
  6. Just an FYI when getting Glew to compile, if you're comiling a 32bit program use the 32 bit libraries doesn't matter what your machine architecture is. Obvious problem was hidden in plain sight for me spent days banging my head against the keyboard when I couldn't compile and run my code on a different machine.
  7. Ok, I've created an simple little image it's a 32x32 pixel image with a white background in MSPaint. then I created a second image this one is a copy of the 1st image only any part that had color was replaced with white and the rest of the image was filled in as black. Do I need to do something special to either image within the image editor? would I need to install something like GIMP to do so? or is MS paint in windows 7 capable of something that advanced? I uploaded the images into the program with SOIL. source: http://www.lonesock.net/soil.html Image loader function: bool MPlayer::LoadObjTexture(char *filename,int slot) { char *index = strchr(filename,'.'); char *mask= new char[0]; strncpy(mask,filename,index-filename); mask[index-filename]='\0'; strcat(mask,"_mask.bmp"); if(MObject::LoadObjTexture(filename,slot,false)&& MObject::LoadObjTexture(mask,slot,true)) return true; else { MessageBox(NULL,L"Hero Sprite failed to Load",L"GAME ERROR",MB_OK|MB_ICONEXCLAMATION); return false; } } bool MObject::LoadObjTexture(char *Filename,int slot,bool isMask) { if(isMask) { mask[slot]=SOIL_load_OGL_texture ( Filename, SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_INVERT_Y | SOIL_FLAG_MIPMAPS|SOIL_FLAG_NTSC_SAFE_RGB ); if(mask[slot]==0) return false; else return true; } else{ sprite[slot]=SOIL_load_OGL_texture ( Filename, SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_INVERT_Y | SOIL_FLAG_MIPMAPS|SOIL_FLAG_NTSC_SAFE_RGB ); if(sprite[slot]==0) return false; else return true; } return false; } Edit: glEnable(GL_BLEND) was declared in my initGL() function which is called at the start of the program. currently I've had no reason to disable blending
  8. Thank you so much for clearing that up. I'm finally able to get the glew libraries to compile and use the glew functionality. So, I suppose there is a part two to this sadly. What I'm trying to accomplish is masking. Too Keep things simple the whole thing is done in glOrtho. I'm trying to create a sprite and the first step right now is rendering a texture and making everything outside of the draw part of the image transparent. the following is the draw function so far with no success in masking. there is nothing behind the drawn image only a black background right now. (no rendered quad or anything.) GLvoid MPlayer::Draw() { glEnable(GL_TEXTURE_2D); glColor4f(1.0f,1.0f,1.0f,1.0f); glLoadIdentity(); glTranslatef(fPosition.x,fPosition.y,0.0f); //glRotatef(spin,0.0f,0.0f,1.0f); glBlendFunc(GL_DST_COLOR,GL_ZERO); glBindTexture(GL_TEXTURE_2D,mask[0]); glBegin(GL_QUADS); glTexCoord2f(0,0); glVertex2i( 3 , interval-2); //start drawing glTexCoord2f(0,1); glVertex2i( 3 , 3); glTexCoord2f(1,1); glVertex2i( interval-2, 3); glTexCoord2f(1,0); glVertex2i( interval-2, interval-2); glEnd(); // glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA); glBlendFunc(GL_ONE, GL_ONE); glBindTexture(GL_TEXTURE_2D,sprite[0]); glBegin(GL_QUADS); glTexCoord2f(0,0); glVertex2i( 3 , interval-2); //start drawing glTexCoord2f(0,1); glVertex2i( 3 , 3); glTexCoord2f(1,1); glVertex2i( interval-2, 3); glTexCoord2f(1,0); glVertex2i( interval-2, interval-2); glEnd(); glDisable(GL_TEXTURE_2D); glBlendFunc(GL_SRC_ALPHA,GL_ZERO); }
  9. I having some serious issues trying to get the GLEW libraries to compile without linker errors any help would be appreciated. #include <Windows.h> // Header File For Windows //#include <GL/GL.h> // Header file for OpenGL32 Library //#include <GL/GLU.h> // Header File for GLu32 Library #include <stdio.h> #include <stdarg.h> #include "aMaze_Objects.h" #include <gl\glew.h> #include <GL/glut.h> #include "SOIL.h" here's the error log when i try to compile. I've tried numerious folders to place the bin lib and include files 1>------ Build started: Project: aMaze, Configuration: Debug Win32 ------ 1>aMaze_Main.obj : error LNK2019: unresolved external symbol __imp__glewInit referenced in function "int __cdecl InitGL(void)" (?InitGL@@YAHXZ) 1>aMaze_Objects.obj : error LNK2001: unresolved external symbol __imp____glewBlendFuncSeparate 1>C:\Users\Varonec\Dropbox\Game\aMaze\Debug\aMaze.exe : fatal error LNK1120: 2 unresolved externals ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== I have tried searching the internet and I've read this link up and down: file:///C:/Users/Varonec/Downloads/glew-1.7.0-win64%281%29/glew-1.7.0/doc/install.html anyway, I'm not sure where I can go from here
  10. Thanks Beernutts, I'm definitely going to keep that snippet of code around for later use. I figured I'd add to the thread to see the outcome of what's happened so far with the game loop implementation. I'm keeping a Psuedo FPS counter what it is really keeping track of is how many Cycles a second it will run through the loop. I say pseudo because without throttling the cycles to 200 cycles a second it was getting over 1000 cycles, I have a goal render with some animation and that was definitely getting some tearing. this might have been due to the limitations of the monitor itself, Anywhere here's a few snippets of time so far implemented in my loop: //condensed the performance query long long milliseconds_now() { static LARGE_INTEGER s_frequency; static BOOL s_use_qpc = QueryPerformanceFrequency(&s_frequency); if (s_use_qpc) { LARGE_INTEGER now; QueryPerformanceCounter(&now); return (1000LL * now.QuadPart) / s_frequency.QuadPart; } else { return GetTickCount(); } } while(!done) //Game LOOOP! { if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) //is there a message? { //peek will not halt program while it looks for a message if(msg.message==WM_QUIT) // have we received a quit message? { done=TRUE; } else{ //if not deal with the window messages TranslateMessage(&msg); //Translate the Message DispatchMessage(&msg); //Dispatch the Message } } else{ // if there are no messages // Draw the Scene. Watch for ESC Key and Quit Messages From DrawGLScene() if((active && !DrawGLScene())|| keys[VK_ESCAPE]) { done=TRUE; // ESC Signalled a Quit } else{ //not time to quit, update screen //drew scene in the if statement while(FPS(start,milliseconds_now())>200LL) //throttle FPS { /*wait*/} if(fcount < 60) { fps_sum=fps_sum+FPS(start,milliseconds_now()); ++fcount; } else { fps=fps_sum/fcount; fcount=0; fps_sum=0LL; } start=milliseconds_now(); SwapBuffers(hDC); //SwapBuffers (double buffering) } } ... //end of loop } //drawing and stepping in the goal object: GLvoid Goal::Step(long long elapse) { if(startTime==0LL) startTime = elapse; //start new animation cycle double ElapsedSeconds = (double)(elapse - startTime)/1000.0f; spin= Velocity.x*ElapsedSeconds; } GLvoid Goal::Draw(){ glLoadIdentity(); // Reset The Modelview Matrix glTranslatef(fPosition.x,fPosition.y,0.0f); //top left corner glColor3f(1.0f,0.2f,0.2f); // Make Goal Red glBegin(GL_LINES); // Start Drawing Goal glVertex2d( 0 , 0+((int)spin%interval)); // Top Point Of Body glVertex2d( interval , interval-((int)spin)%interval); // Bottom Right glVertex2d( interval-((int)spin%interval), 0); // Left Point Of Body glVertex2d( 0+((int)spin%interval) , interval); // Bottom Point Of Body glEnd(); // Done Drawing Enemy Body } this is the first game I've been developing and one of the things I've noticed with a lot of help is people put out a lot of assumptions for an implementation to things. Basically with the current Time implements I can control the frame rate and the animation speed. so I can have choppy fast smooth fast smooth slow etc. I'm very happy with the result. Now that I have that part mostly set up i can start making the actual player
  11. What do you think the best way to go about implementing a GetTimeInMS()? I found this but this code is from the 2005ish maybe earlier. Also C++ or C is usable, Windows only machines. I just want to attempt to establish an animate that would have a time consistancy as said above. struct { __int64 frequency; //timer frequency float resolution; //time resolution unsigned long mm_timer_start; // Multimedia Timer Start Value unsigned long mm_timer_elapsed; // Multimedia Timer Elapsed Time bool performance_timer; //Using the performance timer? __int64 performance_timer_start; //performance timer start __int64 performance_timer_elapsed; } timer; void TimerInit(void) { memset(&timer,0,sizeof(timer)); //clear out timer structure //check to see if a performance Counter is availble //if one is availble the timer frenquency will be updated if(!QueryPerformanceFrequency((LARGE_INTEGER *) &timer.frequency)) { //no performance counter availble timer.performance_timer = FALSE; timer.mm_timer_start = timeGetTime(); timer.resolution = 1.0f/1000.0f; timer.frequency = 1000; timer.mm_timer_elapsed = timer.mm_timer_start; } else{ //performance coutner is available QueryPerformanceCounter((LARGE_INTEGER *) &timer.performance_timer_start); timer.performance_timer = TRUE; //calculate the Timer Resolution Using the Timer frequency timer.resolution = (float) (((double)1.0f)/((double)timer.frequency)); //Set Elapsed time to the current time timer.performance_timer_elapsed=timer.performance_timer_start; } } float TimerGetTime() { __int64 time; //time will hold a 64 bit integer if(timer.performance_timer) { QueryPerformanceCounter((LARGE_INTEGER *) &time); //return the current time minus the start time Multiplied By The Resolution And 1000 (To Get MS) return ( (float) ( time - timer.performance_timer_start * timer.resolution)*1000); } else { return( (float) ( timeGetTime() - timer.mm_timer_start) * timer.resolution)*1000.0f; } } To Recap would this be a good method or are their better implementations out there?
  12. OK this is probably an easy thing I'm omitting but I can't decipher why it won't accept my implementation of giving a pointer a mutli dimensional array. I've looked into a few implementations of this. this looks almost to be more of an issue of the variables I'm passing in as the dimensions of the array. anyway any help is always appreciated. class Grid { public: GLvoid Draw(); void LoadGrid(char *filename[]); Grid(); Grid(char *filename[]); ~Grid(); int height; int width; bool initialized; bool **vline; bool **hline; }; Grid::Grid(){ width=height=0; initialized=false; } void Grid::LoadGrid(char *filename[]) { FILE *filein; char *line; int loop1,loop2; filein =fopen(*filename,"rt"); readstr(filein,line); sscanf(line, "dim %d %d\n", &width, &height); vline= new bool[height][width]; //<==== here's the issue Error: Expression must have a constant value for(loop1=0;loop1<height;loop1++) { //under construction } }
  13. originally the timer was in there to waste cycles, so between the draw scene and the next calculation on movement and action there was a timer to make the computer sit there for a set amount of cycles, the amount of time in the loop was inversely related to how long it took to draw the current scene. I didn't rework the timer right now but the next time I write a game loop I'll try to use the timer to calculate how far each object on the screen should have traveled by how much time has passed.
  14. Vero

    OpenGL Coordinate System

    Well, I'm not entirely sure I've understood your question 100% but here goes for a good answer at the basics for OpenGL when you load an image as a texture the edges for that texture are: (0.0f,0.0f) (0.0f,1.0f) (1.0f,1.0f) (1.0f,0.0f) soo Lets say you made a QUAD like such glBegin(GL_QUAD); glVertex3f(-1.0f, 1.0f,0.0f); // top left glVertex3f( 1.0f, 1.0f,0.0f); // top right glVertex3f( 1.0f,-1.0f,0.0f); // bottom right glVertex3f(-1.0f,-1.0f,0.0f); // bottom left glEnd(); Lets assume you have set everything up and this is at the draw scene stage of things that draws a 2x2 unit square relative to your view and any translation now lets apply a texture to that quad glTextureBind(GL_TEXTURE_2D, texture[0]) //whatever texture you've loaded into this GLuint variable glBegin(GL_QUAD); glVertex3f(-1.0f, 1.0f,0.0f); glTexCoord2f(0.0f,0.0f); glVertex3f( 1.0f, 1.0f,0.0f); glTexCoord2f(1.0f,0.0f); glVertex3f( 1.0f,-1.0f,0.0f); glTexCoord2f(1.0f,1.0f); glVertex3f(-1.0f,-1.0f,0.0f); glTexCoord2f(0.0f,1.0f); glEnd(); usually I invert the Y when loading the image thus why 1.0f in the Y coord makes it go down. but basically you can select any portion of the texture within the 1.0-0.0 constraints and that associates that point on the texture with that point of the quad. you can also select outside the 1.0 constraints and depending on the texture settings you can have multiple images tiled onto the quad or just a smaller image that doesn't fill the whole quad. I'm sure there are many more things but right now that's a simple run down of textures, hope this helps
  15. So, I've been going through a lot of OpenGL Tutorials using C code, Also side question, what would you guys recommend coding more complex games in C or C++? I'm not really used to C because work and so many languages I've used before use Objects and Classes if not for utilities than just to keep things organized, that I'm not certain how I would keep a C game from massing huge amounts of global variables and just becoming a mish mash of code. but so far the most useful tutorials I've found have been coded in C. I created my first really simple game using a tutorial and adding improvements here and there and fixing all the major bugs with stuff that well works and works pretty solid but feels more like duct tape than a nice elegant fix. Now I think most of my issues stemmed from creating consistent/smooth animationwhen traversing cross points on a grid. I did this by incrementing a position stuct for the player/enemie and then every draw cycle I translated to draw on the current position. this either created kind of choppy movement or too slow a movement. My main question is what are some implementations you would use to create movement on a 2d ortho view using C or even C++. Something that would mostly stay consistent not based on CPU power but just by a clock so it would take X amount of time to get from A to B. My next game is going to just be a simple Maze game maybe a maze editor if I get ambitious with it, but I want to make sure I have some of these concepts down first before I continue.
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!