• Content count

  • Joined

  • Last visited

Community Reputation

288 Neutral

About Tallkotten

  • Rank
  1. Uncertainty with VBO and OpenGL

    Ok, thanks!   I'm going to look at how some other people do it and ultimately decide on a way to go. But yours sound solid.
  2. Uncertainty with VBO and OpenGL

    Ok, so you are saying: "Store a static VBO in the memory with some coordinates and texture data and then use glTranslate to move it on the screen"?
  3. Uncertainty with VBO and OpenGL

    I might be talking in my sleep since i know very little on the VBO topic. This is my current code for drawing something to the screen:   float texLeft = (float)clip.x / width; float texRight = (float)( clip.x + clip.w ) / width; float texTop = (float)clip.y / height; float texBottom = (float)( clip.y + clip.h ) / height; glPushMatrix(); glTranslatef(0, 0, 0); glScalef(scale,scale,1); //set color glColor4f(R, G, B, A); glBegin( GL_QUADS ); glTexCoord2f( texLeft, texTop ); glVertex2f( x, y ); glTexCoord2f( texRight, texTop ); glVertex2f( x+w, y ); glTexCoord2f( texRight, texBottom ); glVertex2f( x+w, y+h ); glTexCoord2f( texLeft, texBottom ); glVertex2f( x, y+h ); glEnd(); glPopMatrix(); Each call i update the position and the texture-coords.   From the tutorials i've read on VBO's you have to do the same: (a straight copy-paste from the tutorials) GLfloat vertices_position[8] = { x, y, x+w, y, x+w, y+h, x, y+h, }; GLfloat texture_coord[8] = { texLeft, texTop, texRight, texTop, texRight, texBottom, texLeft, texBottom, }; // Allocate space for vertex positions and texture coordinates glBindBuffer(GL_ARRAY_BUFFER , vbo); glBufferData(GL_ARRAY_BUFFER , sizeof(vertices_position) + sizeof(texture_coord), NULL, GL_STATIC_DRAW); // Transfer the vertex positions: glBufferSubData(GL_ARRAY_BUFFER , 0, sizeof(vertices_position), vertices_position); // Transfer the texture coordinates: glBufferSubData(GL_ARRAY_BUFFER , sizeof(vertices_position), sizeof(texture_coord), texture_coord); This wouldn't in any way decrease the performance? If it will, how else do i define position and texture-coords when using a VBO?   Thank you for taking your time, i really appreciate it!
  4. Uncertainty with VBO and OpenGL

    So you are suggesting that i check if the entity has changed location and if it has i'll update the vertices for location? And same goes with the texture. That's all i ever need to update, drawing location and texture-coords.   How much performance are we talking about? Lower than using immediate mode?
  5. Uncertainty with VBO and OpenGL

      But each enemy hold it's own copy of it? Right?     I understanding right now is that i create a VBO when a (lets say) enemy is created. I then store this with the enemy until it's destroyed (how do i unload a VBO?).   You're saying that i should't update the data, is it ok to update the texture and vertex buffer? That shouldn't be a problem right? Because i need to be able to do that every frame.
  6. Uncertainty with VBO and OpenGL

    Hi,   I've spent the day trying to understand the use of VBO since i want to boost the FPS in my game.   However i'm having some trouble understanding the life-scope of the VBO and how to properly use it. Every sample code and tutorial i've found has shown a single static scene to render and I've got a pretty complex file architecture in my game.    --Revelation?--   So this literally just occurred to me. If a VBO behaves kind of like a texture (you generate and bind it) would i be correct to say that each entity in the game should hold it's own VBO?   For example; my player character would create a VBO at runtime and then call a render-function which fills it with data and renders it?    The render code would take the VBO, texture and some placement information. Then my normal code would run (bind the texture, create a clip for the 2D image) then I create a new vertex buffer and a new texture buffer and bind them. Lastly the VBO should be bound and rendered.   A NPC would have it's own VBO just like the player does. --   Am i thinking right? And even if i am, could you be so kind to explain the scope and use of a VBO? Like i said, all the examples just handled a static scene to render so i'm having trouble understanding how to update it.   My game is in 2D and currently renders everything as quads or circles (all collision is done with rectangles). The size of an object is never changed after creation. When an object animates it'll change the location of the clip within it's loaded imagesheet. So the image itself will rarely change.   I'm kind of tired at the moment so i hope i made myself clear enough for you to understand.   Looking forward to some answer, thanks in advance!
  7. Switching rendering from SDL to OpenGL

      Hi and thanks for the help man!   I actually have a pretty sophisticated image loader that i've written myself but i only takes SDL_Surface's so i only have to make it work with the GL texture instead.   I plan to:  1.open a image in SDL 2.convert it to a texture and save the proportions 3.maybe make a class that keeps track of if the image is in use (like a smart pointer) and if it isnt dispose of it 4.release the SDL_Surface and save all of the other stuff for later use
  8. Switching rendering from SDL to OpenGL

    Every image loading library provides a means to query the width and height of an image. And if you decide one day to implement your own loader, all of the commonly used image formats store width/height data in the file header (as should you if you ever create your own image file format).   I'm thinking of saving the image size from the SDL_Surface when i load an image. Then i link the size to a texture or something,    Thanks for the tip, i'll have to look into that when i get home!
  9. Switching rendering from SDL to OpenGL

    Thank you both for the answers. I suspected that was the FPS theif but like i said i am only trying out this new way atm.     I use SDL for other stuff like keyboard detection as well, so i might stick around with it.    ---   Thanks very much you both! I'll try altering my code a bit when i get home and see if i see any performance boost
  10. Hi!   I took it upon myself to finally start migrating from SDL to OpenGl in my project today. So far I've managed to (in isolated code) translate an SDL_Surface to an OpenGl texture which i then use to apply on polygons.   In my previous rendering method i used a lot of clips. Meaning I've got one image with maybe 3-5 images on it which i then clip before i render to get the desired image to show. I've managed to translate this over to OpenGl as well but it takes a bit of work and i need to know the loaded image dimensions before i do.   Just to clarify how the rendering process works now, so you get a better scope of my problem:   1. Loads image to an SDL_Surface 2. Saves it to an array 3. Something fetches the image memory location from the array 4. Converts the SDL_Surface to a OpenGl texture 5. Clips the texture 6. Renders it to QUADS 7. Destroys the texture   My Convert code is basically the same as this one here: http://content.gpwiki.org/index.php/SDL:Tutorials:Using_SDL_with_OpenGL   Question time:    1. I've noticed a sudden drop of FPS since the tryout change (only the tiles are being rendered at the moment since haven't made it global yet). The drop if from 400+ FPS to around 60 FPS after i use glDeleteTextures(); on the texture I've just drawn. Why is this? I suspect it's the conversion that drains the fps.   2. If it is the conversion that drains the FPS, then it is smarter to convert the image once just as it loads and save the texture in the array instead of the surface? Sounds like it...   3. Is there any reason for me to save the image as a SDL_Surface instead of loading it from OpenGL directly? Can i do that?   4. If there is no reason at all for me to involve SDL in the rendering process then how to i keep track of the loaded image width and height? Right now i use surface->w/surface->h. Is there similar ways in OpenGl?   I think that's all! Thanks for your time, i really appreciate answers!   // Tallkotten    
  11. Memory management, mainly using SDL

    [quote name='SiCrane' timestamp='1352487659' post='4999386'] No, it requires a [i]const[/i] char *, which you can from a std::string with the .c_str() member function. [/quote] Well... f*ck me... I've used that to some extent but now i just feel silly... Is it even worth going back and using that instead of my newly implemented system?
  12. Memory management, mainly using SDL

    [quote name='Karsten_' timestamp='1352477385' post='4999333'] [quote name='Tallkotten' timestamp='1352366168' post='4998799'] How do i know if i have to do that or not? And what difference does it make? [/quote] If you get a compiler error stating that std::tr1::shared_ptr does not exist, then you will need to include the tr1 versions of the header. If you are using the CodeBlocks IDE, that probably means you are using GCC/G++ as your compiler, so it is quite likely you will need to include them. [/quote] Ok thanks! Yes i am using GCC/G++ [quote name='Álvaro' timestamp='1352486514' post='4999377'] So why are you using `new' and `delete' for things like a "char * array"? You probably should be using std::vector or std::string instead of using new to allocate arrays. It's much harder to have a memory leak if you don't use `new'. [/quote] Well that is old code and when i looked up how to do it that was one of the only ways. Also TTF_RenderText_Solid requires a char*. http://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_43.html
  13. Memory management, mainly using SDL

    I just found out where one of the leaks were located... In one of my functions where i turn a string to a char* array i never used delete after new... Thanks everyone! Hopefully i wont get stuck on the rest of the code (that i have yet to check for leaks ).
  14. Memory management, mainly using SDL

    [quote name='Karsten_' timestamp='1352315450' post='4998532'] Hi, if you are using C++, perhaps you can use a smart pointer for this (These two lines looks ugly as sin, but provides memory safety I have yet to see with any other language / platform)... [code] std::tr1::shared_ptr<SDL_Surface> surface; surface.reset(SDL_LoadImage(imageFileName.c_str()), std::tr1::bind(SDL_FreeSurface, std::tr1::placeholders::_1)); // Now you can do whatever and RAII will take care of the memory management. [/code] Remember: You must set the deleter to be SDL_FreeSurface, because otherwise (and in std::auto_ptr) the c++ [b]delete[/b] will just be called, which will cause undefined behaviour with things not created via [b]new[/b]. I generally do this with OpenGL textures but there is no reason this wont work for SDL textures. [/quote] Yes that is one option i might go with later on when i add the manager system. Like i described earlier i dont really have to unload images at the moment since i have so few loaded. But i'll definitely consider it! [quote name='Karsten_' timestamp='1352315450' post='4998532'] If you are not using the very latest compiler you will need to include the technical report 1 versions of memory and functional. #include <tr1/functional> #include <tr1/memory> [/quote] How do i know if i have to do that or not? And what difference does it make? I am running codeblocks
  15. Memory management, mainly using SDL

    [quote name='ultramailman' timestamp='1352247935' post='4998277'] There aren't any references in your code, only pointers D: [/quote] Yeah, my mind were some place else. [quote name='ultramailman' timestamp='1352247935' post='4998277'] I think freeing surfaces should only be done when you are absolutely sure it will never be used again. Are you really going to use this example_image.png once? If you are sure, then the correct way to do it is to use the complement of imageLoader.loadImg [/quote] This is true and i plan on adding this function. But i am planning on writing a system which takes care of what is in use and what's not so i am waiting with this. There really aren't many images now to load either so the unload functions isn't needed at the moment. Thanks for your reply!