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

What do I do with this?

9 posts in this topic

Hey all,

I'm loading a model with AssImp and using DevIL for the textures. I'm using models from Turbosquid for testing and I'm having some troubles. First I'll start with asking what exactly I'm supposed to do with the following?

[img]http://i298.photobucket.com/albums/mm265/ahlywog/color_6.jpg[/img]

The model is made up of a single Mesh, so what do I do with this texture?

Thanks in advance.
0

Share this post


Link to post
Share on other sites
You're supposed to "parse" it using texture coordinates (aligning your model's texture coordinates on this texture image instead of each different texture of your model having its own individual texture image - which would probably contain a lot of wasted space). Doing it like this saves space and is often more convenient for the artist (and looks sort of cool, too).

In theory the model you downloaded from Turbosquid already has its texture coordinates set to match the accompanying texture, so you just need to read those uv's when loading the mesh and use that texture to render. Edited by Bacterius
0

Share this post


Link to post
Share on other sites
Right, they should have correct texture coordinates but when I apply the texture I get the following:

[img]http://i298.photobucket.com/albums/mm265/ahlywog/borkedtextures.jpg[/img]

This would be the second part of my question. The texture seems to be shrunk considerably and then the black edges get clamped all the way around instead of being stretched appropriately.
0

Share this post


Link to post
Share on other sites
How do you apply the texture, can you show some code? And also link to the relevant model (if it's free). I can't really see on the screenshot but it seems you are applying the texture in screen space? Weird. I think code is needed here. Edited by Bacterius
0

Share this post


Link to post
Share on other sites
Loading the texture:
[CODE]
GLuint loadImage(const char* theFileName)
{
ILuint imageID; // Create an image ID as a ULuint

GLuint textureID = 0; // Create a texture ID as a GLuint

ILboolean success; // Create a flag to keep track of success/failure

ILenum error; // Create a flag to keep track of the IL error state

ilGenImages(1, &imageID); // Generate the image ID

ilBindImage(imageID); // Bind the image

success = ilLoadImage((ILstring)theFileName); // Load the image file

// If we managed to load the image, then we can start to do things with it...
if (success)
{
// If the image is flipped (i.e. upside-down and mirrored, flip it the right way up!)
ILinfo ImageInfo;
iluGetImageInfo(&ImageInfo);
if (ImageInfo.Origin == IL_ORIGIN_UPPER_LEFT)
{
iluFlipImage();
}

// Convert the image into a suitable format to work with
// NOTE: If your image contains alpha channel you can replace IL_RGB with IL_RGBA
success = ilConvertImage(ilGetInteger(IL_IMAGE_FORMAT), IL_UNSIGNED_BYTE);

// Quit out if we failed the conversion
if (!success)
{
error = ilGetError();
std::cout << "Image conversion failed - IL reports error: " << error << " - " << iluErrorString(error) << std::endl;
//exit(-1);
}

// Generate a new texture
glGenTextures(1, &textureID);

// Bind the texture to a name
glBindTexture(GL_TEXTURE_2D, textureID);

// Set texture clamping method
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

// Set texture interpolation method to use linear interpolation (no MIPMAPS)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

// Specify the texture specification
glTexImage2D(GL_TEXTURE_2D, // Type of texture
0, // Pyramid level (for mip-mapping) - 0 is the top level
ilGetInteger(IL_IMAGE_BPP), // Image colour depth
ilGetInteger(IL_IMAGE_WIDTH), // Image width
ilGetInteger(IL_IMAGE_HEIGHT), // Image height
0, // Border width in pixels (can either be 1 or 0)
ilGetInteger(IL_IMAGE_FORMAT), // Image format (i.e. RGB, RGBA, BGR etc.)
IL_UNSIGNED_BYTE, // Image data type
ilGetData()); // The actual image data itself
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
}
else // If we failed to open the image file in the first place...
{
error = ilGetError();
std::cout << "Image load failed - IL reports error: " << error << " - " << iluErrorString(error) << std::endl;
std::cout << theFileName << std::endl;
exit(-1);
}
ilDeleteImages(1, &imageID); // Because we have already copied image data into texture data we can release memory used by image.
//std::cout << "Texture creation successful." << std::endl;
return textureID; // Return the GLuint to the texture so you can use it!
}
[/CODE]

Draw the scene:
[CODE]
void RenderScene()
{
std::sort (RenderList.begin(), RenderList.end(), SortRenderList);
glMatrixMode(GL_MODELVIEW);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(1.0f, 1.0f, 1.0f);
Material *TempMat = NULL;
MyVertex *TempVerts = NULL;
glDisable(GL_TEXTURE_2D);
for (RenderListIT = RenderList.begin(); RenderListIT != RenderList.end(); RenderListIT++)
{
glLoadIdentity();
glTranslatef((*RenderListIT)->Position->x, (*RenderListIT)->Position->y, (*RenderListIT)->Position->z);

glScalef ((*RenderListIT)->Scale->x, (*RenderListIT)->Scale->y, (*RenderListIT)->Scale->z);
glRotatef ((*RenderListIT)->Rotation->x, 1.0f, 0.0f, 0.0f);
glRotatef ((*RenderListIT)->Rotation->y, 0.0f, 1.0f, 0.0f);
glRotatef ((*RenderListIT)->Rotation->z, 0.0f, 0.0f, 1.0f);
if (TempMat == NULL || TempMat != (*RenderListIT)->RenderMesh->Materials)
{
TempMat = (*RenderListIT)->RenderMesh->Materials;
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, (*RenderListIT)->RenderMesh->Materials->Diffuse );
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, (*RenderListIT)->RenderMesh->Materials->Specular );
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (*RenderListIT)->RenderMesh->Materials->Ambient );
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, (*RenderListIT)->RenderMesh->Materials->Emission );
}
if (TempVerts == NULL || TempVerts != (*RenderListIT)->RenderMesh->VertexData)
{
TempVerts = (*RenderListIT)->RenderMesh->VertexData;

if ((*RenderListIT)->RenderMesh->HasVertexs == true)
{
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer( 3, GL_FLOAT, sizeof(MyVertex), (*RenderListIT)->RenderMesh->VertexData );
}
else
{
glDisableClientState(GL_VERTEX_ARRAY);
}
if ((*RenderListIT)->RenderMesh->HasNormals == true)
{
glEnable(GL_LIGHTING);
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer( GL_FLOAT, sizeof(MyVertex), (*RenderListIT)->RenderMesh->VertexData );
}
else
{
glDisable(GL_LIGHTING);
glDisableClientState(GL_NORMAL_ARRAY);
}
if ((*RenderListIT)->RenderMesh->HasTexcoords == true)
{
if ((*RenderListIT)->RenderMesh->HasTexture == true)
{
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, (*RenderListIT)->RenderMesh->Active->TextureHandle);
}
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer( 2, GL_FLOAT, sizeof(MyVertex), (*RenderListIT)->RenderMesh->VertexData );
}
else
{
glDisable(GL_TEXTURE_2D);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
if ((*RenderListIT)->RenderMesh->HasColors)
{
glEnableClientState(GL_COLOR_ARRAY);
glColorPointer( 3, GL_FLOAT, sizeof(MyVertex), (*RenderListIT)->RenderMesh->VertexData );
}
else
{
glDisableClientState(GL_COLOR_ARRAY);
}
}
glDrawArrays(GL_TRIANGLES, 0, (*RenderListIT)->RenderMesh->NumVerticies);
}
//RenderList.clear();
glutSwapBuffers();
}
[/CODE]

