Jump to content

  • Log In with Google      Sign In   
  • Create Account


Vero

Member Since 20 Jun 2012
Offline Last Active Nov 02 2012 08:44 AM

Posts I've Made

In Topic: Polymorphism and pointer arrays in c++

26 July 2012 - 02:49 PM

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?

In Topic: Installing GLEW.h libraries for VS express 2010

24 July 2012 - 01:47 PM

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.

In Topic: Installing GLEW.h libraries for VS express 2010

10 July 2012 - 09:29 AM

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

In Topic: Installing GLEW.h libraries for VS express 2010

09 July 2012 - 10:15 AM

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

In Topic: consistent Gaming Loops and Clocks

03 July 2012 - 01:08 PM

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 :D

PARTNERS