id Tech Forums

id Tech 4 (Doom3/Prey/Q4) => id Tech 4 Engine Coding => Topic started by: argoon on February 27, 2020, 06:01:30 PM

Title: How to create a simple quad (by code) inside the 3D world? for gameplay reasons.
Post by: argoon on February 27, 2020, 06:01:30 PM
Hello guys, for a very long time now, i've been trying to create a simple quad programatically in the engine, but I just don't know how that is done! I've browsed the source code for answers, but the geometry code I see is just to complicated for my feeble mind. I see stuff about windings and vertices but nothing direct.   

I tried looking at the gameRenderWorld debug code but again it looks way low level for me. Would someone be so kind to explain with code how to create a simple static quad in the 3D world in idtech4?

I know how to import a quad/model but what I really want is to create a quad dynamically by c++/opengl code.

Any help appreciated cheers.

Title: Re: How to create a simple quad (by code) inside the 3D world? for gameplay reasons.
Post by: argoon on March 12, 2020, 03:14:28 PM
If this community doesn't share knowledge it will never grow that's for sure.

So here is what I found on how to create a simple colored quad at run time. For now is not what I really wanted, what I want is to create a quad at run time that I can apply a material, but is a start.

So again if someone knows how to create a 3D quad that can have a material at run time and doesn't mind sharing said knowledge, please do so, I will appreciate it immensely. Thanks.

Simple colored quad (shows double sided)

Code: [Select]
idWinding w;
idVec3 vert[4];
int size = 20;
vert[0] = idVec3(0, 0, 0); // this is the world origin
vert[1] = idVec3(0, size, 0);
vert[2] = idVec3(0, size, size);
vert[3] = idVec3(0, 0, size);
gameRenderWorld->DebugPolygon(colorRed, w);


Title: Re: How to create a simple quad (by code) inside the 3D world? for gameplay reasons.
Post by: argoon on March 13, 2020, 09:01:39 PM
Player Icons/model sprite to the rescue!!!

Because I don't like multiplayer, I deleted many of the MP code, because of that I also deleted the player icon code, yes I know it was dumb, but I didn't knew better at the time...

So I remembered those icons and went to see on the original fhdoom source code how they were done, I saw they use the model sprite! so I decided to use the code to create sprites easely ingame. :)

Here is the main code that creates the sprites.  Will show the full code if asked or like me just see how the player icons were made.

Code: [Select]
idSprite::idSprite(c_string matName, const vec3 &origin, const mat3 &axis, f32 width, f32 hight) {


spriteEnt.origin = origin;
spriteEnt.axis = axis;
spriteEnt.shaderParms[SHADERPARM_RED] = 1.0f;
spriteEnt.shaderParms[SHADERPARM_GREEN] = 1.0f;
spriteEnt.shaderParms[SHADERPARM_BLUE] = 1.0f;
spriteEnt.shaderParms[SHADERPARM_ALPHA] = 1.0f;
spriteEnt.shaderParms[SHADERPARM_SPRITE_WIDTH] = width;
spriteEnt.shaderParms[SHADERPARM_SPRITE_HEIGHT] = hight;
spriteEnt.hModel = renderModelManager->FindModel("_sprite");
spriteEnt.callback = NULL;
spriteEnt.numJoints = 0;
spriteEnt.joints = NULL;
spriteEnt.customSkin = 0;
spriteEnt.noShadow = true;
spriteEnt.noSelfShadow = true;
spriteEnt.customShader = declManager->FindMaterial(matName);
spriteEnt.referenceShader = 0;
spriteEnt.bounds = spriteEnt.hModel->Bounds(&spriteEnt);

spriteHandle = gameRenderWorld->AddEntityDef(&spriteEnt);