• 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.

Blackstream

Members
  • Content count

    213
  • Joined

  • Last visited

Community Reputation

122 Neutral

About Blackstream

  • Rank
    Member
  1. OpenGL

    Here's my entire sprite loading function. I can make no claims as to the quality of this code. EDIT: My code broke the forums, it was too long. Changed the conversion part to 2 lines. EDIT 2: Finally unbroke the forums. Had way too many huge lines. Had to make them all 2 or even 3 lines. Be on the look out for compiler errors if you are copy pasting, although I think it should be okay. bool bstSprite::loadImg(char *filename, maskflags flags ) { int tempPosNew; int tempPosOld; //Use SDL_Image to load our picture SDL_Surface *sdl_data; sdl_data = IMG_Load(filename); if(!sdl_data) { //Problem loading return false; } //Convert our surface to a true color RGBA surface for easy processing //This byte swapping thing is untested, but in theory, if this compiles on a system //that uses big endian, it'll still show pictures correctly. if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { SDL_PixelFormat format = {NULL, 32, 4, 0, 0, 0, 0, 0, 8, 16, 24, SDL_Swap32(0x000000FF), SDL_Swap32(0x0000FF00), SDL_Swap32(0x00FF0000), SDL_Swap32(0xFF000000), 0, 255}; sdl_data = SDL_ConvertSurface(sdl_data, &format, SDL_SWSURFACE); } else { SDL_PixelFormat format = {NULL, 32, 4, 0, 0, 0, 0, 0, 8, 16, 24, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000, 0, 255}; sdl_data = SDL_ConvertSurface(sdl_data, &format, SDL_SWSURFACE); } //Now we use this sdl_data to make an array of our own data, in order to modify it //to our wishes. First, we need to know what size to make it (has to be a power of 2) //Get and save our dimensions width = (float)sdl_data->w; height = (float)sdl_data->h; trueWidth = 2; trueHeight = 2; //Stop at the first power of 2 that's equal to or greater than the width/height while(trueWidth < width) trueWidth *= 2; while(trueHeight < height) trueHeight *= 2; //Check our width and height and make sure they don't exceed the max texure size int maxsize; glGetIntegerv( GL_MAX_TEXTURE_SIZE, &maxsize ); if(trueWidth > maxsize || trueHeight > maxsize) { //Our picture is too big for our user's system return false; } //Now create the "real" texture. Basically the original texture but with the padded pixels SDL_LockSurface( sdl_data ); rgbaByte *rBP = new rgbaByte[(int)(trueWidth * trueHeight)]; rgbaByte temp; //Get the top left pixel if we are in TOP_LEFT mask mode rgbaByte invis; if(flags == TOP_LEFT) { SDL_GetRGBA(((Uint32 *)sdl_data->pixels)[0], (SDL_PixelFormat *)sdl_data->format, &invis.red, &invis.green, &invis.blue, &invis.alpha); } for(int y = 0; y < trueHeight; y++) { for(int x = 0; x < trueWidth; x++) { tempPosNew = (int)(y*trueWidth + x); tempPosOld = (int)(y*width + x); if(y < height && x < width) { //Get pixel data from the SDL surface SDL_GetRGBA(((Uint32 *)sdl_data->pixels)[tempPosOld], (SDL_PixelFormat *)sdl_data->format, &temp.red, &temp.green, &temp.blue, &temp.alpha); rBP[tempPosNew].red = temp.red; rBP[tempPosNew].green = temp.green; rBP[tempPosNew].blue = temp.blue; //If we are in top left mode, see if we have an invisible pixel or not if(flags == TOP_LEFT && temp.red == invis.red && temp.blue == invis.blue && temp.green == invis.green) { rBP[tempPosNew].alpha = 0; } else { rBP[tempPosNew].alpha = temp.alpha; } } else { //Put in a padded pixel rBP[tempPosNew].red = 0; rBP[tempPosNew].green = 0; rBP[tempPosNew].blue = 0; rBP[tempPosNew].alpha = 0; } } } SDL_UnlockSurface( sdl_data ); SDL_FreeSurface( sdl_data ); //Now, just create our surface! glGenTextures(1, &texSprite); glBindTexture(GL_TEXTURE_2D, texSprite); glTexImage2D(GL_TEXTURE_2D, 0, 4, (GLsizei)trueWidth, (GLsizei)trueHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, rBP); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); //Check for OpenGL errors, if there are any, return failure. GLenum err = glGetError(); if(err != GL_NO_ERROR) { //Clear all the other errors out, then return failure while(glGetError() != GL_NO_ERROR); return false; } delete[] rBP; return true; }
  2. OpenGL

    Quote:Edit: I changed the image im rendering, so it now renders a 128x128 image and things are normal (900+). The old image was some arbitrary number like 511x412. I do intend to use non poer-of-2 textures in my prog, so is there a way around this? What I do is when loading a picture, I figure out the width and height of the image, then go up to the next power of 2 (checking the numbers to make sure the video card can handle it). Then, with all the extra pixels (if any), I fill them with alpha 0 padding pixels. I believe there's a way without doing that to draw non-powers of 2, but not all video cards support it iirc, which is why I took that method.
  3. OpenGL

    I don't think you need this in your drawing code, you have it when you make the texture. At least, I don't have it in my drawing code. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); Also, in my loading code, I have them after the glTexImage2D. Don't think that would make a difference though.
  4. OpenGL

    Quote: And p.s. 5200FX is a piece of shit. seriously terrible. Believe me, I know. I used to have a 7900 GT, but it died on me and I had to return it and put back in my old fx 5200, and I haven't been in a good place to get a new card since then (I will in about a week though). I just thought that I should be able to do better, but it's good to know that it's good as is. Anyways, I'll look into VBOs and see if I can make them work.
  5. OpenGL

    Quote:Original post by Cranky Quote:Per second wise, I get about 30k pictures per second for the big pictures (64x64) and about 200k pictures per second for the small pictures (10x10 and 5x5). You have an fps of 30000-200000 and talk about slow downs? Or to what is that "k" referring to? Or do you mean that you render that amount of sprites to the screen in one second? Yeah, it's number of sprites rendering to my screen. My fps is usually somewhere in the teens at the limits I mentioned. If I was getting 200k fps, I'd be patting myself on the back right about now :p More specifically, say I've got a 5x5 sprite, and I'm laying it over a 640x480 window (fullscreen vs windowed makes no difference either btw). I can draw 12,228 sprites per frame, and about 214k sprite per second, which is about 17.6 fps. Since with that setup I'm only covering the screen once, it feels like I'm probably doing something wrong. Quote:Also try using vertex buffer object's. glVertex* functions are pretty slow, although it should be fine for any 2d rendering... I'll look into that, but I have a feeling I'm missing something more fundamental here that's causing this. [Edited by - Blackstream on October 4, 2007 2:44:27 PM]
  6. OpenGL

    Well it's just one image (and I do plan on using sprite sheets, I have texture coordinate functionality built in). But regardless, I don't think it's that because I can move the outer part of that loop [source="cpp"] for(r = 0; r < 10; r++) { } surround it around the part of my code that draws the sprite [source="cpp"] //Now draw!!1 for(r = 0; r < 10; r++) { glBegin(GL_QUADS); glTexCoord2f(left, top); glVertex2d(0, 0); glTexCoord2f(left, bottom); glVertex2d(0, drawHeight * scale_y); glTexCoord2f(right, bottom); glVertex2d(drawWidth * scale_x, drawHeight * scale_y); glTexCoord2f(right, top); glVertex2d(drawWidth * scale_x, 0); glEnd(); } And there is literally no change in my draw speed, even though I'm now calling the bindtexture 10 times less. EDIT: The guy whose post I was replying to disappeared o_O
  7. Hi all, I'm not sure what exactly I'm doing wrong. I'm trying to make a 2d engine in opengl right now. My video card is kinda crappy (a pci gforce fx 5200), but still, I don't think it should be going this slow. Bascially, I'm just rendering the same image and covering the screen with it, and to try and stress it, do that several times per frame. As it stands now, I can only layer on 1-10 times depending on the sprite size before the program slows down. If it's a big image, I can layer about 10 times, and if it's a small image (I went down to 5x5), even 1 full layer slows down a lot. Per second wise, I get about 30k pictures per second for the big pictures (64x64) and about 200k pictures per second for the small pictures (10x10 and 5x5). I've tried display lists, I've tried to limit the number of calls to bind texture, and they make literally no difference on my fps. Here is my code to draw a sprite void bstSprite::drawSprite(float x, float y, float layer, float scale_x, float scale_y, float turnDegree, float *hotspot_x, float *hotspot_y, rgbaIntensity *rgba, txtCoords *tc) { //Get our draw coordinates float drawWidth, drawHeight; float left, top, right, bottom; if(tc != NULL) { //If we have texture coordinates, get from there drawWidth = (tc->right-tc->left)*trueWidth; drawHeight = (tc->bottom-tc->top)*trueHeight; left = tc->left; top = tc->top; right = tc->right; bottom = tc->bottom; } else { //Otherwise assume they want the full image. txtCoords *tcFull = makeTxtCoords(0, 0, width-1, height-1); drawWidth=width; drawHeight=height; left = tcFull->left; top = tcFull->top; right = tcFull->right; bottom = tcFull->bottom; delete tcFull; } //Save our current state glPushMatrix(); //Set color, if passed if(rgba != NULL) { glColor4f(rgba->redI, rgba->greenI, rgba->blueI, rgba->alphaI); } //Move to position glTranslatef(x, y, layer); //Translate to the center of the picture if(hotspot_x != NULL && hotspot_y != NULL) { glTranslatef((*hotspot_x)*scale_x, (*hotspot_y)*scale_y, 0); } else { glTranslatef(drawWidth/2*scale_x, drawHeight/2*scale_y, 0); } //Rotate glRotatef(turnDegree, 0.0f, 0.0f, 1.0f); //Go up to our new upperleft corner so that we can draw if(hotspot_x != NULL && hotspot_y != NULL) { glTranslatef(-(*hotspot_x)*scale_x, -(*hotspot_y)*scale_y, 0); } else { glTranslatef(-drawWidth/2*scale_x, -drawHeight/2*scale_y, 0); } //Prepare the texture glBindTexture(GL_TEXTURE_2D, texSprite); //Now draw!!1 glBegin(GL_QUADS); glTexCoord2f(left, top); glVertex2d(0, 0); glTexCoord2f(left, bottom); glVertex2d(0, drawHeight * scale_y); glTexCoord2f(right, bottom); glVertex2d(drawWidth * scale_x, drawHeight * scale_y); glTexCoord2f(right, top); glVertex2d(drawWidth * scale_x, 0); glEnd(); //Go back to our original state glPopMatrix(); } And here is my code to layer them on the screen (just quick test code, but it might be important). for(r = 0; r < 10; r++) { for(x = 0; x < 640; x = x+s->getWidth()) { for(y = 0; y < 480; y = y+s->getHeight()) { s->drawSprite(x,y,1,1,1,a,NULL,NULL,&rgbaWhite,NULL); } } } Any help would be appreciated.
  8. What am I doing wrong? objSelect = CreateWindowEx(WS_EX_CLIENTEDGE, "LISTBOX", NULL, WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL | LBS_DISABLENOSCROLL, 655, 0, 175, 320, mainWin, (HMENU)OBJSEL, hInstance, NULL); if(objSelect == NULL) MessageBox(mainWin, "Could not create Object select box.", "Error", MB_OK | MB_ICONERROR); SendMessage(objSelect, LB_ADDSTRING, 0, (LPARAM)"It is working as intended, for sure dude."); This creates a list box in the correct place with the grayed out scroll bars as intended, and the text that I put into the box is big enough that it'll go past the right boundary of the box, yet the horizontal scroll bar stays grayed out and I can't scroll to see the rest of my lame text :( I've tried looking through various windows styles and message, and I'm not sure what I'm missing. The vertical scrollbar works fine, when I tried throwing in a ton of strings, I was able to scroll, it's just this one that doesn't seem to work for some reason. I'm sure I'm missing something obvious (I'm hoping I am anyways).
  9. Obviously video games are responsible due to the rampant infiltration of girls and guys being portrayed as sexual objects. See games like DOA: Beach Volleyball. This kind of imagary creates a kind of thinking that premarital sex is okay, and thus creates the kind of environment where high school pregnancies happen. And yes I'm completely BSing and don't believe any of this.
  10. And I solved my problem with that revelation a few seconds later when I realized I should use unsigned char instead of char for passing the key code to the function that checks to see if my key is pressed or not. In other words, anything above like 128 decimal got turned into a negative. Stupid little silly bugs. It's funny how one keyword (or lackof) can have you scratching your head for hours.
  11. Still investigating the problem... it seems ALL my keys above a certain number don't work... like DIK_F12 and higher (by higher, I mean the actual value that dinput.h assigns to that macro) just do not work.
  12. I doubt anyone will know what's going on, but I'm trying to get input with direct input. I get most keys just fine. Letter keys, function keys, whatever. But whenever I try to get the arrow keys, they are either considered always on, or always off, no matter what I press. It's really really weird. I use this code to update my key array if(FAILED(result = keyboard->GetDeviceState(256 * sizeof(char), (LPVOID)keys))) { if(FAILED(result = Acquire())) { return result; } if(FAILED(result = keyboard->GetDeviceState(256 * sizeof(char), (LPVOID keys))) { return result; } } And I use this code to check to see if a key is pressed if(keys[key] & 0x80) return true; else return false; Where key would equal DIK_DOWN
  13. Somehow, posting questions on this board 9 times out of 10 makes me figure out the answer myself a few minutes later. I just needed to use glScalef to make my text bigger than pixel or something small like that. Of course, now my text is inverted and mirrored, but that's easy cheese to fix :p Thanks :)
  14. Now, you'd think based on my questions from years ago, and how long I've been registered here that I'd be beyond problems like this, but I'm pretty bamboosled by this. Whenever I draw to draw a font, it either comes up as a single black dot, or not at all. I'm not sure why this is, as I pretty much copied the code vertibatem from another program of mine where the text worked perfectly fine. The difference is that I'm in a 2d game, and that's about it... I'm using the code from Nehe's site in general (with the display lists and everything). Anyone have any idea? I'll display my code if needed, but it's all split up into classes in different places, so I'm hoping someone might have an idea what is going on.
  15. Thanks! :D It's working now... I can't believe that one little letter was responsible for all my trouble -_-;