• 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.
Sign in to follow this  
Followers 0
nickme

glut:can someone recommend a simple png loading lib for vc2010

6 posts in this topic

hi

i would like someone recommending a simple png loading library that i do not have to build from source code, which i only have to link it to vc 2010.

i tried to build the freeImage, libpng and SOIL, all failed. i don't know what happened but my vc kept saying that the project is not available or the sln is corrupted, things like that. if you insisting that i use one of the library above, you will have to walk me thru the process of building the library.

thanks in advance Edited by nickme
0

Share this post


Link to post
Share on other sites
Why are you using png files? Maybe it is that your source is png, and you have a lot of them? But if that isn't the case, consider using simple bmp files instead. There is no reason to use png files for the compressed functionality. Your artists shouldn't use png files anyway, they should store the source in either gimp XCF format or Photoshop PSD.[list]
[*]When you load it into OpenGL, they have to be decompressed anyway (or using one of the OpenGL compressed formats).
[*]If you compress images to save disk space, then it is probably an optimization that is not needed. Disk space is cheap today, and most applications don't have that high amounts of image data to make a difference.
[*]If you want to minimize the size of the installation package, then the installer generators will do a compression that is just as good anyway.
[*]If you worry about loading time from disk, then again, you can transform the images into one of the OpenGL compressed formats, and save that on disk.
[*]Loading bmp is very easy. You can find source code that fits on one screen.
[/list]
0

Share this post


Link to post
Share on other sites
Hello,

I tend to just use libpng directly.

The following is a very simple example of loading the png into a byte array (ready for uploading to the graphics card)

http://zarb.org/~gc/html/libpng.html

If you would like a library that generates the OpenGL texture for you, then perhaps also have a look at OpenIL (DevIL). Edited by Karsten_
0

Share this post


Link to post
Share on other sites
[quote name='Karsten_' timestamp='1354211479' post='5005374']
I tend to just use libpng directly.

The following is a very simple example of loading the png into a byte array (ready for uploading to the graphics card)

[url="http://zarb.org/~gc/html/libpng.html"]http://zarb.org/~gc/html/libpng.html[/url]

If you would like a library that generates the OpenGL texture for you, then perhaps also have a look at OpenIL (DevIL).
[/quote]

hi Karsten_

thank for replying.

where do i get the unistd.h file? vc said it was not able to find it.

my problem is not know how to use it, it is how to link it to vs c++ 2010. i might be wrong, i still haven't read the file very carefully, yet. do i have to link the project to libpng.lib before using the program? if that is the case, i still don't know how to link it to libPNG. it would be nice if you could walk me through the process of compiling the libpng lib and building the libPNG.lib. Edited by nickme
0

Share this post


Link to post
Share on other sites
hi Karsten_

it seemed that the program you provided does not save it to a texture where i can use it to display it to the screen. it just save it to a file, it that right? maybe you did not know that i was using vc 2010 with opengl 3.3?
0

Share this post


Link to post
Share on other sites
Although it does write to a file, you can just ignore this function.

Just have a look at [b]read_png_file(char*);[/b] to learn how to read in the .png file and then perhaps take a look at the [b]process_file();[/b] function to see how to use the byte array.

If this still doesnt help, let me know and I will upload a wrapped version of this code from my project that should also generate the OpenGL texture for you.
0

Share this post


Link to post
Share on other sites
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] Edited by SHOKWAV
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0