[DSG] Attention Code Monkeys

Posted by DSG on Feb. 6, 2011, 2:33 a.m.

so, map design was a problem for a while, but I'm almost finished with 3 worlds

rooms are way more 3D so I thought, shit. I should just use textures.

So, i tried this

draw_primitive_begin_texture(pr_trianglestrip,sprite_get_texture(SPtexture,0))
draw_vertex_texture(x+60,y,1,0)
draw_vertex_texture(x+70,y+50,1,1)
draw_vertex_texture(x,y+40,0,0)
draw_primitive_end()

rtfm? i did. It just shows up black.

So uhm. Yea, all I have to share right now.

I've been making slow rocky progress with the implementation of 3D effects, don't know why I didn't try primitives earlier.

Ive done it before too. idfkwuwts.

this appears closer, but sgtill not working. if you run this in game maker, and make the texture sprite a 32x32 box with a target shape in the middle or a large X in the middle so you can tell why this looks wrong

draw_primitive_begin_texture(pr_trianglestrip,sprite_get_texture(SPtexture,0))
draw_set_color(c_white)
draw_vertex_texture(x,y,0,0)
draw_vertex_texture(x,y+20,0,1)
draw_vertex_texture(x+30,y+30,1,1)
draw_vertex_texture(x+30,y-10,1,0)
draw_vertex_texture(x,y,0,0)
draw_primitive_end()

Comments

DFortun81 13 years, 9 months ago

Hmm. Works just fine for me… I'd check to make sure that the sprite_get_texture is actually returning a positive id. Running your game in Debug Mode and then putting sprite_get_texture(SPtexture,0) in one of the debug lines will do the trick. This may also be caused by your draw mode, so try setting it back to normal prior to drawing. Who knows?

DFortun81 13 years, 9 months ago

Actually, you're right. It's drawing the texture as pure black. (Originally I just drew black squiggles.)

DFortun81 13 years, 9 months ago

draw_vertex_texture_color(x+60,y,1,0, c_white, 1)
draw_vertex_texture_color(x+70,y+50,1,1, c_white, 1)
draw_vertex_texture_color(x,y+40,0,0, c_white, 1)

This made it work for me. Try this!

Cesque 13 years, 9 months ago

At least with 3d primitives, you only need to specify the texture at the beginning, so maybe you should just replace draw_vertex_texture with draw_vertex?

DSG 13 years, 9 months ago

Well, basically i'm trying to fake a 3D wall, i want to draw a square sprite with perspective. (the 4 corners of each image/wall will have to be capable of moving with the view like looking inside a 3D box. a wall to the left, right, top, and bottom and look 3D with perspective.)

DSG 13 years, 9 months ago

@DFortun81: Not exactly creating the effect. It'll make triangles but i want a SQUARE. and I assume i have to figure out how to make it out of triangles? because the triangles don't seem to work correctly. the texture bends in a parallelogram manor, not how it should like perspective.

@Cesque: Nope, just comes out black. I think it has to be draw_vertex_texture

Cesque 13 years, 9 months ago

Quote:
@Cesque: Nope, just comes out black. I think it has to be draw_vertex_texture

Err… I thought you were getting black with draw_vertex_texture too? (the way I saw it, the texture is defined in the primitive already)

sirxemic 13 years, 9 months ago

Basically, when you want to draw something in the proper color, do draw_set_color(c_white) first.

Second of all, draw_vertex_texture is crucial for textured primitives.

Third of all, you cannot fake 3D textures by using 2D primitives. You can approximate the appearance, but not create a correctly 3D looking wall.

Fourth of all, the last piece of code has one redundant line, namely the last one. Either you don't know how pr_trianglestrip works or it was just something you overlooked.

Last but not last least, you should call sprite_get_texture only once, like in create event. It would speed up your program with a tiny bit.

Alert Games 13 years, 9 months ago

I think use DF81's _color() advice with c_white and 1 alpha,

and sirXemic's advice about the create event but im pretty sure that the triangle strip use is correct…

But will help you with many programming dilimea's is to go step by step. I would do a show_message() of the sprite_get_texture() just to be sure, unless DF81's advice works right away.

sirxemic 13 years, 9 months ago

Quote:
but im pretty sure that the triangle strip use is correct…
It is. But it is done the dumb way. In fact, I was wrong on what i said

Left is what happens, right is what DSG probably wants to happen:

Left:

first triangle 1 (yellow) is drawn, then triangle 2 (green) and finally triangle 3 (blue).