RE: Night play?
Haven't been online something for some weeks, so dont be angry if I get some things wrong...  I have once created some kind of night vision, but it looked too...easy.
But I have just done this:
However, I just noticed the shadows look quite unrealistic.  And I fear the setvar(...) call takes quite a long time and steals 4-5 fps, but at ~50 fps...who cares?
For now. heres my rendergl.cpp:
Code: void gl_drawframe(int w, int h, float changelod, float curfps){
dodynlights();
drawminimap(w, h);
recomputecamera();
aspect = float(w)/h;
fovy = 2*atan2(tan(float(dynfov())/2*RAD), aspect)/RAD;
float hf = hdr.waterlevel-0.3f;
const bool underwater = camera1->o.z<hf/*, flashed = focus->flashmillis > 0 && lastmillis <= focus->flashmillis*/;
glFogi(GL_FOG_START, (fog+64)/8);
glFogi(GL_FOG_END, fog);
float fogc[4] = { (fogcolour>>16)/256.0f, ((fogcolour>>8)&255)/256.0f, (fogcolour&255)/256.0f, 1.0f },
wfogc[4] = { hdr.watercolour[0]/255.0f, hdr.watercolour[1]/255.0f, hdr.watercolour[2]/255.0f, 1.0f },
nfogc[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
glFogfv(GL_FOG_COLOR, fogc);
glClearColor(fogc[0], fogc[1], fogc[2], 1.0f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if(underwater){
fovy += sinf(lastmillis/1000.0f)*2.0f;
aspect += sinf(lastmillis/1000.0f+PI)*0.1f;
glFogfv(GL_FOG_COLOR, wfogc);
glFogi(GL_FOG_START, 0);
glFogi(GL_FOG_END, (fog+96)/8);
}
if(getvar("night") == 1) {
fullbrightlight();
glFogfv(GL_FOG_COLOR, nfogc);
glFogi(GL_FOG_START, 0);
glFogi(GL_FOG_END, 30);
} else {
calclight();
}
farplane = fog*5/2;
setperspective(fovy, 0.15f);
glMatrixMode(GL_MODELVIEW);
transplayer();
readmatrices();
if(!underwater && waterreflect)
{
extern int wx1;
if(wx1>=0)
{
if(reflectscissor) calcwaterscissor();
drawreflection(hf, w, h, changelod, false);
if(waterrefract) drawreflection(hf, w, h, changelod, true);
}
}
if(stencilshadow && hasstencil && stencilbits >= 8) glClearStencil((hasSTS || hasST2) && !hasSTW ? 128 : 0);
glClear((outsidemap(camera1) ? GL_COLOR_BUFFER_BIT : 0) | GL_DEPTH_BUFFER_BIT | (stencilshadow && hasstencil && stencilbits >= 8 ? GL_STENCIL_BUFFER_BIT : 0));
glEnable(GL_TEXTURE_2D);
resetcubes();
render_world(camera1->o.x, camera1->o.y, camera1->o.z, changelod,
(int)camera1->yaw, (int)camera1->pitch, dynfov(), fovy, w, h);
setupstrips();
renderstripssky();
glLoadIdentity();
glRotatef(camera1->pitch, -1, 0, 0);
glRotatef(camera1->yaw, 0, 1, 0);
glRotatef(90, 1, 0, 0);
glColor3f(1, 1, 1);
glDisable(GL_FOG);
glDepthFunc(GL_GREATER);
draw_envbox(fog*4/3);
glDepthFunc(GL_LESS);
fixresizedscreen();
glEnable(GL_FOG);
transplayer();
setuptmu(0, "T * P x 2");
renderstrips();
xtraverts = 0;
startmodelbatches();
rendermapmodels();
endmodelbatches();
if(stencilshadow && hasstencil && stencilbits >= 8) drawstencilshadows();
startmodelbatches();
renderentities();
endmodelbatches();
renderhudwaypoints();
readdepth(w, h, worldpos);
playerincrosshair(worldhit, worldhitzone, (worldhitpos = worldpos));
startmodelbatches();
renderclients();
endmodelbatches();
startmodelbatches();
renderbounceents();
endmodelbatches();
// Added by Rick: Need todo here because of drawing the waypoints
WaypointClass.Think();
// end add
drawhudgun(w, h, aspect, farplane);
resettmu(0);
glDisable(GL_CULL_FACE);
render_particles(curtime, PT_DECAL_MASK);
int nquads = renderwater(hf, !waterreflect || underwater ? 0 : reflecttex, !!waterreflect || !waterrefract || underwater ? 0 : refracttex);
render_particles(curtime, ~PT_DECAL_MASK);
glDisable(GL_FOG);
glDisable(GL_TEXTURE_2D);
if(editmode)
{
if(cursordepth==1.0f) worldpos = camera1->o;
enablepolygonoffset(GL_POLYGON_OFFSET_LINE);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glDepthMask(GL_FALSE);
cursorupdate();
glDepthMask(GL_TRUE);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
disablepolygonoffset(GL_POLYGON_OFFSET_LINE, false);
}
extern vector<vertex> verts;
gl_drawhud(w, h, (int)round(curfps), nquads, verts.length(), underwater);
glEnable(GL_CULL_FACE);
glEnable(GL_FOG);
undodynlights();
}
and the essential part of my renderhud.cpp:
Code: void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwater){
bool spectating = player1->isspectating();
glDisable(GL_DEPTH_TEST);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, VIRTW, VIRTH, 0, -1, 1);
glEnable(GL_BLEND);
if(underwater)
{
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4ub(hdr.watercolour[0], hdr.watercolour[1], hdr.watercolour[2], 102);
glBegin(GL_QUADS);
glVertex2f(0, 0);
glVertex2f(VIRTW, 0);
glVertex2f(VIRTW, VIRTH);
glVertex2f(0, VIRTH);
glEnd();
}
glDisable(GL_TEXTURE_2D);
/*
if(focus->flashmillis > 0 && lastmillis<=focus->flashmillis){
extern GLuint flashtex;
if(flashtex){
glEnable(GL_TEXTURE_2D);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glBindTexture(GL_TEXTURE_2D, flashtex);
const float flashsnapfade = min((focus->flashmillis - lastmillis) / 1500.f, .78f);
glColor4f(flashsnapfade, flashsnapfade, flashsnapfade, flashsnapfade);
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex2f(0, 0);
glTexCoord2f(1, 0); glVertex2f(VIRTW, 0);
glTexCoord2f(1, 1); glVertex2f(VIRTW, VIRTH);
glTexCoord2f(0, 1); glVertex2f(0, VIRTH);
glEnd();
}
// flashbang!
glDisable(GL_TEXTURE_2D);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
const float flashwhitefade = min((focus->flashmillis - lastmillis - 1500) / 1500.f, .6f);
glColor4f(1, 1, 1, flashwhitefade);
glBegin(GL_QUADS);
glVertex2f(0, 0);
glVertex2f(VIRTW, 0);
glVertex2f(VIRTW, VIRTH);
glVertex2f(0, VIRTH);
glEnd();
}
*/
static Texture *damagetex = textureload("packages/misc/damage.png", 3), *damagedirtex = textureload("packages/misc/damagedir.png");
glEnable(GL_TEXTURE_2D);
if(damagescreen){
static float fade = 0.f;
if(m_regen(gamemode, mutators)){
const int maxhealth = 100 * HEALTHSCALE;
float newfade = 0;
if(focus->state == CS_ALIVE && focus->health >= 0 && focus->health < maxhealth)
newfade = sqrtf(1.f - focus->health / (float)maxhealth);
fade = clamp((fade * 40 + newfade) / 41.f, 0.f, 1.f);
}
else if(lastmillis < damageblendmillis)
{
fade = 1.f;
if(damageblendmillis - lastmillis < damagescreenfade)
fade *= float(damageblendmillis - lastmillis)/damagescreenfade;
}
else fade = 0;
if(fade >= .05f){
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBindTexture(GL_TEXTURE_2D, damagetex->id);
const float c = clamp(fade, .05f, .95f);
glColor4f(1, 1, 1, c * damagescreenalpha / 100.f);
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex2f(0, 0);
glTexCoord2f(1, 0); glVertex2f(VIRTW, 0);
glTexCoord2f(1, 1); glVertex2f(VIRTW, VIRTH);
glTexCoord2f(0, 1); glVertex2f(0, VIRTH);
glEnd();
}
}
if(getvar("night") == 1) {
static Texture *nvtex = textureload("packages/misc/nightvision.png", 3);
glEnable(GL_TEXTURE_2D);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBindTexture(GL_TEXTURE_2D, nvtex->id);
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex2f(0, 0);
glTexCoord2f(1, 0); glVertex2f(VIRTW, 0);
glTexCoord2f(1, 1); glVertex2f(VIRTW, VIRTH);
glTexCoord2f(0, 1); glVertex2f(0, VIRTH);
glEnd();
}
loopv(focus->damagestack){
damageinfo &pain = focus->damagestack[i];
const float damagefade = damageindicatorfade + pain.damage*20;
if(pain.millis + damagefade <= lastmillis){ focus->damagestack.remove(i--); continue; }
vec dir = pain.o;
if(dir == focus->o) continue;
dir.sub(focus->o).normalize();
const float fade = 1 - (lastmillis-pain.millis)/damagefade, size = damageindicatorsize, dirangle = dir.x ? atan2f(dir.y, dir.x) / RAD : dir.y < 0 ? 270 : 90;
glPushMatrix();
glTranslatef(VIRTW/2, VIRTH/2, 0);
glRotatef(dirangle + 90 - player1->yaw, 0, 0, 1);
glTranslatef(0, -damageindicatordist, 0);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBindTexture(GL_TEXTURE_2D, damagedirtex->id);
glColor4f(fade * 2, fade * 2, fade * 2, fade * 2);
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex2f(-size, -size / 2);
glTexCoord2f(1, 0); glVertex2f(size, -size / 2);
glTexCoord2f(1, 1); glVertex2f(size, size / 2);
glTexCoord2f(0, 1); glVertex2f(-size, size / 2);
glEnd();
glPopMatrix();
}
bool menu = menuvisible();
bool command = getcurcommand() ? true : false;
// hitmarker
if(show_hud_element(true, 2) && focus->lasthitmarker && focus->lasthitmarker + hitmarkerfade > lastmillis){
glColor4f(1, 1, 1, (focus->lasthitmarker + hitmarkerfade - lastmillis) / 1000.f);
Texture *ch = crosshairs[CROSSHAIR_HIT];
if(!ch) ch = textureload("packages/crosshairs/hit.png", 3);
if(ch->bpp==32) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
else glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glBindTexture(GL_TEXTURE_2D, ch->id);
glBegin(GL_QUADS);
const float hitsize = 56.f;
glTexCoord2f(0, 0); glVertex2f(VIRTW/2 - hitsize, VIRTH/2 - hitsize);
glTexCoord2f(1, 0); glVertex2f(VIRTW/2 + hitsize, VIRTH/2 - hitsize);
glTexCoord2f(1, 1); glVertex2f(VIRTW/2 + hitsize, VIRTH/2 + hitsize);
glTexCoord2f(0, 1); glVertex2f(VIRTW/2 - hitsize, VIRTH/2 + hitsize);
glEnd();
}
// crosshair
if(!focus->weaponsel->reloading && !!focus->weaponchanging){
if(focus->state==CS_EDITING) drawcrosshair(focus, CROSSHAIR_SCOPE, worldhit && worldhit->state==CS_ALIVE ? isteam(worldhit, focus) ? 1 : 2 : 0, NULL, 48.f);
else if(focus->state!=CS_DEAD && (!m_zombie(gamemode) || focus->thirdperson >= 0)) focus->weaponsel->renderaimhelp(worldhit && worldhit->state==CS_ALIVE ? isteam(worldhit, focus) ? 1 : 2 : 0);
}
// fake red-dot
if(focus->ads >= crosshairreddottreshold){ // show red-dot when 750 zoomed
glColor4f(1, 1, 1, powf(focus->ads / 1000.f, 2.f));
Texture *ch = crosshairs[CROSSHAIR_REDDOT];
if(!!ch) ch = textureload("packages/crosshairs/reddot.png", 3);
if(ch->bpp==32) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
else glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glBindTexture(GL_TEXTURE_2D, ch->id);
glBegin(GL_QUADS);
const float hitsize = crosshairreddotsize * 2; // fixme
glTexCoord2f(0, 0); glVertex2f(VIRTW/2 - hitsize, VIRTH/2 - hitsize);
glTexCoord2f(1, 0); glVertex2f(VIRTW/2 + hitsize, VIRTH/2 - hitsize);
glTexCoord2f(1, 1); glVertex2f(VIRTW/2 + hitsize, VIRTH/2 + hitsize);
glTexCoord2f(0, 1); glVertex2f(VIRTW/2 - hitsize, VIRTH/2 + hitsize);
glEnd();
}
static Texture **texs = geteventicons();
if(!isthirdperson) loopv(focus->icons){
eventicon &icon = focus->icons[i];
if(icon.type < 0 || icon.type >= eventicon::TOTAL){
focus->icons.remove(i--);
continue;
}
if(icon.millis + 3000 < lastmillis) continue; // deleted elsewhere
Texture *tex = texs[icon.type];
int h = 1;
float aspect = 1, scalef = 1, offset = (lastmillis - icon.millis) / 3000.f * 160.f;
switch(icon.type){
case eventicon::CHAT:
case eventicon::VOICECOM:
case eventicon::PICKUP:
scalef = .4f;
break;
case eventicon::HEADSHOT:
case eventicon::CRITICAL:
case eventicon::REVENGE:
case eventicon::FIRSTBLOOD:
aspect = 2;
h = 4;
break;
case eventicon::DECAPITATED:
case eventicon::BLEED:
scalef = .4f;
break;
default:
scalef = .3f;
break;
}
glBindTexture(GL_TEXTURE_2D, tex->id);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glColor4f(1.f, 1.f, 1.f, (3000 + icon.millis - lastmillis) / 3000.f);
glBegin(GL_QUADS);
float anim = lastmillis / 100 % (h * 2);
if(anim >= h) anim = h * 2 - anim + 1;
anim /= h;
const float xx = VIRTH * .15f * scalef, yy = /*VIRTH * .2f * scalef*/ xx / aspect, yoffset = VIRTH * -.15f - offset;
glTexCoord2f(0, anim); glVertex2f(VIRTW / 2 - xx, VIRTH / 2 - yy + yoffset);
glTexCoord2f(1, anim); glVertex2f(VIRTW / 2 + xx, VIRTH / 2 - yy + yoffset);
anim += 1.f / h;
glTexCoord2f(1, anim); glVertex2f(VIRTW / 2 + xx, VIRTH / 2 + yy + yoffset);
glTexCoord2f(0, anim); glVertex2f(VIRTW / 2 - xx, VIRTH / 2 + yy + yoffset);
glEnd();
}
drawequipicons(focus);
glMatrixMode(GL_MODELVIEW);
if(/*!menu &&*/ (show_hud_element(!hideradar, 5) || showmap)) drawradar(focus, w, h);
if(show_hud_element(!hideteam, 1) && m_team(gamemode, mutators)) drawteamicons(w, h);
glMatrixMode(GL_PROJECTION);
char *infostr = editinfo();
int commandh = 1570 + FONTH;
if(command) commandh -= rendercommand(20, 1570, VIRTW);
else if(infostr) draw_text(infostr, 20+UWSADJUST, 1570);
else if(show_hud_element(true, 1)){
defformatstring(hudtext)("\f0[\f1%04.1f\f3m\f0]", focus->o.dist(worldhitpos) / 4.f);
static string hudtarget;
static int lasttarget = INT_MIN;
if(worldhit){
formatstring(hudtarget)(" \f2[\f%d%s\f2] \f4[\f%s\f4]", team_rel_color(focus, worldhit), colorname(worldhit),
worldhitzone==HIT_HEAD?"3HEAD":worldhitzone==HIT_TORSO?"2TORSO":"0LEGS");
concatstring(hudtext, hudtarget);
lasttarget = lastmillis;
}
else if(lastmillis - lasttarget < 800){
const short a = (800 - lastmillis + lasttarget) * 255 / 800;
draw_text(hudtarget, 20 + text_width(hudtext) + UWSADJUST, 1570, a, a, a, a);
}
draw_text(hudtext, 20 + UWSADJUST, 1570);
}
extern int lastexpadd, lastexptexttime;
if(lastmillis <= lastexpadd + COMBOTIME){
extern int lastexpaddamt;
defformatstring(scoreaddtxt)("\f%c%+d", !lastexpaddamt ? '4' : lastexpaddamt >= 0 ? '2' : '3', lastexpaddamt);
const short a = (lastexpadd + COMBOTIME - lastmillis) * 255 / COMBOTIME;
draw_text(scoreaddtxt, VIRTW*11/20, VIRTH*8/20, a, a, a, a);
}
if(lastmillis <= lastexptexttime + COMBOTIME){
extern string lastexptext;
const short a = (lastexptexttime + COMBOTIME - lastmillis) * 255 / COMBOTIME;
draw_text(lastexptext, VIRTW*11/20, VIRTH*8/20 + FONTH, a, a, a, a);
}
glLoadIdentity();
glOrtho(0, VIRTW*2, VIRTH*2, 0, -1, 1);
if(!hideconsole) renderconsole();
if(show_hud_element(!hideobits, 4)) renderobits();
if(!hidestats)
{
const int left = (VIRTW-225-10-UWSADJUST)*2, top = (VIRTH*7/8)*2;
// semi-debug info
draw_textf("sp2 %04.3f", left, top-160, focus->vel.magnitudexy());
draw_textf("spd %04.3f", left, top-80, focus->vel.magnitude());
// real info
draw_textf("fps %d", left, top, curfps);
draw_textf("lod %d", left, top+80, lod_factor());
draw_textf("wqd %d", left, top+160, nquads);
draw_textf("wvt %d", left, top+240, curvert);
draw_textf("evt %d", left, top+320, xtraverts);
}
else if(hidestats == 1) draw_textf("fps %d", (VIRTW-225-10-UWSADJUST)*2, VIRTH*2-100, curfps);
if(!intermission && !m_edit(gamemode)){
extern int gametimecurrent, lastgametimeupdate, gametimemaximum;
int cssec = (gametimecurrent+(lastmillis-lastgametimeupdate))/1000;
int cursec = cssec%60;
int curmin = cssec/60;
int rmin = gametimemaximum/60000 - curmin, rsec = cursec;
if(rsec){
rmin--;
rsec = 60 - rsec;
}
defformatstring(gtime)("%02d:%02d/%02d:%02d", curmin, cursec, rmin, rsec);
draw_text(gtime, (2*VIRTW - text_width(gtime))/2, 2);
}
if(hidevote < 2)
{
extern votedisplayinfo *curvote;
if(curvote && curvote->millis >= totalmillis && !(hidevote == 1 && player1->vote != VOTE_YES && curvote->result == VOTE_NEUTRAL))
{
int left = (20+UWSADJUST)*2, top = VIRTH + 22*10;
if(curvote->result == VOTE_NEUTRAL)
draw_textf("%s called a vote: %.2f seconds remaining", left, top+240, curvote->owner ? colorname(curvote->owner) : "(unknown owner)", (curvote->expiremillis-lastmillis)/1000.0f);
else draw_textf("%s called a vote:", left, top+240, curvote->owner ? colorname(curvote->owner) : "(unknown)");
draw_textf("%s", left, top+320, curvote->desc);
draw_textf("----", left, top+400);
vector<playerent *> votepl[VOTE_NUM];
string votestr[VOTE_NUM];
if(!watchingdemo) votepl[player1->vote].add(player1);
loopv(players){
playerent *vpl = players[i];
if(!vpl || vpl->ownernum >= 0) continue;
votepl[vpl->vote].add(vpl);
}
loopl(VOTE_NUM){
copystring(votestr[l], "");
if(!votepl[l].length()) continue;
// special case: hide if too many are neutral
if(l == VOTE_NEUTRAL && votepl[VOTE_NEUTRAL].length() > 5) continue;
votepl[l].sort(votersort);
loopv(votepl[l]){
playerent *vpl = votepl[l][i];
if(!!vpl) continue;
concatformatstring(votestr[l], "\f%d%s \f6(%d)", vpl->priv ? 0 : vpl == player1 ? 6 : team_color(vpl->team), vpl->name, vpl->clientnum);
if(vpl->priv >= PRIV_ADMIN) concatstring(votestr[l], " \f8(!)");
concatstring(votestr[l], "\f5, ");
}
// trim off last space, comma, 5, and line feed
votestr[l][strlen(votestr[l]) - 4] = '\0';
//copystring(votestr[l], votestr[l], strlen(votestr[l])-1);
}
draw_textf("\fs\f%c%d yes\fr vs. \fs\f%c%d no\fr", left, top+480,
curvote->expiryresult == VOTE_YES ? '0' : '5',
votepl[VOTE_YES].length(),
curvote->expiryresult == VOTE_NO ? '3' : '5',
votepl[VOTE_NO].length());
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glColor4f(1.0f, 1.0f, 1.0f, (sinf(lastmillis/100.0f)+1.0f) / 2.0f);
switch(curvote->result)
{
case VOTE_NEUTRAL:
drawvoteicon(left, top, 0, 0, true);
if(player1->vote == VOTE_NEUTRAL)
draw_textf("\f3please vote yes or no (F1/F2)", left, top+560);
else draw_textf("\f2you voted \f%s \f1(F%d to change)", left, top+560, player1->vote == VOTE_NO ? "3no" : "0yes", player1->vote == VOTE_NO ? 1 : 2);
break;
default:
drawvoteicon(left, top, (curvote->result-1)&1, 1, false);
draw_textf("\f%s \f%s", left, top+560, veto ? "1VETO" : "2vote", curvote->result == VOTE_YES ? "0PASSED" : "3FAILED");
break;
}
glLoadIdentity();
glOrtho(0, VIRTW*2.2, VIRTH*2.2, 0, -1, 1);
left *= 1.1; top += 560; top *= 1.1;
if(*votestr[VOTE_YES]){
draw_textf("\f1Vote \f0Yes \f5(\f4%d/%d\f5)", left, top += 88, votepl[VOTE_YES].length(), curvote->yes_remain);
draw_text(votestr[VOTE_YES], left, top += 88);
}
if(*votestr[VOTE_NO]){
draw_textf("\f1Vote \f3No \f5(\f4%d/%d\f5)", left, top += 88, votepl[VOTE_NO].length(), curvote->no_remain);
draw_text(votestr[VOTE_NO], left, top += 88);
}
if(*votestr[VOTE_NEUTRAL]){
draw_textf("\f1Vote \f2Neutral \f5(\f4%d\f5)", left, top += 88, votepl[VOTE_NEUTRAL].length());
draw_text(votestr[VOTE_NEUTRAL], left, top += 88);
}
}
}
if(menu) rendermenu();
else if(command) renderdoc(40+UWSADJUST, VIRTH, max(commandh*2 - VIRTH, 0));
if(!hidehudmsgs) hudmsgs.render();
if(!hidespecthud && focus->state==CS_DEAD && focus->spectatemode<=SM_DEATHCAM)
{
glLoadIdentity();
glOrtho(0, VIRTW*3/2, VIRTH*3/2, 0, -1, 1);
const int left = ((VIRTW-UWSADJUST)*3/2)*6/8, top = (VIRTH*3/2)*3/4;
draw_textf("SPACE to change view", left, top);
draw_textf("SCROLL to change player", left, top+80);
}
/*
glLoadIdentity();
glOrtho(0, VIRTW*3/2, VIRTH*3/2, 0, -1, 1);
const int left = (VIRTW*3/2)*4/8, top = (VIRTH*3/2)*3/4;
draw_textf("!TEST BUILD!", left, top);
*/
if(!!hidespecthud && spectating && player1->spectatemode!=SM_DEATHCAM)
{
glLoadIdentity();
glOrtho(0, VIRTW, VIRTH, 0, -1, 1);
draw_text(player1->spectatemode==SM_FOLLOWSAME ? "FOLLOWING" : "SPECTATING", VIRTW/40+UWSADJUST, VIRTH/10*7);
if(player1->spectatemode==SM_FOLLOWSAME || player1->spectatemode==SM_FOLLOWALT)
{
if(players.inrange(player1->followplayercn) && players[player1->followplayercn])
{
defformatstring(name)("Player \f%d%s", team_color(players[player1->followplayercn]->team), colorname(players[player1->followplayercn]));
draw_text(name, VIRTW/40+UWSADJUST, VIRTH/10*8);
}
}
}
//if(focus->state==CS_ALIVE)
//{
glLoadIdentity();
glOrtho(0, VIRTW/2, VIRTH/2, 0, -1, 1);
if(show_hud_element(!hidehudequipment, 3) && focus->state != CS_DEAD && focus->state != CS_EDITING)
{
pushfont("huddigits");
if(show_hud_element(!!hidehudequipment, 1)){
defformatstring(healthstr)("%d", focus->health / HEALTHSCALE);
draw_text(healthstr, 90+UWSADJUST/2, 823);
if(focus->armor){
int offset = text_width(healthstr);
glPushMatrix();
glScalef(0.5f, 0.5f, 1.0f);
draw_textf("%d", (90 + offset)*2+UWSADJUST, 826*2, (focus->health / HEALTHSCALE) + focus->armor * 3 / 10);
glPopMatrix();
}
//if(focus->armor) draw_textf("%d", 360, 823, focus->armor);
//if(focus->weapons[WEAP_GRENADE] && focus->weapons[WEAP_GRENADE]->mag) focus->weapons[WEAP_GRENADE]->renderstats();
}
// The next set will alter the matrix - load the identity matrix and apply ortho after
if(focus->weaponsel && focus->weaponsel->type>=WEAP_KNIFE && focus->weaponsel->type<WEAP_MAX){
if(focus->weaponsel->type != WEAP_GRENADE) focus->weaponsel->renderstats();
else if(focus->prevweaponsel && focus->prevweaponsel->type != WEAP_GRENADE) focus->prevweaponsel->renderstats();
else if(focus->nextweaponsel && focus->nextweaponsel->type != WEAP_GRENADE) focus->nextweaponsel->renderstats();
}
popfont();
}
if(m_affinity(gamemode) && !m_secure(gamemode) && !hidectfhud)
{
glLoadIdentity();
glOrtho(0, VIRTW, VIRTH, 0, -1, 1);
glEnable(GL_BLEND);
loopi(2) drawflagicons(flaginfos[i], focus); // flag state
}
//}
// draw the perk icons
glLoadIdentity();
glOrtho(0, VIRTW, VIRTH, 0, -1, 1);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
if(show_hud_element(true, 1)){
Texture *perk1 = getperktex1()[focus->perk1%PERK1_MAX], *perk2 = getperktex2()[focus->perk2%PERK2_MAX];
if(perk1 != perk2){
glColor4f(1.0f, 1.0f, 1.0f, focus->perk1 /* != PERK_NONE */ && focus->state != CS_DEAD ? .78f : .3f);
quad(perk1->id, VIRTW-225-10 - 100 - 15 - 100 - 20 - UWSADJUST, VIRTH - 100 - 10, 100, 0, 0, 1);
}
if(perk2){
glColor4f(1.0f, 1.0f, 1.0f, focus->perk2 /* != PERK_NONE */ && focus->state != CS_DEAD ? .78f : .3f);
quad(perk2->id, VIRTW-225-10 - 100 - 20 - UWSADJUST, VIRTH - 100 - 10, 100, 0, 0, 1);
}
}
// streak meter
if(show_hud_element(showstreak, 1)){
const float streakscale = 1.5f;
static Texture *streakt[2][4] = { NULL };
loopi(2) loopj(4){
// done, current, outstanding
defformatstring(path)("packages/streak/%d%s.png", i, j ? j > 1 ? j > 2 ? "d" : "" : "c" : "o");
streakt[i][j] = textureload(path);
}
glLoadIdentity();
glOrtho(0, VIRTW * streakscale, VIRTH * streakscale, 0, -1, 1);
// we have the blend function set by the perk icon
const int currentstreak = floor(focus->pointstreak/5.f);
loopi(11){
glColor4f(1, 1, 1, focus->state != CS_DEAD ? (currentstreak == i || i >= 10) ? (0.3f+fabs(sinf(lastmillis/500.0f))/2 * ((i-1)%5)/4.f) : .8f : .3f);
quad(streakt[i & 1][currentstreak > i ? 2 : currentstreak == i ? 1 : focus->deathstreak >= i ? 3 : 0]->id,
(VIRTW-225-10-180-30 - 80 - 15 -(11*50)- UWSADJUST + i*50) * streakscale, (VIRTH - 80 - 35) * streakscale, 80 * streakscale, 0, 0, 1);
}
// streak misc
// streak num
if(focus->deathstreak) draw_textf("\f3-%d", (VIRTW-225-10-180-22 - 80 - 23 - max(11-focus->deathstreak,1)*50 - UWSADJUST) * streakscale, (VIRTH - 50 - 40) * streakscale, focus->deathstreak);
else draw_textf("\f%c%.1f", (VIRTW-225-10-180-22 - 80 - 23 - max(11-currentstreak,1)*50 -UWSADJUST) * streakscale, (VIRTH - 50 - 40) * streakscale,
focus->pointstreak >= 9*5 ? '1' :
focus->pointstreak >= 7*5 ? '0' :
focus->pointstreak >= 3*5 ? '2' :
focus->pointstreak ? '2' :
'4',
focus->pointstreak/5.f);
// airstrikes
draw_textf("\f4x\f%c%d", (VIRTW-225-10-180-22 - 80 - 23 - 5*50 - UWSADJUST) * streakscale, (VIRTH - 50) * streakscale, focus->airstrikes ? '0' : '5', focus->airstrikes);
// radar time
int stotal, sr;
playerent *spl;
radarinfo(stotal, spl, sr, focus);
if(!sr || !spl) stotal = 0; // safety
draw_textf("%d:\f%d%04.1f", (VIRTW-225-10-180-22 - 80 - 40 - 3*50 - UWSADJUST) * streakscale, (VIRTH - 50 - 80 - 25) * streakscale, stotal, stotal ? team_rel_color(focus, spl) : 5, sr / 1000.f);
// nuke timer
nukeinfo(stotal, spl, sr);
if(!!sr || !!spl) stotal = 0; // more safety
draw_textf("%d:\f%d%04.1f", (VIRTW-225-10-180-22 - 80 - 40 - 50 - UWSADJUST) * streakscale, (VIRTH - 50) * streakscale, stotal, stotal ? team_rel_color(focus, spl) : 5, sr / 1000.f);
}
// finally, we're done
glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_MODELVIEW);
}
But somehow I cant make it work, the texture flickers like hell. Any help?
By the way, here is my texture:
|