Jump to content

  • Log In with Google      Sign In   
  • Create Account

BeginGamer

Member Since 02 Jun 2012
Offline Last Active Mar 15 2014 07:36 AM

Posts I've Made

In Topic: Texture Error

09 July 2012 - 08:37 AM

For the way you use the vector I would suggest textures.resize(imagefiles.size()) instead of the wonky insert. If not, a short debugging session or an update of this thread with the current code and behavior should put you much closer to your goal.

Yes! You was absolutely right...

Though, I still have this problem of drawing both images.... It draws the background fine but not the sprite image...

I updated both the renderer and image upload with debug feed back. Usually, it tells me that it couldn't open the certain sprite file from IMG_LOAD.. Though, I have the filename correct and the format isn't wrong, it's just a simple png with transparent background. I even tested with a another sprite that work in another program I made just to make sure... The dlls are correct, because I just copy/paste from another working program.. So, I'm kind of scratching my head why it isn't working... I did test if my program receive the proper vertices and texvertices as well for the render function.. No errors was shown and had the positional values that I wanted..

In Topic: Texture Error

08 July 2012 - 04:16 PM

Thanks for everything.. Apparently, the image wasn't loading.. it had a weird extensions LOL.... *Debugging is key* is there anyway to store Gluint in vector or just simply stick with gluint array? Also, do I need to use glDeletetextures ?

In Topic: Texture Error

08 July 2012 - 02:27 AM

it compiles and works... with GLuint * texture yet now it's not printing my sprites... but it does print background... if you want to see my rendering code


void gameDraw::Render_2D::Render(glSDL_Config & gConfig )
{
	if( gConfig.Draw_Background)
	{
		GLubyte bk_indices [] = {
								0, 1 , 2,
								0, 2 , 3
								};

		glBindTexture(GL_TEXTURE_2D , textures[gConfig.background]);

		glSDL_Vertex   bk_vRect  = gConfig.bk_Vertex;
		glSDL_texture  bk_tRect  = gConfig.bk_texture;
		GLfloat bk_vertices[ ] =  {
									bk_vRect.x , bk_vRect.y + bk_vRect.h, 0,
									bk_vRect.x , bk_vRect.y , 0,
									bk_vRect.x + bk_vRect.w , bk_vRect.y , 0,
									bk_vRect.x + bk_vRect.w , bk_vRect.y + bk_vRect.h, 0
								  };
		GLfloat bk_Texvertices[ ] = {
									bk_tRect.x , bk_tRect.y + bk_tRect.num,
									bk_tRect.x , bk_tRect.y ,
									bk_tRect.x + bk_tRect.num , bk_tRect.y ,
									bk_tRect.x + bk_tRect.num , bk_tRect.y + bk_tRect.num
									};
		glEnableClientState(GL_VERTEX_ARRAY);
		glEnableClientState(GL_TEXTURE_COORD_ARRAY);
		glTexCoordPointer(2, GL_FLOAT,0, bk_Texvertices);
		glVertexPointer(3, GL_FLOAT, 0, bk_vertices);
		glDrawElements(GL_TRIANGLES, 12, GL_UNSIGNED_BYTE, bk_indices);
		glDisableClientState(GL_TEXTURE_COORD_ARRAY);
		glDisableClientState(GL_VERTEX_ARRAY);
	}
	 if( gConfig.Draw_Sprite)
	{
			if( gConfig.foreground != gConfig.background)
			{
				glBindTexture(GL_TEXTURE_2D, textures[gConfig.foreground]);
			}
		int nSize = RenderArray.size();
		GLfloat vertices[nSize * 12];
		GLfloat texvertices[nSize * 8];
		glSDL_Vertex  vtemp;
		glSDL_texture textemp;
		unsigned int itv = 0;
		unsigned int itex = 0;
		BOOST_FOREACH( SpriteData & iter , RenderArray )
		{
		  vtemp	 = boost::get<0>(iter);
		  textemp   = boost::get<1>(iter);
		  //buttom left
		  vertices[itv] = vtemp.x;
		  vertices[itv + 1] = vtemp.y + vtemp.h;
		  vertices[itv + 2] = vtemp.layer;
		  //upper left
		  vertices[itv + 3] = vtemp.x;
		  vertices[itv + 4] = vtemp.y;
		  vertices[itv + 5] = vtemp.layer;
		  //upper right
		  vertices[itv + 6] = vtemp.x + vtemp.w;
		  vertices[itv + 7] = vtemp.y;
		  vertices[itv + 8] = vtemp.layer;
		  //lower right
		  vertices[itv + 9] = vtemp.x + vtemp.w;
		  vertices[itv + 10] = vtemp.y + vtemp.h;
		  vertices[itv + 11] = vtemp.layer;
		  itv += 12;
		 //buttom left
		  texvertices[itex] = textemp.x;
		  texvertices[itex + 1] = textemp.y + textemp.num;
		  //upper left
		  texvertices[itex + 2] = textemp.x;
		  texvertices[itex + 3] = textemp.y;
		  //upper right
		  texvertices[itex + 4] = textemp.x + textemp.num;
		  texvertices[itex + 5] = textemp.y;
		  //buttom right
		  texvertices[itex + 6] = textemp.x + textemp.num;
		  texvertices[itex + 7] = textemp.y + textemp.num;
		  itex += 8;
		}
		RenderArray.clear();
		unsigned short quadindices[nSize * 6 ];
		unsigned short *ndx = quadindices;
		 for (int i = 0, fv = 0; i < nSize; i++, fv += 4, ndx += 6)
		{
				ndx[0] = fv;
				ndx[1] = fv + 1;
				ndx[2] = fv + 2;
				ndx[3] = fv;
				ndx[4] = fv + 2;
				ndx[5] = fv + 3;
		}
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
		//Enable drawing state
		glEnableClientState(GL_VERTEX_ARRAY);
		glEnableClientState(GL_TEXTURE_COORD_ARRAY);
		glTexCoordPointer(2, GL_FLOAT,0,  texvertices);
		glVertexPointer(3, GL_FLOAT, 0, vertices);
		glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, quadindices);
		//Done with drawing state
		glDisableClientState(GL_TEXTURE_COORD_ARRAY);
		glDisableClientState(GL_VERTEX_ARRAY);
		glDisable(GL_BLEND);
	}
	 SDL_GL_SwapBuffers();

}