the model [url="http://www.turbosquid.com/FullPreview/Index.cfm/ID/526437"]http://www.turbosquid.com/FullPreview/Index.cfm/ID/526437[/url]
0

Share this post


Link to post
Share on other sites
It looks like you are using RenderMesh->VertexData for your texcoords, this is most likely incorrect (Since it appears as if you're only storing vertex coordinates in that structure), With assimp you get the texture coordinates in the mTextureCoords member. (I can't see your model loading code so i can't be much more specific than that)
1

Share this post


Link to post
Share on other sites
[CODE]
struct MyVertex
{
float x, y, z; // Vertex
float nx, ny, nz; // Normal
float u, v; // Texcoords
float a, r, g, b; // Color
float padding[4];
};
[/CODE]

That's my VertexData
0

Share this post


Link to post
Share on other sites
[quote name='Ahl' timestamp='1345478925' post='4971508']
[CODE]
struct MyVertex
{
float x, y, z; // Vertex
float nx, ny, nz; // Normal
float u, v; // Texcoords
float a, r, g, b; // Color
float padding[4];
};
[/CODE]
[/quote]

My openGL is a bit rusty, but I believe you want the value passed into the gl*Pointer() functions to actually point to the part of the struct that is relevant.
ie:
[CODE]
glNormalPointer( GL_FLOAT, sizeof(MyVertex), &(*RenderListIT)->RenderMesh->VertexData.nx );
glTexCoordPointer( 2, GL_FLOAT, sizeof(MyVertex), &(*RenderListIT)->RenderMesh->VertexData.u );
glColorPointer( 3, GL_FLOAT, sizeof(MyVertex), &(*RenderListIT)->RenderMesh->VertexData.a );
//etc....
[/CODE]
2

Share this post


Link to post
Share on other sites
[quote name='WarAmp' timestamp='1345480866' post='4971531']
[CODE]
glNormalPointer( GL_FLOAT, sizeof(MyVertex), &(*RenderListIT)->RenderMesh->VertexData.nx );
glTexCoordPointer( 2, GL_FLOAT, sizeof(MyVertex), &(*RenderListIT)->RenderMesh->VertexData.u );
glColorPointer( 3, GL_FLOAT, sizeof(MyVertex), &(*RenderListIT)->RenderMesh->VertexData.a );
//etc....
[/CODE]
[/quote]

That did it. It's working now. Awesome, thank you.
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