[SOLVED] Simple texturing problem, tristrips and nodepaths

Hi,

I am very new to Panda (as in I started yesterday). I am creating a video player and so am using the sample which uses a VideoTexture, problem is, I want more than one video playing (I know this is meant to have bad performance but I’ll work on that later).

I’ve hit a fundamental problem as I don’t know how panda3d really does texturing on primitives. I’ve got as far as creating 6 vertices with texcoords and put them into a GeomVertexData, then tried to create 2 tristrips from these 6 points to get 4 triangles (2 quads) as follows:

o–o--o
|\ |\ |
| | |
o–o--o

(o = vertex, \ = triangle edge)

I have added the first quad (as a tristrip) to a Geom, then that into a GeomNode then that into a NodePath as described in the documentation:

prim1 = GeomTristrips(Geom.UHStatic)
        prim1.addVertices(0, 1, 2, 3)
        
        geom1 = Geom(vdata)
        geom1.addPrimitive(prim1)
        
        node1 = GeomNode('gnode1')
        node1.addGeom(geom1)
        self.nodePath1 = render.attachNewNode(node1)
        
        self.nodePath1.setTexture(self.tex1)
        self.nodePath1.setTexScale(TextureStage.getDefault(), self.tex1.getTexScale())
        

(ignore the indentation messups).

This is where my problem lies. The texcoords are set up correct for the first tristrip but that means the 2nd one will be messed up right? Because they share those 2 middle vertices?

So should I just use 8 vertices, duplicating the middle 2 to be able to set up the texcoords correctly or is the optimisation of sharing vertices worth it?

Also, I have a problem understanding how textures get applied, can I not just bind a texture to certain vertices like with raw OpenGL? Do I have to play a texture to a NodePath, and if so, does that mean I can only have one of my tristrips in a NodePath (as I have 2 videos playing, one for each quad)?

It would be very nice if I could create one NodePath or something that has 2 textures on it for both tristrips because otherwise the code looks a bit bloated and there are lots of duplicates.

Thanks for your time,

Poncho

I recommend duplicating the common vertices. Make two completely different objects to show your two different textures. You gain nothing by keeping them shared, and only complicate your code.

It’s the same way with raw OpenGL. You can’t actually bind a texture to a particular vertex; you can only bind a texture to the current render state, then draw one or more triangle strips in the current state. If you want to switch textures, you have to switch states, which means you have to re-issue the vertices anyway. Of course you could share the same vertex buffer for both draw calls, which is what you are simulating here by having two Geoms that share the same GeomVertexData; but there’s no advantage to doing this when you’re only talking about a handful of vertices.

By the way, if you’re only creating rectangular geometry for the purpose of applying a texture, I suggest using the high-level CardMaker class instead of mucking about with the low-level Geom structures. Or even create an egg file with the appropriate texture already applied, and simply load the egg file.

David

This thread has a couple code snippets that make quads (using CardMaker) to display images. I’m not sure whether it’s suitable for movies, but maybe you could make use of it.

[url]A non-power-of-2, pixel centric texture loader for directGui]

Ah thank you very much for the replies.

I’ve managed to just go with the CardMaker route, you see I didn’t realise the “cards” it made were NodePaths and therefore could be put anywhere in 3d space, I thought they were just orthographics and so shown in 2d space.

Thanks for the responses,

Poncho