I should make a test if the vertices and texvertices data have came in ~_~.....

In Topic: Texture Error

08 July 2012 - 01:40 AM

I tried that and still got an error , and I also tried
void gameDraw::Render_2D::getSpriteSheets(const std::vector<std::string> & imagefiles )
{
    unsigned int nSize = imagefiles.size();
    std::vector<GLuint> SpriteSheets(nSize, 0);
    unsigned int i = 0;
    BOOST_FOREACH( std::string image, imagefiles )
    {
	    uploadImage(image, SpriteSheets[i]);
	    ++i;
    }
    textures = SpriteSheets;
}

In Topic: Drawing multiple quads for 2d game

03 July 2012 - 02:17 PM

ahh... Well if I wanted to do it the VBO way.. would it be along the lines of this
//assume Opengl 2.1
GLuint VBOid;
glGenBuffers( 1 , &VBOid);
glBindBuffer(GL_ARRAY_BUFFER, VBOid);
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*6, NULL, GL_DYNAMIC_DRAW);
glVertexPointer(3, GL_FLOAT, 0, NULL); 

glBindTexture(GL_TEXTURE_2D, spritesheetID);
// for each sprite in sprites do something like this?
glPushMatrix()
glTranslatedf(posx , posy, layer);
glScalef(sizeX, sizeY, 0 );
glTexCoordPointer(2, GL_FLOAT, 0 ,  texvertices);

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glDrawElements(GL_TRIANGLES, 6 , GL_UNSIGNED_BYTE, indices);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glPopMatrix();

not sure if my idea is correct

PARTNERS