Forums > Jitter

jit.gl.text3d + capture = backwards text – why?

October 11, 2006 | 5:35 am

Hi -

In the javascript below, I’m using the capture attribute of a sketch object to render some 3D text as a texture onto some 3D primitives.

Can someone explain to me why the text comes out backwards?

Better yet, can anyone tell me how to get it to map correctly?

Thanks -

- pH

//begin text3d.js

var myText = new JitterObject("jit.gl.text3d","glcontext2");
myText.automatic = 0;
myText.name = "t3d";
myText.align = 1;
myText.lighting_enable = 1;
myText.color = [1,1,0,1]
myText.depth = 0.5;
myText.rotate = [-30,0,0];
myText.scale = [0.1,0.3,0.1];
myText.font("Geneva");
myText.text("Why is this text backwards?");

var myDestTexture = new JitterObject("jit.gl.texture","glcontext2");
myDestTexture.dim = [640,480];
myDestTexture.name = "cap";

var mySourceSketch = new JitterObject("jit.gl.sketch","glcontext2");
mySourceSketch.capture = "cap";
mySourceSketch.reset();
mySourceSketch.glclear();
mySourceSketch.color = [0,0.5,0,1];
mySourceSketch.plane(1.5);
mySourceSketch.gltranslate(0,0,0.5);
mySourceSketch.drawobject(myText.name,0);

var myDestSketch = new JitterObject("jit.gl.sketch","glcontext2");
myDestSketch.lighting_enable = 1;
myDestSketch.smooth_shading = 1;

var myHandle = new JitterObject("jit.gl.handle","glcontext2");

var myRender = new JitterObject("jit.gl.render","glcontext2");
myRender.erase_color = [0,0,0.25,1];
myRender.depth_enable = 1;

var myWindow = new JitterObject("jit.window","glcontext2");
myWindow.size = [640,480];
myWindow.depthbuffer = 1;

function bang() {
myDestSketch.reset();
myDestSketch.glclear();
myDestSketch.glrotate(myHandle.rotate);
myDestSketch.gltranslate(myHandle.position);

myDestSketch.glcolor(1,1,1,1);
myDestSketch.glbindtexture("cap");

myDestSketch.glpushmatrix();
myDestSketch.gltranslate(0.66,0,0);
myDestSketch.cube(0.25);
myDestSketch.glpopmatrix();

myDestSketch.shapeorient(90,0,0);

myDestSketch.glpushmatrix();
myDestSketch.gltranslate(-0.66,0,0);
myDestSketch.sphere(0.25);
myDestSketch.glpopmatrix();

myDestSketch.cylinder(0.25,0.25,0.25);

myRender.erase();
myRender.drawswap();
}

//end text3d.js


October 11, 2006 | 10:36 pm

More data:

forgot to mention that I’m running this under OS X 10.4.8, runs the same on PPC and Intel.

Tried running it on XP, and the result is the same (backwards text), but I also get these errors constantly:

jit.gl.texture: setting compare func.: GL Error: Invalid enumeration
jit.gl.texture: setting texture mode.: GL Error: Invalid enumeration

So am I doing something wrong?

I’m fairly desperate to find a quick answer to this due to an impending deadline. Any clues appreciated.

Also, forgot to post the max patch to go along with the js, all it is is the javascript & a metro, but just in case here it is:

max v2;
#N vpatcher 766 178 1366 578;
#P window setfont "Sans Serif" 9.;
#P newex 15 54 57 196617 qmetro 20;
#P toggle 15 35 14 0;
#P newex 15 77 102 196617 js text3d.js;
#P connect 1 0 2 0;
#P connect 2 0 0 0;
#P pop;


October 12, 2006 | 5:28 am

i think its something to do with normals but im not sure, i got it
displaying correctly by changing the scale to negative on the x
myText.scale = [-0.1,0.3,0.1];

2006/10/12, Perry Hoberman :
>
>
> More data:
>
> forgot to mention that I’m running this under OS X 10.4.8, runs the same
> on PPC and Intel.
>
> Tried running it on XP, and the result is the same (backwards text), but I
> also get these errors constantly:
>
> jit.gl.texture: setting compare func.: GL Error: Invalid enumeration
> jit.gl.texture: setting texture mode.: GL Error: Invalid enumeration
>
> So am I doing something wrong?
>
> I’m fairly desperate to find a quick answer to this due to an impending
> deadline. Any clues appreciated.
>
> Also, forgot to post the max patch to go along with the js, all it is is
> the javascript & a metro, but just in case here it is:
>
> max v2;
> #N vpatcher 766 178 1366 578;
> #P window setfont "Sans Serif" 9.;
> #P newex 15 54 57 196617 qmetro 20;
> #P toggle 15 35 14 0;
> #P newex 15 77 102 196617 js text3d.js;
> #P connect 1 0 2 0;
> #P connect 2 0 0 0;
> #P pop;
>
>


October 12, 2006 | 10:30 am

Well, the text doesn’t really display ‘correctly’ – it reads left-to-right, but the normals get all screwed up.

Another possibility is to draw the cylinder backwards:

myDestSketch.cylinder(0.25,0.25,0.25,360,0);

but then the normals on the cylinder get reversed.

It seems that any simple workaround to turn the text around messes up some other aspect of the rendering.

> i think its something to do with normals but im not sure, i got it
> displaying correctly by changing the scale to negative on the x
> myText.scale = [-0.1,0.3,0.1];


October 12, 2006 | 11:39 am

My latest brainstorm is to import .obj files to a jit.gl.model instead of using the jit.gl.sketch primitives – and it works! the text reads correctly!

So I think this qualifies as a bug between jit.gl.sketch’s primitives & captured textures.

Summary:
When using the capture attribute with a source jit.gl.sketch object (to map 3D geometry as a texture onto objects in a destination jit.gl.sketch), the captured texture is flipped (right-to-left).

Steps to Reproduce:
1. Create a jitl.gl.texture. Name it.
2. Draw some non-symmetrical objects or text in a jit.gl.sketch.
3. Set the capture attribute of the sketch object to the name of the texture.
4. Create another jit.gl.sketch object.
5. Bind the captured texture to a primitive cube, cylinder or sphere in the second jit.gl.sketch.

Expected Results:
Expected the captured texture to have the same orientation as the original scene.

Actual Results:
The captured texture is flipped right-to-left.

Regression:
Same results on PPC, Mactel and XP.

Notes:
Workaround: use a jit.gl.model (with automatic 0 and drawobject) instead – captured texture renders correctly.


Viewing 5 posts - 1 through 5 (of 5 total)