• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

BeginGamer

Members
  • Content count

    11
  • Joined

  • Last visited

Community Reputation

106 Neutral

About BeginGamer

  • Rank
    Member
  1. I am trying to integrate my Scene and Input_handle class for a tile base games.. I would like to make in the future. Though, I am out of ideas for a ice way to make both classes work together. Any suggestions?
  2. [quote] 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. [/quote] 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..
  3. 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 ?
  4. 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 [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(); } [/CODE] I should make a test if the vertices and texvertices data have came in ~_~.....
  5. I tried that and still got an error , and I also tried [CODE] 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; } [/CODE]
  6. I was battling with my code for today, and I pin-pointed the error of my sdl program instantly closing from error with the generation of my textures... [CODE] // in my DrawingGame definition source file static void uploadImage( std::string & filename, GLuint & id ) { SDL_Surface * tempt = IMG_Load(filename.c_str()); if(!tempt) { id = 0; } SDL_Surface * nCopy = SDL_CreateRGBSurface(SDL_SWSURFACE,tempt->w,tempt->h,32, #if SDL_BYTEORDER == SDL_BIG_ENDIAN 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff #else 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 #endif ); SDL_BlitSurface(tempt,NULL,nCopy,NULL); glGenTextures(1, &id); glBindTexture(GL_TEXTURE_2D, id); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, nCopy->w, nCopy->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, nCopy->pixels); SDL_FreeSurface(tempt); SDL_FreeSurface(nCopy); } void gameDraw::Render_2D::getSpriteSheets(const std::vector<std::string> & imagefiles ) { std::vector<GLuint>::iterator it; unsigned int nSize = imagefiles.size(); textures.insert(it,nSize, 0); unsigned int i = 0; BOOST_FOREACH( std::string image, imagefiles ) { uploadImage(image, textures[i]); ++i; } } [/CODE]
  7. ahh... Well if I wanted to do it the VBO way.. would it be along the lines of this [CODE] //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(); [/CODE] not sure if my idea is correct
  8. May I have example snippet.... if you don't mind me asking ?
  9. Well, I wanted to write a 2d rendering class around glDrawelements. I was just scratching my head, how Icould render N number of quads without rewriting the array of indices
  10. I figured out how to print two quads using vertex arrays, but I think there maybe an easier way to render multiple quads... any suggestions? [CODE] #include "SDL/SDL.h" #include "SDL_image.h" #include "SDL/SDL_opengl.h" GLuint get_texture(void) { SDL_Surface * surface = IMG_Load("image1.png"); SDL_Surface *tempt = SDL_CreateRGBSurface(SDL_SWSURFACE, surface->w, surface->h, 32, #if SDL_BYTEORDER == SDL_BIG_ENDIAN 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff #else 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 #endif ); SDL_BlitSurface(surface, NULL,tempt, NULL); GLuint texture; glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_2D, texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tempt->w, tempt->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, tempt->pixels); SDL_FreeSurface(tempt); SDL_FreeSurface(surface); return texture; } int main( int argc , char ** argv ) { SDL_Init(SDL_INIT_EVERYTHING); SDL_SetVideoMode(640, 480, 32, SDL_OPENGL); glClearColor(0, 0, 0, 0); glViewport(0, 0, 640, 480); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, 640, 480, 0, 1, -1); glDisable(GL_DEPTH_TEST); glMatrixMode(GL_MODELVIEW); glEnable(GL_TEXTURE_2D); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); GLuint id = get_texture(); glBindTexture(GL_TEXTURE_2D,id); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); GLfloat vertices [] = { //first quad 0,16,0, 0,0,0, 16,0,0, 16,16,0, //second quad 50,66,0, 50,50,0, 66,50,0, 66,66,0 }; GLubyte indices [] = { //first indice 0,1,2, 0,2,3, //second 4,5,6, 4,6,7 }; GLfloat texvertices [] = { //first quad 0,.5, 0,0, .5,0, .5,.5, //second quad .5,1, .5,.5, 1,.5, 1,1 }; glTexCoordPointer(2, GL_FLOAT,0, texvertices); glVertexPointer(3, GL_FLOAT, 0, vertices); glDrawElements(GL_TRIANGLES, 12, GL_UNSIGNED_BYTE, indices); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); SDL_GL_SwapBuffers(); SDL_Delay(9000); return 0; } [/CODE]
  11. I have trouble uploading the surface to opengl texture and switching between multiple textures. The program compiles, but leaves a blank screen. I was loading a 32 bit PNG file with transparency. This is the drawing class's Code [CODE] class EzDraw { public: EzDraw(int N); void getImage(const char *); bool selectTex(unsigned int num); void Begin(); void End(); void DrawImage( SDL_Rect & rect, float sx , float sy , float sL ); private: std::vector<unsigned int> textures; unsigned int Inc; }; EzDraw::EzDraw(int N) { Inc = 0; glPixelStorei(GL_UNPACK_ALIGNMENT,4); glGenTextures(N, &textures[ 0 ] ); } #if SDL_BYTEORDER == SDL_LIL_ENDIAN static const Uint32 rmask = 0x000000FF; static const Uint32 bmask = 0x0000FF00; static const Uint32 gmask = 0x00FF0000; static const Uint32 amask = 0xFF000000; #else static const Uint32 rmask = 0xFF000000; static const Uint32 bmask = 0x00FF0000; static const Uint32 gmask = 0x0000FF00; static const Uint32 amask = 0x000000FF; #endif void EzDraw::getImage(const char * filename) { SDL_Surface * surface = IMG_Load(filename); if(surface == NULL) { // could not get filename return; } SDL_PixelFormat *format = surface->format; Uint32 width = surface->w; Uint32 height = surface->h; Uint32 widthPow = (unsigned) pow( 2, ceil( log( width ) / log( 2 ) ) ); Uint32 heightPow = (unsigned) pow( 2, ceil( log( height ) / log( 2 ) ) ); // Create new empty surface. SDL_Surface* newSurface = SDL_CreateRGBSurface( SDL_SRCALPHA, widthPow, heightPow, 32, rmask, bmask, gmask, amask ); // Fill sprite with alpha. Uint32 alpha = 0; alpha = SDL_MapRGBA( format, 0, 0, 0, amask ); SDL_Rect rect; rect.x = 0; rect.y = 0; rect.h = heightPow; rect.w = widthPow; int ret = SDL_FillRect( newSurface, &rect, alpha); surface->flags &= !SDL_SRCALPHA; SDL_SetAlpha( newSurface, SDL_SRCALPHA, SDL_ALPHA_TRANSPARENT ); // Copy image data to our new surface. SDL_BlitSurface( surface, 0, newSurface, 0 ); // Bind the texture. glBindTexture(GL_TEXTURE_2D, textures[Inc]); // Convert surface to Open GL format. gluBuild2DMipmaps(GL_TEXTURE_2D, 4, widthPow, heightPow, GL_RGBA,GL_UNSIGNED_BYTE, newSurface->pixels); // Free our temporary SDL buffers. SDL_FreeSurface( surface ); SDL_FreeSurface( newSurface ); ++Inc; } bool EzDraw::selectTex(unsigned int num) { if( num < Inc) { glBindTexture(GL_TEXTURE_2D, textures[num]);; return true; } return false; } [/CODE]