textured objects in viewer

Hi, I just downloaded and built the Collada 1.2.0 viewer and I had 2 questions:

  1. Has anyone else had trouble viewing example scenes containing textured objects? For some reason, any object that should be textured is being displayed with only smooth shading enabled. If I insert some OpenGL calls in the viewer to load the texture on-the-spot (i.e. I use a glTexImage2D right before the objects are drawn), then simple scenes like texturedcube.xml work. But this is a pretty bad hack, so if anyone knows of a cleaner fix, I’d really appreciate it.

  2. Do some of the example scenes look different in the viewer than their reference .png files that are provided in the distribution? For example, for the texturedrevolve.xml scene, in the viewer the checkerboard texture is multicolored (rather than black and white) and the actual layout of the pattern looks a little different than the .png’s. Is this a known quirk, or am I doing something wrong?

I had similar problems. For me, the solution was to

  1. copy the .exe and .dll’s into the examples directory

  2. right-mouse click on the .exe and “Create Shortcut”

  3. drag and drop examples onto the shortcut

-Don

OK, I tried that and the problem’s still there (I’m pretty sure the textures are being loaded correctly). By the way, I’m working on Windows XP, and it seems like if I add an appropriate call to glBindTexture right before each glTexCoordPointer is set up in Draw.c, regular and multitexturing work, except for the first frame in multitexture.xml.

What version of Windows are you using? And are you using precompiled binaries or compiling from source? Thanks for the speedy reply, by the way.

OK, I found out what was wrong. Basically, I’m using a previous-generation gfx card that only has 3 texture units. The problem is that the viewer always assumes I have 8 texture units, so when it tries to disable texture units [ 3 - 7 ], it ends up screwing up the texture settings. Here’re the two fixes I put in, in case anyone is in the same situation.


Fix 1

These hard-coded values may cause problems when the viewer is run on weaker gfx cards:

CgDraw.h
#define CvCgMAX_NUM_OF_LIGHTS 2
#define CvCgMAX_NUM_OF_TEXCOORS 8
#define CvCgMAX_NUM_OF_TEXTURES 8

VertexNode.h
#define CvMAX_NUM_OF_TEXTURE_ENGINES 8

So in GL\Draw.c, where CvMAX_NUM_OF_TEXTURE_ENGINES is used, I instead use the query:

glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &max_texture_engines);

The changes for the other constants should be similar, although I haven’t gotten to them yet.


Fix 2

Fixed bug that causes only one of 2 multitextures to display correctly in the first frame. In _MaterialDefine() in GL\Draw.c, in the for loop at the end of the function, moved the first call to:

SetActiveTexture(LC);

above the inner if:

if((!LMaterial->Textures.values[LC]->Image->id) && LMaterial->Textures.values[LC]->Image->data.c)
   {
    CvGL_LoadTexture(LMaterial->Textures.values[LC]->Image);
   }

so that changing the active texture occurs before the texture is loaded. The second call to SetActiveTexture(LC) in the function is unchanged.

Hi and thanks for the feedback.
The public cviewer is very old now.
There has been a lot of changes and fixes since then (including the texture management). I’ll see if/when we can release it again.

Looking forward to it… thanks!

Hi all!
I have just installed collada 1.2.0 and built it alright. The examples that do not use textures are rendered well with the cviewer, but I can’t manage to render the textured objects. I have tried to follow the instructions of pewwy without success. Any idea? Thanks all!

Does texturedcube.xml also not work? If so, then it might be due to the problem that Don mentioned (2nd post in this thread). You should make sure your working directory is COLLADA/examples, since the scene files are hard coded to look for the Textures directory relative to where you start running (and the path to this directory is actually COLLADA/examples/Textures).

Copy the executable into COLLADA/examples, move into this directory, and then try running the viewer on the scene file (or you can make a shortcut in this directory to the viewer, like Don suggested).

I have already done that. I have a copy of my executable in the path COLLADA/examples and all the examples are rendered without any texture. Maybe they are not even loaded. How could I check that? Thanks!

Since all of the textures used in the examples are in ppm format, you can make the following change to Cv_LoadPPM() in viewer/Texture.c:

Old:


int Cv_LoadPPM (CvImageData * ret, const char * filename)
{
	char header[256];
	double nbyte;
	int err;
	FILE *fp = texture_fopen(&filename, "rb");
	header[2]=0;

New:


int Cv_LoadPPM (CvImageData * ret, const char * filename)
{
	char header[256];
	double nbyte;
	int err;
	FILE *fp = texture_fopen(&filename, "rb");
	if (!fp) {
	  // print out failure if file not found
	  printf("---------------------------------------
");
	  printf("WARNING: could not find texture file: %s
", filename);
	  printf("---------------------------------------
");
	  printf("[type letter + enter] to continue
");
	  scanf("%d", &err);
	  return 0;
	}
	header[2]=0;

You can add similar checks throughout this function to make sure it goes through successfully. Also, notice that at the very bottom of viewer/GL/Texture.c, an error message should be printed to stdout if there was a problem loading the texture into OpenGL, so also look out for this (in case the problem is on OpenGL’s end).