Author Topic: How to create a simple quad (by code) inside the 3D world? for gameplay reasons.  (Read 737 times)

0 Members and 1 Guest are viewing this topic.

argoon

  • Sr. Member
  • ****
  • Posts: 279
  • Karma: +21/-81
  • Doom Newbie
    • View Profile
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.

 

argoon

  • Sr. Member
  • ****
  • Posts: 279
  • Karma: +21/-81
  • Doom Newbie
    • View Profile
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);
w.AddPoint(vert[0]);
w.AddPoint(vert[1]);
w.AddPoint(vert[2]);
w.AddPoint(vert[3]);
gameRenderWorld->DebugPolygon(colorRed, w);

 

 

argoon

  • Sr. Member
  • ****
  • Posts: 279
  • Karma: +21/-81
  • Doom Newbie
    • View Profile
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) {
FreeSprite();

ZeroStruct(spriteEnt);

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);
}