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

SHOKWAV

Members
  • Content count

    17
  • Joined

  • Last visited

Community Reputation

138 Neutral

About SHOKWAV

  • Rank
    Member
  1. Eh, your code actually looks pretty slick, considering you're doing GUI programming. Also, the "established libraries" for GUIs are notoriously bulky, so hand-rolling a solution is actually a viable option in this case.
  2. Hello, I need to learn the proper usage for glClearBufferData for an application I'm creating. I've looked at the official documentation... which isn't very descriptive, mainly what I don't understand are the internalformat, format, and type parameters. void glClearBufferData( GLenum target, GLenum internalformat, GLenum format, GLenum type, const void * data); I have a buffer with a target and some data, and all the data are in float form. I want to clear it all out to 0. Question is, how? Which one do I specify that it's in floats? Internalformat? What about the format and type? I just want to clear out all the memory. I know to specify NULL for data... but what about format and type?
  3. Ah well that makes sense. Although I thought UVs were only for supplying corners.
  4. OpenGL

    Seems that glut is messing with some internal state, no? You really shouldn't be using glut or fixed-functionality.
  5. The uvs are computed from xml files at run-time. But I can't 'skip' a portion of a texture using supplied uvs, right? Also, what I'm using is working, I just moved it to the fragment shader.
  6. I don't see how this could be done CPU wise? But here's what I'm attempting to use to render a section of a texture (frag shader)[CODE] #version 140 in vec4 frag_color; in vec2 frag_tex_coord; uniform sampler2D tex; uniform vec2 frag_tex_coord_offset; void main(){ gl_FragColor = texture(tex, frag_tex_coord + frag_tex_coord_offset); } [/CODE]
  7. Here's what I'm currently using, straight from libpng. [CODE] int Memento::_GetTextureInfo(int color_type){ switch(color_type){ case PNG_COLOR_TYPE_GRAY: return (1); break; case PNG_COLOR_TYPE_GRAY_ALPHA: return (2); break; case PNG_COLOR_TYPE_RGB: return (3); break; case PNG_COLOR_TYPE_RGB_ALPHA: return (4); break; default: return (-1); break; }; return (-1); } unsigned Memento::_LoadImageIntoTexture(std::string const& file, unsigned& width, unsigned& height, bool clamp_texture){ png_struct* img_read_struct = NULL; png_info* img_info_struct = NULL; png_byte img_sig[PNG_SIG_SIZE], *img_pixels = NULL, **img_row_ptrs = NULL; std::FILE* img_file = NULL; int img_bit_depth, img_color_type, img_components; unsigned tex, gl_colors, img_width, img_height; if(!(img_file = std::fopen(file.c_str(), "rb")))return (PNG_READ_FAILURE); std::fread(img_sig, PNG_SIG_SIZE, sizeof(png_byte), img_file); if(png_sig_cmp(img_sig, 0, PNG_SIG_SIZE) != 0){ std::fclose(img_file); return (PNG_READ_FAILURE); } std::rewind(img_file); if(!(img_read_struct = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL))){ std::fclose(img_file); return (PNG_READ_FAILURE); } if(!(img_info_struct = png_create_info_struct(img_read_struct))){ png_destroy_read_struct(&img_read_struct, NULL, NULL); std::fclose(img_file); return (PNG_READ_FAILURE); } if(setjmp(png_jmpbuf(img_read_struct))){ png_destroy_read_struct(&img_read_struct, &img_info_struct, NULL); std::fclose(img_file); return (PNG_READ_FAILURE); } png_init_io(img_read_struct, img_file); png_read_info(img_read_struct, img_info_struct); img_bit_depth = png_get_bit_depth(img_read_struct, img_info_struct); img_color_type = png_get_color_type(img_read_struct, img_info_struct); if(img_color_type == PNG_COLOR_TYPE_PALETTE) png_set_palette_to_rgb(img_read_struct); if(img_color_type == PNG_COLOR_TYPE_GRAY && img_bit_depth < 8){ png_set_expand_gray_1_2_4_to_8(img_read_struct); } if(png_get_valid(img_read_struct, img_info_struct, PNG_INFO_tRNS)) png_set_tRNS_to_alpha(img_read_struct); if(img_bit_depth == 16){ png_set_strip_16(img_read_struct); }else if(img_bit_depth < 8){ png_set_packing(img_read_struct); } png_read_update_info(img_read_struct, img_info_struct); png_get_IHDR(img_read_struct, img_info_struct, &img_width, &img_height, &img_bit_depth, &img_color_type, NULL, NULL, NULL); if((img_components = Memento::_GetTextureInfo(img_color_type)) == -1){ png_destroy_read_struct(&img_read_struct, &img_info_struct, NULL); std::fclose(img_file); return (PNG_READ_FAILURE); } img_pixels = (png_byte*)malloc(sizeof(png_byte) * (img_width * img_height * img_components)); img_row_ptrs = (png_byte**)malloc(sizeof(png_byte*) * img_height); for(unsigned i = 0; i < img_height; ++i) img_row_ptrs[i] = (png_byte*)(img_pixels + (i * img_width * img_components)); png_read_image(img_read_struct, img_row_ptrs); png_read_end(img_read_struct, NULL); glGenTextures(1, &tex); glBindTexture(GL_TEXTURE_2D, tex); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); if(clamp_texture){ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); } (img_components == 4)? (gl_colors = GL_RGBA):(0); (img_components == 3)? (gl_colors = GL_RGB):(0); (img_components == 2)? (gl_colors = GL_LUMINANCE_ALPHA):(0); (img_components == 1)? (gl_colors = GL_LUMINANCE):(0); glTexImage2D(GL_TEXTURE_2D, 0, img_components, img_width, img_height, 0, gl_colors, GL_UNSIGNED_BYTE, img_pixels); glBindTexture(GL_TEXTURE_2D, 0); png_destroy_read_struct(&img_read_struct, &img_info_struct, NULL); std::fclose(img_file); free(img_row_ptrs); free(img_pixels); width = img_width; height = img_height; return (tex); } [/CODE]
  8. Hello, I have a problem of which I couldn't seem to find any advice of on Google. I'm using a tileset creator (Tiled) for my game, which takes images and splits them up into tilesets for rendering. I figure this is very efficient and I would like to adopt this in my rendering. However, how can I actually just render a PORTION of a texture in OpenGL? Changing the texture coordinates does nothing more than just move the actual corners of the image. What I want to do is choose what area of the texture to render from, rather than having to split up the image into a bunch of smaller images and load them, which sounds extremely inefficient. Is this a GLSL or an OpenGL problem? Help!
  9. I love you. That fixed everything, and I can finally more forward with the program. THANK.YOU. In case anyone was wondering, this is what I was trying to describe: http://www.youtube.com/watch?v=yDVF08jILE4&feature=youtu.be
  10. Guys, please help... I'm really desperate to get this done... please, can anyone explain this unfixable, sudden problem? It ONLY does this when I reset the rotated polygon and try to rotate it from there...
  11. It's... really hard to explain, it's rotating very strangely. It's supposed to rotate only on the Z axis, and was doing just that a while ago... header: [CODE]#ifndef POLY2D_H #define POLY2D_H #include "Global.h" #include "Dim2D.h" class Poly2D{ Dim2D<float>* center; float rotation; short (*vertices)[2]; float (*rotVertices)[2]; //rotated vertices const ushort vertLength; void setCenter(); public: Poly2D(Dim2D<short>* list[], const ushort len); ~Poly2D(); void translate(Dim2D<short>*& amount); void rotateBy(const float angle); void draw(); }; #endif[/CODE] definition file: [CODE]#include "Poly2D.h" Poly2D::Poly2D(Dim2D<short>* list[], const ushort len):center(new Dim2D<float>()), vertices(new short[len][2]), rotVertices(new float[len][2]), vertLength(len), rotation(0.0f){ for(ushort i = 0; i < len; i++){ vertices[i][X] = list[i] -> x; vertices[i][Y] = list[i] -> y; rotVertices[i][X] = (float)list[i] -> x; rotVertices[i][Y] = (float)list[i] -> y; } setCenter(); } Poly2D::~Poly2D(){ } void Poly2D::setCenter(){ float cx = 0.0f, cy = 0.0f; for(ushort i = 0; i < vertLength; i++){ cx += rotVertices[i][X]; cy += rotVertices[i][Y]; } cx = cx / (float)vertLength; cy = cy / (float)vertLength; center -> x = cx; center -> y = cy; } void Poly2D::translate(Dim2D<short>*& amount){ //todo: update this for(ushort i = 0; i < vertLength; i++){ vertices[i][X] += (float)amount -> x; vertices[i][Y] += (float)amount -> y; } setCenter(); } void Poly2D::rotateBy(const float angle){ rotation += angle; const float sinA = sinf(rotation), cosA = cosf(rotation); for(ushort i = 0; i < vertLength; i++){ //reset vertices rotVertices[i][X] = vertices[i][X]; rotVertices[i][Y] = vertices[i][Y]; float &x = rotVertices[i][X], &y = rotVertices[i][Y]; x -= center -> x; y -= center -> y; x = (x * cosA) - (y * sinA); y = (x * sinA) + (y * cosA); x += center -> x; y += center -> y; } } void Poly2D::draw(){ glEnableClientState(GL_VERTEX_ARRAY); glLoadIdentity(); glPushMatrix(); glVertexPointer(2, GL_FLOAT, 0, rotVertices); glDrawArrays(GL_POLYGON, 0, vertLength); glPopMatrix(); glDisableClientState(GL_VERTEX_ARRAY); }[/CODE]
  12. Strange... I took your advice, and I created another array to hold a copy of the vertex data to apply the rotations to... now it's wanting to rotate on like every axis? [CODE]void Poly2D::rotateBy(const float angle){ //accumulated rotation... what's the efficient way to clamp this? rotation += angle; const float sinA = sinf(rotation), cosA = cosf(rotation); for(ushort i = 0; i < vertLength; i++){ //this is just a copy of the vertex data rotVertices[i][X] = vertices[i][X]; rotVertices[i][Y] = vertices[i][Y]; float &x = rotVertices[i][X], &y = rotVertices[i][Y]; x -= center -> x; y -= center -> y; x = (x * cosA) - (y * sinA); y = (x * sinA) + (y * cosA); x += center -> x; y += center -> y; } }[/CODE]
  13. [quote name='jefferytitan' timestamp='1339564827' post='4948721'] This is common in graphics due to compounding rounding issues. I would suggest keeping the original polygon co-ordinates untouched, and do rendering based on a copy which is the original polygon rotated by the accumulated rotations. Also consider letting the GPU do the work, as it's pretty good at applying a transformation to a sequence of primitives. [/quote] Thanks, I figured that was the issue, I'll resolve it quite easily now. Also I'm not very good at things like GLSL, lol.
  14. I'm making my own polygon class for a game I'm making. However, whenever I try to apply rotation to 'em, it shrinks the entire polygon. After around 1000 rotations the shrinking becomes apparent, and visually you can notice them shrinking rapidly. Is there any way to minimize this? I'm assuming it's some precision errors? Here's my code below, I'm hoping it's enough to see my problem. (X and Y are macros btw) [CODE]void Poly2D::rotateBy(const float angle){ const float sinA = sinf(angle), cosA = cosf(angle); for(ushort i = 0; i < vertLength; i++){ float &x = vertices[i][X], &y = vertices[i][Y]; //move to origin for rotating x -= center -> x; y -= center -> y; x = (x * cosA) - (y * sinA); y = (x * sinA) + (y * cosA); //move back x += center -> x; y += center -> y; std::cout << x << ", " << y << std::endl; } }[/CODE]
  15. [quote name='ReaperSMS' timestamp='1332610919' post='4924931'] You're already telling it to use 2 shorts per vertex, glDrawArrays expects a vertex count, not a component count. [/quote] Thanks, guys! Fixed it, and it runs perfectly now. I do have one last question: can I just enable and disable the vertex and textrue arrays when I startup and shutdown my program, or should I enable and disable them every time I draw? I'm trying to conserve speed.