void draw_image_info(ARegion *ar, int color_manage, int channels, int x, int y, char *cp, float *fp, int *zp, float *zpf) { char str[256]; float dx= 6; /* text colors */ /* XXX colored text not allowed in Blender UI */ #if 0 unsigned char red[3] = {255, 50, 50}; unsigned char green[3] = {0, 255, 0}; unsigned char blue[3] = {100, 100, 255}; #else unsigned char red[3] = {255, 255, 255}; unsigned char green[3] = {255, 255, 255}; unsigned char blue[3] = {255, 255, 255}; #endif float hue=0, sat=0, val=0, lum=0, u=0, v=0; float col[4], finalcol[4]; glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); /* noisy, high contrast make impossible to read if lower alpha is used. */ glColor4ub(0, 0, 0, 190); glRecti(0.0, 0.0, ar->winrct.xmax - ar->winrct.xmin + 1, 20); glDisable(GL_BLEND); BLF_size(blf_mono_font, 11, 72); glColor3ub(255, 255, 255); sprintf(str, "X:%-4d Y:%-4d |", x, y); // UI_DrawString(6, 6, str); // works ok but fixed width is nicer. BLF_position(blf_mono_font, dx, 6, 0); BLF_draw_ascii(blf_mono_font, str, sizeof(str)); dx += BLF_width(blf_mono_font, str); if(zp) { glColor3ub(255, 255, 255); sprintf(str, " Z:%-.4f |", 0.5f+0.5f*(((float)*zp)/(float)0x7fffffff)); BLF_position(blf_mono_font, dx, 6, 0); BLF_draw_ascii(blf_mono_font, str, sizeof(str)); dx += BLF_width(blf_mono_font, str); } if(zpf) { glColor3ub(255, 255, 255); sprintf(str, " Z:%-.3f |", *zpf); BLF_position(blf_mono_font, dx, 6, 0); BLF_draw_ascii(blf_mono_font, str, sizeof(str)); dx += BLF_width(blf_mono_font, str); } if(channels >= 3) { glColor3ubv(red); if (fp) sprintf(str, " R:%-.4f", fp[0]); else if (cp) sprintf(str, " R:%-3d", cp[0]); else sprintf(str, " R:-"); BLF_position(blf_mono_font, dx, 6, 0); BLF_draw_ascii(blf_mono_font, str, sizeof(str)); dx += BLF_width(blf_mono_font, str); glColor3ubv(green); if (fp) sprintf(str, " G:%-.4f", fp[1]); else if (cp) sprintf(str, " G:%-3d", cp[1]); else sprintf(str, " G:-"); BLF_position(blf_mono_font, dx, 6, 0); BLF_draw_ascii(blf_mono_font, str, sizeof(str)); dx += BLF_width(blf_mono_font, str); glColor3ubv(blue); if (fp) sprintf(str, " B:%-.4f", fp[2]); else if (cp) sprintf(str, " B:%-3d", cp[2]); else sprintf(str, " B:-"); BLF_position(blf_mono_font, dx, 6, 0); BLF_draw_ascii(blf_mono_font, str, sizeof(str)); dx += BLF_width(blf_mono_font, str); if(channels == 4) { glColor3ub(255, 255, 255); if (fp) sprintf(str, " A:%-.4f", fp[3]); else if (cp) sprintf(str, " A:%-3d", cp[3]); else sprintf(str, "- "); BLF_position(blf_mono_font, dx, 6, 0); BLF_draw_ascii(blf_mono_font, str, sizeof(str)); dx += BLF_width(blf_mono_font, str); } } /* color rectangle */ if (channels==1) { if (fp) col[0] = col[1] = col[2] = fp[0]; else if (cp) col[0] = col[1] = col[2] = (float)cp[0]/255.0f; else col[0] = col[1] = col[2] = 0.0f; } else if (channels==3) { if (fp) copy_v3_v3(col, fp); else if (cp) { col[0] = (float)cp[0]/255.0f; col[1] = (float)cp[1]/255.0f; col[2] = (float)cp[2]/255.0f; } else zero_v3(col); } else if (channels==4) { if (fp) copy_v4_v4(col, fp); else if (cp) { col[0] = (float)cp[0]/255.0f; col[1] = (float)cp[1]/255.0f; col[2] = (float)cp[2]/255.0f; col[3] = (float)cp[3]/255.0f; } else zero_v4(col); } if (color_manage) { linearrgb_to_srgb_v3_v3(finalcol, col); finalcol[3] = col[3]; } else { copy_v4_v4(finalcol, col); } glDisable(GL_BLEND); glColor3fv(finalcol); dx += 5; glBegin(GL_QUADS); glVertex2f(dx, 3); glVertex2f(dx, 17); glVertex2f(dx+30, 17); glVertex2f(dx+30, 3); glEnd(); dx += 35; glColor3ub(255, 255, 255); if(channels == 1) { if (fp) { rgb_to_hsv(fp[0], fp[0], fp[0], &hue, &sat, &val); rgb_to_yuv(fp[0], fp[0], fp[0], &lum, &u, &v); } else if (cp) { rgb_to_hsv((float)cp[0]/255.0f, (float)cp[0]/255.0f, (float)cp[0]/255.0f, &hue, &sat, &val); rgb_to_yuv((float)cp[0]/255.0f, (float)cp[0]/255.0f, (float)cp[0]/255.0f, &lum, &u, &v); } sprintf(str, "V:%-.4f", val); BLF_position(blf_mono_font, dx, 6, 0); BLF_draw_ascii(blf_mono_font, str, sizeof(str)); dx += BLF_width(blf_mono_font, str); sprintf(str, " L:%-.4f", lum); BLF_position(blf_mono_font, dx, 6, 0); BLF_draw_ascii(blf_mono_font, str, sizeof(str)); dx += BLF_width(blf_mono_font, str); } else if(channels >= 3) { if (fp) { rgb_to_hsv(fp[0], fp[1], fp[2], &hue, &sat, &val); rgb_to_yuv(fp[0], fp[1], fp[2], &lum, &u, &v); } else if (cp) { rgb_to_hsv((float)cp[0]/255.0f, (float)cp[1]/255.0f, (float)cp[2]/255.0f, &hue, &sat, &val); rgb_to_yuv((float)cp[0]/255.0f, (float)cp[1]/255.0f, (float)cp[2]/255.0f, &lum, &u, &v); } sprintf(str, "H:%-.4f", hue); BLF_position(blf_mono_font, dx, 6, 0); BLF_draw_ascii(blf_mono_font, str, sizeof(str)); dx += BLF_width(blf_mono_font, str); sprintf(str, " S:%-.4f", sat); BLF_position(blf_mono_font, dx, 6, 0); BLF_draw_ascii(blf_mono_font, str, sizeof(str)); dx += BLF_width(blf_mono_font, str); sprintf(str, " V:%-.4f", val); BLF_position(blf_mono_font, dx, 6, 0); BLF_draw_ascii(blf_mono_font, str, sizeof(str)); dx += BLF_width(blf_mono_font, str); sprintf(str, " L:%-.4f", lum); BLF_position(blf_mono_font, dx, 6, 0); BLF_draw_ascii(blf_mono_font, str, sizeof(str)); dx += BLF_width(blf_mono_font, str); } (void)dx; }
/* Draw a sequence strip, bounds check already made ARegion is currently only used to get the windows width in pixels so wave file sample drawing precision is zoom adjusted */ static void draw_seq_strip(Scene *scene, ARegion *ar, Sequence *seq, int outline_tint, float pixelx) { View2D *v2d= &ar->v2d; float x1, x2, y1, y2; unsigned char col[3], background_col[3], is_single_image; /* we need to know if this is a single image/color or not for drawing */ is_single_image = (char)seq_single_check(seq); /* body */ if(seq->startstill) x1= seq->start; else x1= seq->startdisp; y1= seq->machine+SEQ_STRIP_OFSBOTTOM; if(seq->endstill) x2= seq->start+seq->len; else x2= seq->enddisp; y2= seq->machine+SEQ_STRIP_OFSTOP; /* get the correct color per strip type*/ //get_seq_color3ubv(scene, seq, col); get_seq_color3ubv(scene, seq, background_col); /* draw the main strip body */ if (is_single_image) /* single image */ draw_shadedstrip(seq, background_col, seq_tx_get_final_left(seq, 0), y1, seq_tx_get_final_right(seq, 0), y2); else /* normal operation */ draw_shadedstrip(seq, background_col, x1, y1, x2, y2); /* draw additional info and controls */ if (!is_single_image) draw_seq_extensions(scene, ar, seq); draw_seq_handle(v2d, seq, pixelx, SEQ_LEFTHANDLE); draw_seq_handle(v2d, seq, pixelx, SEQ_RIGHTHANDLE); /* draw the strip outline */ x1= seq->startdisp; x2= seq->enddisp; /* draw sound wave */ if(seq->type == SEQ_SOUND) drawseqwave(scene, seq, x1, y1, x2, y2, (ar->v2d.cur.xmax - ar->v2d.cur.xmin)/ar->winx); /* draw lock */ if(seq->flag & SEQ_LOCK) { glEnable(GL_POLYGON_STIPPLE); glEnable(GL_BLEND); /* light stripes */ glColor4ub(255, 255, 255, 32); glPolygonStipple(stipple_diag_stripes_pos); glRectf(x1, y1, x2, y2); /* dark stripes */ glColor4ub(0, 0, 0, 32); glPolygonStipple(stipple_diag_stripes_neg); glRectf(x1, y1, x2, y2); glDisable(GL_POLYGON_STIPPLE); glDisable(GL_BLEND); } get_seq_color3ubv(scene, seq, col); if (G.moving && (seq->flag & SELECT)) { if(seq->flag & SEQ_OVERLAP) { col[0]= 255; col[1]= col[2]= 40; } else UI_GetColorPtrShade3ubv(col, col, 120+outline_tint); } else UI_GetColorPtrShade3ubv(col, col, outline_tint); glColor3ubv((GLubyte *)col); if (seq->flag & SEQ_MUTE) { glEnable(GL_LINE_STIPPLE); glLineStipple(1, 0x8888); } uiDrawBoxShade(GL_LINE_LOOP, x1, y1, x2, y2, 0.0, 0.1, 0.0); if (seq->flag & SEQ_MUTE) { glDisable(GL_LINE_STIPPLE); } if(seq->type==SEQ_META) drawmeta_contents(scene, seq, x1, y1, x2, y2); /* calculate if seq is long enough to print a name */ x1= seq->startdisp+seq->handsize; x2= seq->enddisp-seq->handsize; /* info text on the strip */ if(x1<v2d->cur.xmin) x1= v2d->cur.xmin; else if(x1>v2d->cur.xmax) x1= v2d->cur.xmax; if(x2<v2d->cur.xmin) x2= v2d->cur.xmin; else if(x2>v2d->cur.xmax) x2= v2d->cur.xmax; /* nice text here would require changing the view matrix for texture text */ if( (x2-x1) / pixelx > 32) { draw_seq_text(v2d, seq, x1, x2, y1, y2, background_col); } }
// color void MGLContext::setColor(const MColor & color){ glColor4ub(color.r, color.g, color.b, color.a); }
void GLWidget::draw() { QPainter p(this); // used for text overlay // save the GL state set for QPainter p.beginNativePainting(); saveGLState(); // render the 'bubbles.svg' file into our pbuffer QPainter pbuffer_painter(pbuffer); svg_renderer->render(&pbuffer_painter); pbuffer_painter.end(); glFlush(); if (!hasDynamicTextureUpdate) pbuffer->updateDynamicTexture(dynamicTexture); makeCurrent(); // draw into the GL widget glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-1, 1, -1, 1, 10, 100); glTranslatef(0.0f, 0.0f, -15.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glViewport(0, 0, width() * devicePixelRatio(), height() * devicePixelRatio()); glBindTexture(GL_TEXTURE_2D, dynamicTexture); glEnable(GL_TEXTURE_2D); glEnable(GL_MULTISAMPLE); glEnable(GL_CULL_FACE); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // draw background glPushMatrix(); glScalef(1.7f, 1.7f, 1.7f); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glCallList(tile_list); glPopMatrix(); const int w = logo.width(); const int h = logo.height(); glRotatef(rot_x, 1.0f, 0.0f, 0.0f); glRotatef(rot_y, 0.0f, 1.0f, 0.0f); glRotatef(rot_z, 0.0f, 0.0f, 1.0f); glScalef(scale/w, scale/w, scale/w); glDepthFunc(GL_LESS); glEnable(GL_DEPTH_TEST); // draw the Qt icon glTranslatef(-w+1, -h+1, 0.0f); for (int y=h-1; y>=0; --y) { uint *p = (uint*) logo.scanLine(y); uint *end = p + w; int x = 0; while (p < end) { glColor4ub(qRed(*p), qGreen(*p), qBlue(*p), uchar(qAlpha(*p)*.9)); glTranslatef(0.0f, 0.0f, wave[y*w+x]); if (qAlpha(*p) > 128) glCallList(tile_list); glTranslatef(0.0f, 0.0f, -wave[y*w+x]); glTranslatef(2.0f, 0.0f, 0.0f); ++x; ++p; } glTranslatef(-w*2.0f, 2.0f, 0.0f); } // restore the GL state that QPainter expects restoreGLState(); p.endNativePainting(); // draw the overlayed text using QPainter p.setPen(QColor(197, 197, 197, 157)); p.setBrush(QColor(197, 197, 197, 127)); p.drawRect(QRect(0, 0, width(), 50)); p.setPen(Qt::black); p.setBrush(Qt::NoBrush); const QString str1(tr("A simple OpenGL pbuffer example.")); const QString str2(tr("Use the mouse wheel to zoom, press buttons and move mouse to rotate, double-click to flip.")); QFontMetrics fm(p.font()); p.drawText(width()/2 - fm.width(str1)/2, 20, str1); p.drawText(width()/2 - fm.width(str2)/2, 20 + fm.lineSpacing(), str2); }
/* draw a handle, for each end of a sequence strip */ static void draw_seq_handle(View2D *v2d, Sequence *seq, float pixelx, short direction) { float v1[2], v2[2], v3[2], rx1=0, rx2=0; //for triangles and rect float x1, x2, y1, y2; float handsize; float minhandle, maxhandle; char numstr[32]; unsigned int whichsel=0; x1= seq->startdisp; x2= seq->enddisp; y1= seq->machine+SEQ_STRIP_OFSBOTTOM; y2= seq->machine+SEQ_STRIP_OFSTOP; /* clamp handles to defined size in pixel space */ handsize = seq->handsize; minhandle = 7; maxhandle = 40; CLAMP(handsize, minhandle*pixelx, maxhandle*pixelx); /* set up co-ordinates/dimensions for either left or right handle */ if (direction == SEQ_LEFTHANDLE) { rx1 = x1; rx2 = x1+handsize * 0.75f; v1[0]= x1+handsize/4; v1[1]= y1+( ((y1+y2)/2.0f - y1)/2); v2[0]= x1+handsize/4; v2[1]= y2-( ((y1+y2)/2.0f - y1)/2); v3[0]= v2[0] + handsize/4; v3[1]= (y1+y2)/2.0f; whichsel = SEQ_LEFTSEL; } else if (direction == SEQ_RIGHTHANDLE) { rx1 = x2-handsize*0.75f; rx2 = x2; v1[0]= x2-handsize/4; v1[1]= y1+( ((y1+y2)/2.0f - y1)/2); v2[0]= x2-handsize/4; v2[1]= y2-( ((y1+y2)/2.0f - y1)/2); v3[0]= v2[0] - handsize/4; v3[1]= (y1+y2)/2.0f; whichsel = SEQ_RIGHTSEL; } /* draw! */ if(seq->type < SEQ_EFFECT || get_sequence_effect_num_inputs(seq->type) == 0) { glEnable( GL_BLEND ); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); if(seq->flag & whichsel) glColor4ub(0, 0, 0, 80); else if (seq->flag & SELECT) glColor4ub(255, 255, 255, 30); else glColor4ub(0, 0, 0, 22); glRectf(rx1, y1, rx2, y2); if(seq->flag & whichsel) glColor4ub(255, 255, 255, 200); else glColor4ub(0, 0, 0, 50); glEnable( GL_POLYGON_SMOOTH ); glBegin(GL_TRIANGLES); glVertex2fv(v1); glVertex2fv(v2); glVertex2fv(v3); glEnd(); glDisable( GL_POLYGON_SMOOTH ); glDisable( GL_BLEND ); } if(G.moving || (seq->flag & whichsel)) { const char col[4]= {255, 255, 255, 255}; if (direction == SEQ_LEFTHANDLE) { BLI_snprintf(numstr, sizeof(numstr),"%d", seq->startdisp); x1= rx1; y1 -= 0.45f; } else { BLI_snprintf(numstr, sizeof(numstr), "%d", seq->enddisp - 1); x1= x2 - handsize*0.75f; y1= y2 + 0.05f; } UI_view2d_text_cache_add(v2d, x1, y1, numstr, col); } }
static void draw_movieclip_cache(SpaceClip *sc, ARegion *ar, MovieClip *clip, Scene *scene) { float x; int *points, totseg, i, a; float sfra = SFRA, efra = EFRA, framelen = ar->winx / (efra - sfra + 1); MovieTracking *tracking = &clip->tracking; MovieTrackingObject *act_object = BKE_tracking_object_get_active(tracking); MovieTrackingTrack *act_track = BKE_tracking_track_get_active(&clip->tracking); MovieTrackingPlaneTrack *act_plane_track = BKE_tracking_plane_track_get_active(&clip->tracking); MovieTrackingReconstruction *reconstruction = BKE_tracking_get_active_reconstruction(tracking); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); /* cache background */ ED_region_cache_draw_background(ar); /* cached segments -- could be usefu lto debug caching strategies */ BKE_movieclip_get_cache_segments(clip, &sc->user, &totseg, &points); ED_region_cache_draw_cached_segments(ar, totseg, points, sfra, efra); /* track */ if (act_track || act_plane_track) { for (i = sfra - clip->start_frame + 1, a = 0; i <= efra - clip->start_frame + 1; i++) { int framenr; int markersnr = generic_track_get_markersnr(act_track, act_plane_track); while (a < markersnr) { int marker_framenr = generic_track_get_marker_framenr(act_track, act_plane_track, a); if (marker_framenr >= i) break; if (a < markersnr - 1 && generic_track_get_marker_framenr(act_track, act_plane_track, a + 1) > i) break; a++; } a = min_ii(a, markersnr - 1); if (generic_track_is_marker_enabled(act_track, act_plane_track, a)) { framenr = generic_track_get_marker_framenr(act_track, act_plane_track, a); if (framenr != i) glColor4ub(128, 128, 0, 96); else if (generic_track_is_marker_keyframed(act_track, act_plane_track, a)) glColor4ub(255, 255, 0, 196); else glColor4ub(255, 255, 0, 96); glRecti((i - sfra + clip->start_frame - 1) * framelen, 0, (i - sfra + clip->start_frame) * framelen, 4 * UI_DPI_FAC); } } } /* failed frames */ if (reconstruction->flag & TRACKING_RECONSTRUCTED) { int n = reconstruction->camnr; MovieReconstructedCamera *cameras = reconstruction->cameras; glColor4ub(255, 0, 0, 96); for (i = sfra, a = 0; i <= efra; i++) { bool ok = false; while (a < n) { if (cameras[a].framenr == i) { ok = true; break; } else if (cameras[a].framenr > i) { break; } a++; } if (!ok) glRecti((i - sfra + clip->start_frame - 1) * framelen, 0, (i - sfra + clip->start_frame) * framelen, 8 * UI_DPI_FAC); } } glDisable(GL_BLEND); /* current frame */ x = (sc->user.framenr - sfra) / (efra - sfra + 1) * ar->winx; UI_ThemeColor(TH_CFRAME); glRecti(x, 0, x + ceilf(framelen), 8 * UI_DPI_FAC); ED_region_cache_draw_curfra_label(sc->user.framenr, x, 8.0f * UI_DPI_FAC); /* solver keyframes */ glColor4ub(175, 255, 0, 255); draw_keyframe(act_object->keyframe1 + clip->start_frame - 1, CFRA, sfra, framelen, 2); draw_keyframe(act_object->keyframe2 + clip->start_frame - 1, CFRA, sfra, framelen, 2); /* movie clip animation */ if ((sc->mode == SC_MODE_MASKEDIT) && sc->mask_info.mask) { ED_mask_draw_frames(sc->mask_info.mask, ar, CFRA, sfra, efra); } }
static void apply_color(const gameswf::rgba& c) // Set the given color. { glColor4ub(c.m_r, c.m_g, c.m_b, c.m_a); }
void Target_draw() { float ratio = textureImages[textureIndex].ratio; float minTexCoordX = (ratio > 1.0f ? -0.5f : -0.5f / ratio) * (extendedTexCoords ? 2.0f : 1.0f) + 0.5f; float maxTexCoordX = (ratio > 1.0f ? 0.5f : 0.5f / ratio) * (extendedTexCoords ? 2.0f : 1.0f) + 0.5f; float minTexCoordY = (ratio < 1.0f ? -0.5f : -0.5f * ratio) * (extendedTexCoords ? 2.0f : 1.0f) + 0.5f; float maxTexCoordY = (ratio < 1.0f ? 0.5f : 0.5f * ratio) * (extendedTexCoords ? 2.0f : 1.0f) + 0.5f; struct vertex_p3f_t2f vertices[] = { {{-0.5f, -0.5f, 0.0f}, {minTexCoordX, minTexCoordY}}, {{ 0.5f, -0.5f, 0.0f}, {maxTexCoordX, minTexCoordY}}, {{ 0.5f, 0.5f, 0.0f}, {maxTexCoordX, maxTexCoordY}}, {{ 0.5f, 0.5f, 0.0f}, {maxTexCoordX, maxTexCoordY}}, {{-0.5f, 0.5f, 0.0f}, {minTexCoordX, maxTexCoordY}}, {{-0.5f, -0.5f, 0.0f}, {minTexCoordX, minTexCoordY}}, {{-0.5f, -0.75f, -0.5f}, {minTexCoordX, minTexCoordY}}, {{ 0.5f, -0.75f, -0.5f}, {maxTexCoordX, minTexCoordY}}, {{ 0.5f, -0.75f, 0.5f}, {maxTexCoordX, maxTexCoordY}}, {{ 0.5f, -0.75f, 0.5f}, {maxTexCoordX, maxTexCoordY}}, {{-0.5f, -0.75f, 0.5f}, {minTexCoordX, maxTexCoordY}}, {{-0.5f, -0.75f, -0.5f}, {minTexCoordX, minTexCoordY}}, {{-0.5f, 0.75f, -0.5f}, {minTexCoordX, minTexCoordY}}, {{ 0.5f, 0.75f, -0.5f}, {maxTexCoordX, minTexCoordY}}, {{ 0.5f, 0.75f, 0.5f}, {maxTexCoordX, maxTexCoordY}}, {{ 0.5f, 0.75f, 0.5f}, {maxTexCoordX, maxTexCoordY}}, {{-0.5f, 0.75f, 0.5f}, {minTexCoordX, maxTexCoordY}}, {{-0.5f, 0.75f, -0.5f}, {minTexCoordX, minTexCoordY}} }; Matrix matrix; if (whiteBackground) { glClearColor(1.0f, 1.0f, 1.0f, 0.0f); } else { glClearColor(0.0f, 0.0f, 0.0f, 0.0f); } glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); matrix = Matrix_perspective(Matrix_identity(), 60.0f, (float) viewportWidth / viewportHeight, 0.25f, 100.0f); glMultMatrixf(matrix.m); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0f, 0.0f, zoomedOut ? -5.0f : -2.0f); texture->activate(texture); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glColor4ub(0xFF, 0xFF, 0xFF, 0xFF); glVertexPointer(3, GL_FLOAT, sizeof(struct vertex_p3f_t2f), vertices[0].position); glTexCoordPointer(2, GL_FLOAT, sizeof(struct vertex_p3f_t2f), vertices[0].texCoords); glDrawArrays(GL_TRIANGLES, 0, sizeof(vertices) / sizeof(struct vertex_p3f_t2f)); glDisableClientState(GL_TEXTURE_COORD_ARRAY); texture->deactivate(texture); if (iPhoneMode) { float viewRatio = (float) viewportWidth / viewportHeight; glMatrixMode(GL_PROJECTION); glLoadIdentity(); matrix = Matrix_ortho(Matrix_identity(), 0.0f, viewRatio, 0.0f, 1.0f, -1.0f, 1.0f); glMultMatrixf(matrix.m); glMatrixMode(GL_MODELVIEW); drawControl(0.0f, 0.0f / 6.0f, 1.0f / 6.0f, textureIndex); drawControl(0.0f, 1.0f / 6.0f, 1.0f / 6.0f, autoBlendModeIndex); drawControl(0.0f, 2.0f / 6.0f, 1.0f / 6.0f, minFilterIndex); drawControl(0.0f, 3.0f / 6.0f, 1.0f / 6.0f, magFilterIndex); drawControl(0.0f, 4.0f / 6.0f, 1.0f / 6.0f, wrapSModeIndex); drawControl(0.0f, 5.0f / 6.0f, 1.0f / 6.0f, wrapTModeIndex); drawControl(viewRatio - 1.0f / 6.0f, 0.0f / 6.0f, 1.0f / 6.0f, autoMipmap); drawControl(viewRatio - 1.0f / 6.0f, 1.0f / 6.0f, 1.0f / 6.0f, anisotropicFilter); drawControl(viewRatio - 1.0f / 6.0f, 2.0f / 6.0f, 1.0f / 6.0f, extendedTexCoords); drawControl(viewRatio - 1.0f / 6.0f, 3.0f / 6.0f, 1.0f / 6.0f, whiteBackground); drawControl(viewRatio - 1.0f / 6.0f, 4.0f / 6.0f, 1.0f / 6.0f, zoomedOut); drawControl(viewRatio - 1.0f / 6.0f, 5.0f / 6.0f, 1.0f / 6.0f, 0); } }
/* draw keyframes in each channel */ void draw_channel_strips(bAnimContext *ac, SpaceAction *saction, ARegion *ar) { ListBase anim_data = {NULL, NULL}; bAnimListElem *ale; int filter; View2D *v2d= &ar->v2d; bDopeSheet *ads= &saction->ads; AnimData *adt= NULL; float act_start, act_end, y; int height, items; unsigned char col1[3], col2[3]; unsigned char col1a[3], col2a[3]; unsigned char col1b[3], col2b[3]; /* get theme colors */ UI_GetThemeColor3ubv(TH_BACK, col2); UI_GetThemeColor3ubv(TH_HILITE, col1); UI_GetThemeColor3ubv(TH_GROUP, col2a); UI_GetThemeColor3ubv(TH_GROUP_ACTIVE, col1a); UI_GetThemeColor3ubv(TH_DOPESHEET_CHANNELOB, col1b); UI_GetThemeColor3ubv(TH_DOPESHEET_CHANNELSUBOB, col2b); /* set view-mapping rect (only used for x-axis), for NLA-scaling mapping with less calculation */ /* if in NLA there's a strip active, map the view */ if (ac->datatype == ANIMCONT_ACTION) { adt= ANIM_nla_mapping_get(ac, NULL); /* start and end of action itself */ calc_action_range(ac->data, &act_start, &act_end, 0); } /* build list of channels to draw */ filter= (ANIMFILTER_VISIBLE|ANIMFILTER_CHANNELS); items= ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); /* Update max-extent of channels here (taking into account scrollers): * - this is done to allow the channel list to be scrollable, but must be done here * to avoid regenerating the list again and/or also because channels list is drawn first * - offset of ACHANNEL_HEIGHT*2 is added to the height of the channels, as first is for * start of list offset, and the second is as a correction for the scrollers. */ height= ((items*ACHANNEL_STEP) + (ACHANNEL_HEIGHT*2)); /* don't use totrect set, as the width stays the same * (NOTE: this is ok here, the configuration is pretty straightforward) */ v2d->tot.ymin= (float)(-height); /* first backdrop strips */ y= (float)(-ACHANNEL_HEIGHT); glEnable(GL_BLEND); for (ale= anim_data.first; ale; ale= ale->next) { const float yminc= (float)(y - ACHANNEL_HEIGHT_HALF); const float ymaxc= (float)(y + ACHANNEL_HEIGHT_HALF); /* check if visible */ if ( IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) || IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax) ) { bAnimChannelType *acf= ANIM_channel_get_typeinfo(ale); int sel=0; /* determine if any need to draw channel */ if (ale->datatype != ALE_NONE) { /* determine if channel is selected */ if (acf->has_setting(ac, ale, ACHANNEL_SETTING_SELECT)) sel= ANIM_channel_setting_get(ac, ale, ACHANNEL_SETTING_SELECT); if (ELEM3(ac->datatype, ANIMCONT_ACTION, ANIMCONT_DOPESHEET, ANIMCONT_SHAPEKEY)) { switch (ale->type) { case ANIMTYPE_SUMMARY: { // FIXME: hardcoded colors - reddish color from NLA glColor4f(0.8f, 0.2f, 0.0f, 0.4f); } break; case ANIMTYPE_SCENE: case ANIMTYPE_OBJECT: { if (sel) glColor4ub(col1b[0], col1b[1], col1b[2], 0x45); else glColor4ub(col1b[0], col1b[1], col1b[2], 0x22); } break; case ANIMTYPE_FILLACTD: case ANIMTYPE_FILLMATD: case ANIMTYPE_FILLPARTD: case ANIMTYPE_DSSKEY: case ANIMTYPE_DSWOR: { if (sel) glColor4ub(col2b[0], col2b[1], col2b[2], 0x45); else glColor4ub(col2b[0], col2b[1], col2b[2], 0x22); } break; case ANIMTYPE_GROUP: { if (sel) glColor4ub(col1a[0], col1a[1], col1a[2], 0x22); else glColor4ub(col2a[0], col2a[1], col2a[2], 0x22); } break; default: { if (sel) glColor4ub(col1[0], col1[1], col1[2], 0x22); else glColor4ub(col2[0], col2[1], col2[2], 0x22); } break; } /* draw region twice: firstly backdrop, then the current range */ glRectf(v2d->cur.xmin, (float)y-ACHANNEL_HEIGHT_HALF, v2d->cur.xmax+EXTRA_SCROLL_PAD, (float)y+ACHANNEL_HEIGHT_HALF); if (ac->datatype == ANIMCONT_ACTION) glRectf(act_start, (float)y-ACHANNEL_HEIGHT_HALF, act_end, (float)y+ACHANNEL_HEIGHT_HALF); } else if (ac->datatype == ANIMCONT_GPENCIL) { /* frames less than one get less saturated background */ if (sel) glColor4ub(col1[0], col1[1], col1[2], 0x22); else glColor4ub(col2[0], col2[1], col2[2], 0x22); glRectf(0.0f, (float)y-ACHANNEL_HEIGHT_HALF, v2d->cur.xmin, (float)y+ACHANNEL_HEIGHT_HALF); /* frames one and higher get a saturated background */ if (sel) glColor4ub(col1[0], col1[1], col1[2], 0x44); else glColor4ub(col2[0], col2[1], col2[2], 0x44); glRectf(v2d->cur.xmin, (float)y-ACHANNEL_HEIGHT_HALF, v2d->cur.xmax+EXTRA_SCROLL_PAD, (float)y+ACHANNEL_HEIGHT_HALF); } } } /* Increment the step */ y -= ACHANNEL_STEP; } glDisable(GL_BLEND); /* Draw keyframes * 1) Only channels that are visible in the Action Editor get drawn/evaluated. * This is to try to optimise this for heavier data sets * 2) Keyframes which are out of view horizontally are disregarded */ y= (float)(-ACHANNEL_HEIGHT); for (ale= anim_data.first; ale; ale= ale->next) { const float yminc= (float)(y - ACHANNEL_HEIGHT_HALF); const float ymaxc= (float)(y + ACHANNEL_HEIGHT_HALF); /* check if visible */ if ( IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) || IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax) ) { /* check if anything to show for this channel */ if (ale->datatype != ALE_NONE) { adt= ANIM_nla_mapping_get(ac, ale); /* draw 'keyframes' for each specific datatype */ switch (ale->datatype) { case ALE_ALL: draw_summary_channel(v2d, ale->data, y); break; case ALE_SCE: draw_scene_channel(v2d, ads, ale->key_data, y); break; case ALE_OB: draw_object_channel(v2d, ads, ale->key_data, y); break; case ALE_ACT: draw_action_channel(v2d, adt, ale->key_data, y); break; case ALE_GROUP: draw_agroup_channel(v2d, adt, ale->data, y); break; case ALE_FCURVE: draw_fcurve_channel(v2d, adt, ale->key_data, y); break; case ALE_GPFRAME: draw_gpl_channel(v2d, ads, ale->data, y); break; } } } y-= ACHANNEL_STEP; } /* free tempolary channels used for drawing */ BLI_freelistN(&anim_data); /* black line marking 'current frame' for Time-Slide transform mode */ if (saction->flag & SACTION_MOVING) { glColor3f(0.0f, 0.0f, 0.0f); glBegin(GL_LINES); glVertex2f(saction->timeslide, v2d->cur.ymin-EXTRA_SCROLL_PAD); glVertex2f(saction->timeslide, v2d->cur.ymax); glEnd(); } }
bool Object::draw() { if(!alive) { return false; } if(!visible) { return true; } if( this->alphaColor < 255) { glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } //Nouveau Repere glPushMatrix(); //scaling / Translation / rotations de l'objet glTranslated(transX,transY,transZ); glRotated(rotateX,1,0,0); glRotated(rotateY,0,1,0); glRotated(rotateZ,0,0,1); glScalef( xScale, yScale, zScale ); glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_GREATER, 0.0f); //La couleur Ambiante de l'objet est mise au BLANC ( sinon vert par defaut) glColor4ub(255,255,255,this->alphaColor); //Texture a appliquer glBindTexture(GL_TEXTURE_2D,this->noTexture); //donne le tableau des points glVertexPointer( 3, GL_FLOAT, 0, this->data->point ); //on prepare le traçage des points glEnableClientState( GL_VERTEX_ARRAY ); //donne le tableau des textures glTexCoordPointer(2, GL_FLOAT, 0, this->data->texture); //Prepare la pose de la texture glEnableClientState(GL_TEXTURE_COORD_ARRAY); glDrawElements( GL_TRIANGLES, this->data->nbIndice , GL_UNSIGNED_INT, data->indice ); //on arrete le traçage glDisableClientState( GL_VERTEX_ARRAY ); //on arrete le traçage de texture glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisable(GL_ALPHA_TEST); //Nouveau Repere detruit glPopMatrix(); return true; }
void gxRenderingTriangle::Render() { GLint nRenderMode = GL_RENDER; glGetIntegerv(GL_RENDER_MODE, &nRenderMode); bool bRenderWithTexture = (m_bTextured) && (nRenderMode == GL_RENDER); if(bRenderWithTexture) { glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, m_nTextureObject); glBegin(GL_TRIANGLES); mlVector3D vNormal = Normal(); vNormal.Normalise(); glNormal3f(vNormal.x, vNormal.y, vNormal.z); glColor4ub(colorA.red, colorA.green, colorA.blue, colorA.alpha); glTexCoord2f(textureCoordA.x, textureCoordA.y); glVertex3f(a.x, a.y, a.z); glColor4ub(colorB.red, colorB.green, colorB.blue, colorB.alpha); glTexCoord2f(textureCoordB.x, textureCoordB.y); glVertex3f(b.x, b.y, b.z); glColor4ub(colorC.red, colorC.green, colorC.blue, colorC.alpha); glTexCoord2f(textureCoordC.x, textureCoordC.y); glVertex3f(c.x, c.y, c.z); glEnd(); glDisable(GL_TEXTURE_2D); } else { glDisable(GL_TEXTURE_2D); glBegin(GL_TRIANGLES); mlVector3D vNormal = Normal(); vNormal.Normalise(); glNormal3f(vNormal.x, vNormal.y, vNormal.z); glColor4ub(colorA.red, colorA.green, colorA.blue, colorA.alpha); glVertex3f(a.x, a.y, a.z); glColor4ub(colorB.red, colorB.green, colorB.blue, colorB.alpha); glVertex3f(b.x, b.y, b.z); glColor4ub(colorC.red, colorC.green, colorC.blue, colorC.alpha); glVertex3f(c.x, c.y, c.z); glEnd(); } }
int main(int argc, char *argv[]) { if(argc < 2) { std::cout << "Please provide a filename." << std::endl; return 1; } const char* filename = argv[1]; // Load file and decode image. std::vector<unsigned char> image; unsigned width, height; unsigned error = lodepng::decode(image, width, height, filename); // If there's an error, display it. if(error != 0) { std::cout << "error " << error << ": " << lodepng_error_text(error) << std::endl; return 1; } // Here the PNG is loaded in "image". All the rest of the code is SDL and OpenGL stuff. int screenw = width; if(screenw > 1024) screenw = 1024; int screenh = height; if(screenh > 768) screenw = 768; if(SDL_Init(SDL_INIT_VIDEO) < 0) { std::cout << "Error: Unable to init SDL: " << SDL_GetError() << std::endl; return 1; } SDL_Surface* scr = SDL_SetVideoMode(screenw, screenh, 32, SDL_OPENGL); if(scr == 0) { std::cout << "Error: Unable to set video. SDL error message: " << SDL_GetError() << std::endl; return 1; } // The official code for "Setting Your Raster Position to a Pixel Location" (i.e. set up a camera for 2D screen) glViewport(0, 0, screenw, screenh); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, screenw, screenh, 0, -1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // Make some OpenGL properties better for 2D and enable alpha channel. glDisable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glDisable(GL_ALPHA_TEST); if(glGetError() != GL_NO_ERROR) { std::cout << "Error initing GL" << std::endl; return 1; } // Texture size must be power of two for the primitive OpenGL version this is written for. Find next power of two. size_t u2 = 1; while(u2 < width) u2 *= 2; size_t v2 = 1; while(v2 < height) v2 *= 2; // Ratio for power of two version compared to actual version, to render the non power of two image with proper size. double u3 = (double)width / u2; double v3 = (double)height / v2; // Make power of two version of the image. std::vector<unsigned char> image2(u2 * v2 * 4); for(size_t y = 0; y < height; y++) for(size_t x = 0; x < width; x++) for(size_t c = 0; c < 4; c++) { image2[4 * u2 * y + 4 * x + c] = image[4 * width * y + 4 * x + c]; } // Enable the texture for OpenGL. glEnable(GL_TEXTURE_2D); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); //GL_NEAREST = no smoothing glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, 4, u2, v2, 0, GL_RGBA, GL_UNSIGNED_BYTE, &image2[0]); bool done = false; SDL_Event event = {0}; glColor4ub(255, 255, 255, 255); while(!done) { // Quit the loop when receiving quit event. while(SDL_PollEvent(&event)) { if(event.type == SDL_QUIT) done = 1; } // Draw the texture on a quad, using u3 and v3 to correct non power of two texture size. glBegin(GL_QUADS); glTexCoord2d( 0, 0); glVertex2f( 0, 0); glTexCoord2d(u3, 0); glVertex2f(width, 0); glTexCoord2d(u3, v3); glVertex2f(width, height); glTexCoord2d( 0, v3); glVertex2f( 0, height); glEnd(); // Redraw and clear screen. SDL_GL_SwapBuffers(); glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //Limit frames per second, to not heat up the CPU and GPU too much. SDL_Delay(16); } }
// Render a world polygon without multitexture support. This will do two-polygon draws, // one with the regular texture, then another with the lightmap texture. Clearly we hope // we don't have to use this function (if multitexture is supported in hardware and OpenGL // ICD, we won't have to), but its here just in case. void Render_WorldPolyRegular(DRV_TLVertex *Pnts, int32 NumPoints, geRDriver_THandle *THandle, DRV_LInfo *LInfo, GLfloat shiftU, GLfloat shiftV, GLfloat scaleU, GLfloat scaleV, GLubyte alpha) { DRV_TLVertex *pPnt; GLfloat zRecip; GLfloat tu, tv; GLint i; #ifdef USE_LIGHTMAPS if(LInfo != NULL) { glDepthMask(GL_FALSE); } #endif pPnt = Pnts; glBegin(GL_TRIANGLE_FAN); for(i = 0; i < NumPoints; i++) { zRecip = 1.0f / pPnt->z; tu = (pPnt->u * scaleU + shiftU); tv = (pPnt->v * scaleV + shiftV); glColor4ub((GLubyte)pPnt->r, (GLubyte)pPnt->g, (GLubyte)pPnt->b, alpha); glTexCoord4f(tu * THandle->InvScale * zRecip, tv * THandle->InvScale * zRecip, 0.0f, zRecip); glVertex3f(pPnt->x, pPnt->y, -1.0f + zRecip); pPnt++; } glEnd(); #ifdef USE_LIGHTMAPS if(LInfo != NULL) { glDepthMask(GL_TRUE); glBlendFunc(GL_DST_COLOR,GL_ZERO); pPnt = Pnts; if(boundTexture != LInfo->THandle->TextureID) { glBindTexture(GL_TEXTURE_2D, LInfo->THandle->TextureID); boundTexture = LInfo->THandle->TextureID; } if(LInfo->THandle->Flags & THANDLE_UPDATE) { THandle_Update(LInfo->THandle); } shiftU = (GLfloat)LInfo->MinU - 8.0f; shiftV = (GLfloat)LInfo->MinV - 8.0f; glColor4ub(255, 255, 255, 255); glBegin(GL_TRIANGLE_FAN); for(i = 0; i < NumPoints; i++) { zRecip = 1.0f / pPnt->z; tu = pPnt->u - shiftU; tv = pPnt->v - shiftV; glTexCoord4f(tu * LInfo->THandle->InvScale * zRecip, tv * LInfo->THandle->InvScale * zRecip, 0.0f, zRecip); glVertex3f(pPnt->x, pPnt->y, -1.0f + zRecip); pPnt++; } glEnd(); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } #endif }
// Render a world polygon using multiple TMUs to map the regular texture and lightmap in one pass void Render_WorldPolyMultitexture(DRV_TLVertex *Pnts, int32 NumPoints, geRDriver_THandle *THandle, DRV_LInfo *LInfo, GLfloat shiftU, GLfloat shiftV, GLfloat scaleU, GLfloat scaleV, GLubyte alpha) { DRV_TLVertex *pPnt; GLfloat zRecip; GLfloat tu, tv, lu, lv; GLfloat shiftU2, shiftV2; GLint i; if(LInfo != NULL) { glActiveTextureARB(GL_TEXTURE1_ARB); glEnable(GL_TEXTURE_2D); if(boundTexture2 != LInfo->THandle->TextureID) { glBindTexture(GL_TEXTURE_2D, LInfo->THandle->TextureID); boundTexture2 = LInfo->THandle->TextureID; } if(LInfo->THandle->Flags & THANDLE_UPDATE) { THandle_Update(LInfo->THandle); } shiftU2 = (GLfloat)LInfo->MinU - 8.0f; shiftV2 = (GLfloat)LInfo->MinV - 8.0f; } pPnt = Pnts; glBegin(GL_TRIANGLE_FAN); for(i = 0; i < NumPoints; i++) { zRecip = 1.0f / pPnt->z; tu = (pPnt->u * scaleU + shiftU); tv = (pPnt->v * scaleV + shiftV); glColor4ub((GLubyte)pPnt->r, (GLubyte)pPnt->g, (GLubyte)pPnt->b, alpha); glMultiTexCoord4fARB(GL_TEXTURE0_ARB, tu * THandle->InvScale * zRecip, tv * THandle->InvScale * zRecip, 0.0f, zRecip); if(LInfo) { lu = pPnt->u - shiftU2; lv = pPnt->v - shiftV2; glMultiTexCoord4fARB(GL_TEXTURE1_ARB, lu * LInfo->THandle->InvScale * zRecip, lv * LInfo->THandle->InvScale * zRecip, 0.0f, zRecip); } glVertex3f(pPnt->x, pPnt->y, -1.0f + zRecip); pPnt++; } glEnd(); if(LInfo != NULL) { glDisable(GL_TEXTURE_2D); glActiveTextureARB(GL_TEXTURE0_ARB); } }
int main() { int fontNormal = FONS_INVALID; int fontItalic = FONS_INVALID; int fontBold = FONS_INVALID; int fontJapanese = FONS_INVALID; GLFWwindow* window; const GLFWvidmode* mode; if (!glfwInit()) return -1; mode = glfwGetVideoMode(glfwGetPrimaryMonitor()); window = glfwCreateWindow(mode->width - 40, mode->height - 80, "Font Stash", NULL, NULL); if (!window) { glfwTerminate(); return -1; } glfwSetKeyCallback(window, key); glfwMakeContextCurrent(window); fs = glfonsCreate(256, 256, FONS_ZERO_TOPLEFT); if (fs == NULL) { printf("Could not create stash.\n"); return -1; } fonsSetErrorCallback(fs, stashError, fs); fontNormal = fonsAddFont(fs, "sans", "../example/DroidSerif-Regular.ttf"); if (fontNormal == FONS_INVALID) { printf("Could not add font normal.\n"); return -1; } fontItalic = fonsAddFont(fs, "sans-italic", "../example/DroidSerif-Italic.ttf"); if (fontItalic == FONS_INVALID) { printf("Could not add font italic.\n"); return -1; } fontBold = fonsAddFont(fs, "sans-bold", "../example/DroidSerif-Bold.ttf"); if (fontBold == FONS_INVALID) { printf("Could not add font bold.\n"); return -1; } fontJapanese = fonsAddFont(fs, "sans-jp", "../example/DroidSansJapanese.ttf"); if (fontJapanese == FONS_INVALID) { printf("Could not add font japanese.\n"); return -1; } while (!glfwWindowShouldClose(window)) { float sx, sy, dx, dy, lh = 0; int width, height; int atlasw, atlash; unsigned int white,black,brown,blue; char msg[64]; glfwGetFramebufferSize(window, &width, &height); // Update and render glViewport(0, 0, width, height); glClearColor(0.3f, 0.3f, 0.32f, 1.0f); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_TEXTURE_2D); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0,width,height,0,-1,1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glDisable(GL_DEPTH_TEST); glColor4ub(255,255,255,255); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_CULL_FACE); white = glfonsRGBA(255,255,255,255); brown = glfonsRGBA(192,128,0,128); blue = glfonsRGBA(0,192,255,255); black = glfonsRGBA(0,0,0,255); sx = 50; sy = 50; dx = sx; dy = sy; dash(dx,dy); fonsClearState(fs); fonsSetSize(fs, size); fonsSetFont(fs, fontNormal); fonsVertMetrics(fs, NULL, NULL, &lh); dx = sx; dy += lh; dash(dx,dy); fonsSetSize(fs, size); fonsSetFont(fs, fontNormal); fonsSetColor(fs, white); dx = fonsDrawText(fs, dx,dy,"The quick ",NULL); fonsSetSize(fs, size/2); fonsSetFont(fs, fontItalic); fonsSetColor(fs, brown); dx = fonsDrawText(fs, dx,dy,"brown ",NULL); fonsSetSize(fs, size/3); fonsSetFont(fs, fontNormal); fonsSetColor(fs, white); dx = fonsDrawText(fs, dx,dy,"fox ",NULL); fonsSetSize(fs, 14); fonsSetFont(fs, fontNormal); fonsSetColor(fs, white); fonsDrawText(fs, 20, height-20,"Press UP / DOWN keys to change font size and to trigger atlas full callback, R to reset atlas, E to expand atlas.",NULL); fonsGetAtlasSize(fs, &atlasw, &atlash); snprintf(msg, sizeof(msg), "Atlas: %d × %d", atlasw, atlash); fonsDrawText(fs, 20, height-50, msg, NULL); fonsDrawDebug(fs, width - atlasw - 20, 20.0); glEnable(GL_DEPTH_TEST); glfwSwapBuffers(window); glfwPollEvents(); } glfonsDelete(fs); glfwTerminate(); return 0; }
JNIEXPORT void JNICALL JNIFUNCTION_NATIVE(nativeDrawFrame(JNIEnv* env, jobject obj, jint movieWidth, jint movieHeight, jint movieTextureID, jfloatArray movieTextureMtx)) { float width, height; // Get the array contents. //jsize movieTextureMtxLen = env->GetArrayLength(movieTextureMtx); float movieTextureMtxUnpacked[16]; env->GetFloatArrayRegion(movieTextureMtx, 0, /*movieTextureMtxLen*/ 16, movieTextureMtxUnpacked); if (!videoInited) { #ifdef DEBUG LOGI("nativeDrawFrame !VIDEO\n"); #endif return; // No point in trying to draw until video is inited. } if (!nftDataLoaded && nftDataLoadingThreadHandle) { // Check if NFT data loading has completed. if (threadGetStatus(nftDataLoadingThreadHandle) > 0) { nftDataLoaded = true; threadWaitQuit(nftDataLoadingThreadHandle); threadFree(&nftDataLoadingThreadHandle); // Clean up. } else { #ifdef DEBUG LOGI("nativeDrawFrame !NFTDATA\n"); #endif return; // No point in trying to draw until NFT data is loaded. } } #ifdef DEBUG LOGI("nativeDrawFrame\n"); #endif if (!gARViewInited) { if (!initARView()) return; } if (gARViewLayoutRequired) layoutARView(); // Upload new video frame if required. if (videoFrameNeedsPixelBufferDataUpload) { pthread_mutex_lock(&gVideoFrameLock); arglPixelBufferDataUploadBiPlanar(gArglSettings, gVideoFrame, gVideoFrame + videoWidth*videoHeight); videoFrameNeedsPixelBufferDataUpload = false; pthread_mutex_unlock(&gVideoFrameLock); } glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear the buffers for new frame. // Display the current frame arglDispImage(gArglSettings); // Set up 3D mode. glMatrixMode(GL_PROJECTION); glLoadMatrixf(cameraLens); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glStateCacheEnableDepthTest(); // Set any initial per-frame GL state you require here. // ---> // Lighting and geometry that moves with the camera should be added here. // (I.e. should be specified before camera pose transform.) // ---> // Draw an object on all valid markers. for (int i = 0; i < markersNFTCount; i++) { if (markersNFT[i].valid) { glLoadMatrixf(markersNFT[i].pose.T); // // Draw a rectangular surface textured with the movie texture. // float w = 80.0f; float h = w * (float)movieHeight/(float)movieWidth; GLfloat vertices[4][2] = { {0.0f, 0.0f}, {w, 0.0f}, {w, h}, {0.0f, h} }; GLfloat normals[4][3] = { {0.0f, 0.0f, 1.0f}, {0.0f, 0.0f, 1.0f}, {0.0f, 0.0f, 1.0f}, {0.0f, 0.0f, 1.0f} }; GLfloat texcoords[4][2] = { {0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f} }; glStateCacheActiveTexture(GL_TEXTURE0); glMatrixMode(GL_TEXTURE); glPushMatrix(); glLoadMatrixf(movieTextureMtxUnpacked); glMatrixMode(GL_MODELVIEW); glVertexPointer(2, GL_FLOAT, 0, vertices); glNormalPointer(GL_FLOAT, 0, normals); glStateCacheClientActiveTexture(GL_TEXTURE0); glTexCoordPointer(2, GL_FLOAT, 0, texcoords); glStateCacheEnableClientStateVertexArray(); glStateCacheEnableClientStateNormalArray(); glStateCacheEnableClientStateTexCoordArray(); glStateCacheBindTexture2D(0); glStateCacheDisableTex2D(); glStateCacheDisableLighting(); glEnable(GL_TEXTURE_EXTERNAL_OES); glBindTexture(GL_TEXTURE_EXTERNAL_OES, movieTextureID); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); glBindTexture(GL_TEXTURE_EXTERNAL_OES, 0); glDisable(GL_TEXTURE_EXTERNAL_OES); glMatrixMode(GL_TEXTURE); glPopMatrix(); glMatrixMode(GL_MODELVIEW); // // End. // } } if (cameraPoseValid) { glMultMatrixf(cameraPose); // All lighting and geometry to be drawn in world coordinates goes here. // ---> } // If you added external OpenGL code above, and that code doesn't use the glStateCache routines, // then uncomment the line below. //glStateCacheFlush(); // Set up 2D mode. glMatrixMode(GL_PROJECTION); glLoadIdentity(); width = (float)viewPort[viewPortIndexWidth]; height = (float)viewPort[viewPortIndexHeight]; glOrthof(0.0f, width, 0.0f, height, -1.0f, 1.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glStateCacheDisableDepthTest(); // Add your own 2D overlays here. // ---> // If you added external OpenGL code above, and that code doesn't use the glStateCache routines, // then uncomment the line below. //glStateCacheFlush(); #ifdef DEBUG // Example of 2D drawing. It just draws a white border line. Change the 0 to 1 to enable. const GLfloat square_vertices [4][2] = { {0.5f, 0.5f}, {0.5f, height - 0.5f}, {width - 0.5f, height - 0.5f}, {width - 0.5f, 0.5f} }; glStateCacheDisableLighting(); glStateCacheDisableTex2D(); glVertexPointer(2, GL_FLOAT, 0, square_vertices); glStateCacheEnableClientStateVertexArray(); glColor4ub(255, 255, 255, 255); glDrawArrays(GL_LINE_LOOP, 0, 4); CHECK_GL_ERROR(); #endif }
void pauseIcons() { ////////Play icon/////// glPointSize(2); glColor3ub(200,0,0); pauseIconX[0]=3*width/9; pauseIconY[0]=3*height/8; drawColorBall(pauseIconX[0],pauseIconY[0],40); glColor4ub(0,0,0,40); glPointSize(4); drawCircle(pauseIconX[0],pauseIconY[0],40); glPointSize(2); glColor3ub(255,255,255); glPushMatrix(); glTranslated(3*width/9-15,3*height/8,0); glRotated(-90,0,0,1); glBegin(GL_TRIANGLES); glVertex2d(35*sin(45*(M_PI/180)),0); glVertex2d(-35*cos(45*(M_PI/180)),0); glVertex2d(0,40); glEnd(); glPopMatrix(); ////////////Restart Icon/////////// glPointSize(2); glColor3ub(0,200,0); pauseIconX[1]=2*width/3; pauseIconY[1]=3*height/8; drawColorBall(pauseIconX[1],pauseIconY[1],40); glColor4ub(0,0,0,40); glPointSize(4); drawCircle(pauseIconX[1],pauseIconY[1],40); glLineWidth(8); glPointSize(5); glColor3ub(255,255,255); glPushMatrix(); glTranslated(pauseIconX[1]-18,pauseIconY[1]-18,0); glScalef(0.5,0.5,1); strokeString("c"); glPopMatrix(); glLineWidth(8); glPointSize(4); glPushMatrix(); glTranslated(pauseIconX[1]+10,pauseIconY[1]+10,0); glScalef(0.6,0.6,1); glRotated(-140,0,0,1); glBegin(GL_TRIANGLES); glVertex2d(20*sin(45*(M_PI/180)),0); glVertex2d(-20*cos(45*(M_PI/180)),0); glVertex2d(0,30); glEnd(); glPopMatrix(); ///////////Return Icon//////////// glPointSize(2); glColor3ub(204,0,204); pauseIconX[2]=width/2; pauseIconY[2]=height/8; drawColorBall(pauseIconX[2],pauseIconY[2],40); glColor4ub(0,0,0,40); glPointSize(4); drawCircle(pauseIconX[2],pauseIconY[2],40); glLineWidth(8); glPointSize(5); glColor3ub(255,255,255); glPushMatrix(); glTranslated(pauseIconX[2]-25,pauseIconY[2]-5,0); glScalef(0.25,0.25,1); drawArrow(); glPopMatrix(); glLineWidth(4); glPointSize(2); glColor3ub(255,255,255); glPushMatrix(); glTranslated(pauseIconX[2],pauseIconY[2],0); glScalef(1,1,1); glBegin(GL_LINES); glVertex2d(-10,20); glVertex2d(10,20); glVertex2d(10,20); glVertex2d(10,-20); glVertex2d(10,-20); glVertex2d(-10,-20); glVertex2d(-10,-20); glVertex2d(-10,20); glEnd(); glPopMatrix(); }
//********************************************************* void GLFont::RenderText (const char* String, float size, Element* element) { //Return if we don't have a valid glFont if (!ok) { throw GLFontError::InvalidFont(); } float floatWidth, floatHeight; float tempArray[2]; float tempSecondArray[2]; window_t* window = element->elementInfo; window_t* parentInfo = window->parent->elementInfo; //Work out the bounds of the textbox switch (element->windowType) { case 0: //The first corner of the window tempArray[0] = element->originPosition[0] + element->rendering->PixelToFloat1D(window->x, element->screenWidth) * element->xModifier; tempArray[1] = element->originPosition[1] + element->rendering->PixelToFloat1D(window->y, element->screenHeight) * element->yModifier; //The second corner of the window tempSecondArray[0] = element->originPosition[0] + element->rendering->PixelToFloat1D(window->x + window->width, element->screenWidth) * element->xModifier; tempSecondArray[1] = element->originPosition[1] + element->rendering->PixelToFloat1D(window->y + window->height, element->screenHeight) * element->yModifier; break; case 1: //The first corner of the window tempArray[0] = element->originPosition[0] + element->rendering->GetRelativeFloat1D(window->x, parentInfo->width) * element->xModifier; tempArray[1] = element->originPosition[1] + element->rendering->GetRelativeFloat1D(window->y, parentInfo->height) * element->yModifier; //The second corner of the window tempSecondArray[0] = element->originPosition[0] + element->rendering->GetRelativeFloat1D(window->x + window->width, parentInfo->width) * element->xModifier; tempSecondArray[1] = element->originPosition[1] + element->rendering->GetRelativeFloat1D(window->y + window->height, parentInfo->height) * element->yModifier; break; case 2: //Convert the height into a float value floatHeight = element->rendering->PixelToFloat1D(window->height, element->screenHeight); //The first corner of the window tempArray[0] = element->originPosition[0] + element->rendering->GetRelativeFloat1D(window->x, parentInfo->width) * element->xModifier; tempArray[1] = element->originPosition[1] + element->rendering->GetRelativeFloat1D(window->y, parentInfo->height) * element->yModifier; //The second corner of the window tempSecondArray[0] = element->originPosition[0] + element->rendering->GetRelativeFloat1D(window->x + window->width, parentInfo->width) * element->xModifier; tempSecondArray[1] = tempArray[1] + floatHeight * element->yModifier; break; case 3: //Convert the width into a float value floatWidth = element->rendering->PixelToFloat1D(window->width, element->screenWidth) * element->xModifier; //The first corner of the window tempArray[0] = element->originPosition[0] + element->rendering->GetRelativeFloat1D(window->x, parentInfo->width) * element->xModifier; tempArray[1] = element->originPosition[1] + element->rendering->GetRelativeFloat1D(window->y, parentInfo->height) * element->yModifier; //The second corner of the window tempSecondArray[0] = tempArray[0] + floatWidth * element->xModifier; tempSecondArray[1] = element->originPosition[1] + element->rendering->GetRelativeFloat1D(window->y + window->height, parentInfo->height) * element->yModifier; break; } float topLeft[2]; //Work out the co-ordinates of the bottom left and top right of the //textbox. if (tempArray[0] < tempSecondArray[0]) { topLeft[0] = tempArray[0]; } else { topLeft[0] = tempSecondArray[0]; } if (tempArray[1] < tempSecondArray[1]) { topLeft[1] = tempSecondArray[1]; } else { topLeft[1] = tempArray[1]; } float x = topLeft[0]; float y = topLeft[1]; int Length = strlen(String); //Begin rendering quads glBegin(GL_TRIANGLE_STRIP); glColor4ub( element->borderColour[0], element->borderColour[1], element->borderColour[2], element->borderColour[3]); //Loop through characters for (int i = 0; i < Length; i++) { //Get pointer to glFont character GLFONTCHAR *Char = &Font.Char[(int)String[i] - Font.IntStart]; float dx = Char->dx*size; float dy = Char->dy*size; //Specify vertices and texture coordinates glTexCoord2f(Char->tx1, Char->ty2); glVertex2f(x, y - dy); glTexCoord2f(Char->tx1, Char->ty1); glVertex2f(x, y); glTexCoord2f(Char->tx2, Char->ty2); glVertex2f(x + dx, y - dy); glTexCoord2f(Char->tx2, Char->ty1); glVertex2f(x + dx, y); //Move to next character x += dx; } //Stop rendering quads glEnd(); }
void display(Uint8* data, int width, int height, const gameswf::matrix* m, const gameswf::rect* bounds, const gameswf::rgba& color) { // this can't be placed in constructor becuase opengl may not be accessible yet if (m_texture == 0) { glEnable(GL_TEXTURE_2D); glGenTextures(1, &m_texture); glBindTexture(GL_TEXTURE_2D, m_texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // GL_NEAREST ? glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); } glBindTexture(GL_TEXTURE_2D, m_texture); glEnable(GL_TEXTURE_2D); // glDisable(GL_TEXTURE_GEN_S); // glDisable(GL_TEXTURE_GEN_T); // update texture from video frame if (data) { int w2p = p2(width); int h2p = p2(height); m_scoord = (float) width / w2p; m_tcoord = (float) height / h2p; if (m_clear_background) { // set video background color // assume left-top pixel of the first frame as background color if (m_background_color.m_a == 0) { m_background_color.m_a = 255; m_background_color.m_r = data[2]; m_background_color.m_g = data[1]; m_background_color.m_b = data[0]; } // clear video background, input data has BGRA format Uint8* p = data; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { // calculate color distance, dist is in [0..195075] int r = m_background_color.m_r - p[2]; int g = m_background_color.m_g - p[1]; int b = m_background_color.m_b - p[0]; float dist = (float) (r * r + g * g + b * b); static int s_min_dist = 3 * 64 * 64; // hack Uint8 a = (dist < s_min_dist) ? (Uint8) (255 * (dist / s_min_dist)) : 255; p[3] = a; // set alpha p += 4; } } } // don't use compressed texture for video, it slows down video // ogl::create_texture(GL_RGBA, m_width2p, m_height2p, NULL); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w2p, h2p, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); //TODO - pete - GL_BGRA undefined in IWGL? swapping to GL_RGBA //glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_BGRA, GL_UNSIGNED_BYTE, data); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data); } if (m_scoord == 0.0f && m_scoord == 0.0f) { // no data return; } gameswf::point a, b, c, d; m->transform(&a, gameswf::point(bounds->m_x_min, bounds->m_y_min)); m->transform(&b, gameswf::point(bounds->m_x_max, bounds->m_y_min)); m->transform(&c, gameswf::point(bounds->m_x_min, bounds->m_y_max)); d.m_x = b.m_x + c.m_x - a.m_x; d.m_y = b.m_y + c.m_y - a.m_y; glColor4ub(color.m_r, color.m_g, color.m_b, color.m_a); // glBegin(GL_TRIANGLE_STRIP); // { // glTexCoord2f(0, 0); // glVertex2f(a.m_x, a.m_y); // glTexCoord2f(m_scoord, 0); // glVertex2f(b.m_x, b.m_y); // glTexCoord2f(0, m_tcoord); // glVertex2f(c.m_x, c.m_y); // glTexCoord2f(m_scoord, m_tcoord); // glVertex2f(d.m_x, d.m_y); // } // glEnd(); // this code is equal to code that above GLfloat squareVertices[8]; squareVertices[0] = a.m_x; squareVertices[1] = a.m_y; squareVertices[2] = b.m_x; squareVertices[3] = b.m_y; squareVertices[4] = c.m_x; squareVertices[5] = c.m_y; squareVertices[6] = d.m_x; squareVertices[7] = d.m_y; GLfloat squareTextureCoords[8]; squareTextureCoords[0] = 0; squareTextureCoords[1] = 0; squareTextureCoords[2] = m_scoord; squareTextureCoords[3] = 0; squareTextureCoords[4] = 0; squareTextureCoords[5] = m_tcoord; squareTextureCoords[6] = m_scoord; squareTextureCoords[7] = m_tcoord; glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, 0, squareTextureCoords); glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(2, GL_FLOAT, 0, squareVertices); glEnable(GL_LINE_SMOOTH); glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDisable(GL_LINE_SMOOTH); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); glDisable(GL_TEXTURE_2D); }
int main(int argc, char *argv[]) { const SDL_VideoInfo* video = NULL; bool bQuit = false; if( g_Screen.initialize() < 0 ) { fprintf(stderr, "Video initialization failed: %s\n", SDL_GetError()); SDL_Quit(); exit(1); } video = SDL_GetVideoInfo(); if( !video ) { fprintf(stderr, "Video query failed: %s\n", SDL_GetError()); SDL_Quit(); exit(1); } SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 1); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); g_Screen.m_bpp = video->vfmt->BitsPerPixel; fprintf(stderr, "BPP %d\n", video->vfmt->BitsPerPixel); if (g_Screen.m_bpp == 16) { fprintf(stderr, "WARNING:Running at 16bit expecting decreased performance\nChanging Desktop depth to 32bit may correct this problem\n"); } g_Screen.m_flags = SDL_OPENGL | SDL_HWSURFACE | SDL_RESIZABLE; g_Screen.m_width = 800; g_Screen.m_height = 600; g_Screen.m_useVBO = false; //flags |= SDL_FULLSCREEN; if( !g_Screen.setVideoMode() ) { fprintf(stderr, "Video mode set failed: %s", SDL_GetError()); SDL_Quit(); exit(1); } SDL_WM_SetCaption("Pie Toaster powered by AntTweakBar+SDL", "WZ Stats Tools"); // Enable SDL unicode and key-repeat SDL_EnableUNICODE(1); SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); // Set OpenGL viewport and states glViewport(0, 0, g_Screen.m_width, g_Screen.m_height); glEnable(GL_DEPTH_TEST); glEnable(GL_TEXTURE_2D); //glEnable(GL_LIGHTING); //glEnable(GL_LIGHT0); // use default light diffuse and position //glEnable(GL_NORMALIZE); //glEnable(GL_COLOR_MATERIAL); glDisable(GL_CULL_FACE); //glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); glShadeModel(GL_SMOOTH); // Initialize AntTweakBar TwInit(TW_OPENGL, NULL); /// pie vertex type TwStructMember vertice3fMembers[] = { { "X", TW_TYPE_FLOAT, offsetof(_vertice_list, vertice.x), "step=0.1" }, { "Y", TW_TYPE_FLOAT, offsetof(_vertice_list, vertice.y), "step=0.1" }, { "Z", TW_TYPE_FLOAT, offsetof(_vertice_list, vertice.z), "step=0.1" }, { "Selected", TW_TYPE_BOOLCPP, offsetof(_vertice_list, selected), "" }, }; g_tw_pieVertexType = TwDefineStruct("VerticePie", vertice3fMembers, 4, sizeof(_vertice_list), NULL, NULL); TwStructMember vector2fMembers[] = { { "X", TW_TYPE_FLOAT, offsetof(Vector2f, x), "min=0 max=4096 step=1" }, { "Y", TW_TYPE_FLOAT, offsetof(Vector2f, y), "min=0 max=4096 step=1" }, }; g_tw_pieVector2fType = TwDefineStruct("Vector2fPie", vector2fMembers, 2, sizeof(Vector2f), NULL, NULL); // Tell the window size to AntTweakBar TwWindowSize(g_Screen.m_width, g_Screen.m_height); iIMDShape *testIMD = NULL; //ResMaster = new CResMaster; ResMaster.getOGLExtensionString(); if (ResMaster.isOGLExtensionAvailable("GL_ARB_vertex_buffer_object")) { g_Screen.initializeVBOExtension(); } ResMaster.cacheGridsVertices(); ResMaster.readTextureList("pages.txt"); ResMaster.loadTexPages(); ResMaster.addGUI(); #ifdef SDL_TTF_TEST if (!(ResMaster.initFont() && ResMaster.loadFont("FreeMono.ttf", 12))) { return 1; } #endif //argc = 2; //argv[1] = "building1b.pie"; if (argc < 2) { fprintf(stderr, "NOTE:no file specified\n"); //ResMaster.addPie(testIMD, "newpie"); //No need to add new pie for now } else { testIMD = iV_ProcessIMD(argv[1]); if (testIMD == NULL) { fprintf(stderr, "no file specified\n creating new one...\n"); ResMaster.addPie(testIMD, "newpie"); } else { ResMaster.addPie(testIMD, argv[1]); } } //ResMaster.getPieAt(0)->ToFile("test13.pie"); OpenFileDialog.m_Up = false; while( !bQuit ) { SDL_Event event; int handled; glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); // Set OpenGL camera glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(30, (double)g_Screen.m_width/g_Screen.m_height, 1, 1000); gluLookAt(0,0,250, 0,0,0, 0,1,0); //updateBars(); inputUpdate(); // Process incoming events while( SDL_PollEvent(&event) ) { if (OpenFileDialog.m_Up) { if (event.type == SDL_KEYDOWN) { Uint16 key = event.key.keysym.sym; SDLMod modifier = event.key.keysym.mod; if (key == SDLK_BACKSPACE) { OpenFileDialog.decrementChar(); } else if (key == SDLK_KP_ENTER || key == SDLK_RETURN) { OpenFileDialog.doFunction(); OpenFileDialog.deleteTextBox(); continue; } else if (key == SDLK_PAUSE || key == SDLK_ESCAPE) { //cancels current action and closes text box //OpenFileDialog.text_pointer = NULL; OpenFileDialog.deleteTextBox(); continue; } else if (key > 12 && key < 128) { if (modifier & KMOD_CAPS || modifier & KMOD_LSHIFT || modifier & KMOD_RSHIFT) { if (key >= 'a' && key <= 'z') { key = toupper(key); } else { key = shiftChar(key); } } OpenFileDialog.incrementChar(key); } OpenFileDialog.updateTextBox(); //interrupts input when text box is up continue; } } else if (AddSubModelDialog.m_Up) { if (event.type == SDL_KEYDOWN) { Uint16 key = event.key.keysym.sym; SDLMod modifier = event.key.keysym.mod; if (key == SDLK_BACKSPACE) { AddSubModelDialog.decrementChar(); } else if (key == SDLK_KP_ENTER || key == SDLK_RETURN) { AddSubModelDialog.doFunction(); AddSubModelDialog.deleteTextBox(); continue; } else if (key == SDLK_PAUSE || key == SDLK_ESCAPE) { //cancels current action and closes text box //OpenFileDialog.text_pointer = NULL; AddSubModelDialog.deleteTextBox(); continue; } else if (key > 12 && key < 128) { if (modifier & KMOD_CAPS || modifier & KMOD_LSHIFT || modifier & KMOD_RSHIFT) { if (key >= 'a' && key <= 'z') { key = toupper(key); } else { key = shiftChar(key); } } AddSubModelDialog.incrementChar(key); } AddSubModelDialog.updateTextBox(); //interrupts input when text box is up continue; } } else if (AddSubModelFileDialog.m_Up) { if (event.type == SDL_KEYDOWN) { Uint16 key = event.key.keysym.sym; SDLMod modifier = event.key.keysym.mod; if (key == SDLK_BACKSPACE) { AddSubModelFileDialog.decrementChar(); } else if (key == SDLK_KP_ENTER || key == SDLK_RETURN) { AddSubModelFileDialog.doFunction(); AddSubModelFileDialog.deleteTextBox(); continue; } else if (key == SDLK_PAUSE || key == SDLK_ESCAPE) { //cancels current action and closes text box //OpenFileDialog.text_pointer = NULL; AddSubModelFileDialog.deleteTextBox(); continue; } else if (key > 12 && key < 128) { if (modifier & KMOD_CAPS || modifier & KMOD_LSHIFT || modifier & KMOD_RSHIFT) { if (key >= 'a' && key <= 'z') { key = toupper(key); } else { key = shiftChar(key); } } AddSubModelFileDialog.incrementChar(key); } AddSubModelFileDialog.updateTextBox(); //interrupts input when text box is up continue; } } else if (ReadAnimFileDialog.m_Up) { if (event.type == SDL_KEYDOWN) { Uint16 key = event.key.keysym.sym; SDLMod modifier = event.key.keysym.mod; if (key == SDLK_BACKSPACE) { ReadAnimFileDialog.decrementChar(); } else if (key == SDLK_KP_ENTER || key == SDLK_RETURN) { ReadAnimFileDialog.doFunction(); ReadAnimFileDialog.deleteTextBox(); continue; } else if (key == SDLK_PAUSE || key == SDLK_ESCAPE) { //cancels current action and closes text box //OpenFileDialog.text_pointer = NULL; ReadAnimFileDialog.deleteTextBox(); continue; } else if (key > 12 && key < 128) { if (modifier & KMOD_CAPS || modifier & KMOD_LSHIFT || modifier & KMOD_RSHIFT) { if (key >= 'a' && key <= 'z') { key = toupper(key); } else { key = shiftChar(key); } } ReadAnimFileDialog.incrementChar(key); } ReadAnimFileDialog.updateTextBox(); //interrupts input when text box is up continue; } } else if (WriteAnimFileDialog.m_Up) { if (event.type == SDL_KEYDOWN) { Uint16 key = event.key.keysym.sym; SDLMod modifier = event.key.keysym.mod; if (key == SDLK_BACKSPACE) { WriteAnimFileDialog.decrementChar(); } else if (key == SDLK_KP_ENTER || key == SDLK_RETURN) { WriteAnimFileDialog.doFunction(); WriteAnimFileDialog.deleteTextBox(); continue; } else if (key == SDLK_PAUSE || key == SDLK_ESCAPE) { //cancels current action and closes text box //OpenFileDialog.text_pointer = NULL; WriteAnimFileDialog.deleteTextBox(); continue; } else if (key > 12 && key < 128) { if (modifier & KMOD_CAPS || modifier & KMOD_LSHIFT || modifier & KMOD_RSHIFT) { if (key >= 'a' && key <= 'z') { key = toupper(key); } else { key = shiftChar(key); } } WriteAnimFileDialog.incrementChar(key); } WriteAnimFileDialog.updateTextBox(); //interrupts input when text box is up continue; } } if (event.type == SDL_KEYDOWN) { Uint16 key = event.key.keysym.sym; SDLMod modifier = event.key.keysym.mod; if ((key == SDLK_KP_ENTER || key == SDLK_RETURN) && modifier & KMOD_LALT) { // Resize SDL video mode g_Screen.m_flags ^= SDL_FULLSCREEN; if( !g_Screen.setVideoMode() ) fprintf(stderr, "WARNING: Video mode set failed: %s", SDL_GetError()); // Resize OpenGL viewport glViewport(0, 0, g_Screen.m_width, g_Screen.m_height); if (ResMaster.isTextureMapperUp()) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, g_Screen.m_width, 0, g_Screen.m_height, -1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } else { // Restore OpenGL states (SDL seems to lost them) glEnable(GL_DEPTH_TEST); glEnable(GL_TEXTURE_2D); gluPerspective(30, (double)g_Screen.m_width/g_Screen.m_height, 1, 1000); gluLookAt(0,0,250, 0,0,0, 0,1,0); //glEnable(GL_LIGHTING); //glEnable(GL_LIGHT0); //glEnable(GL_NORMALIZE); //glEnable(GL_COLOR_MATERIAL); } glDisable(GL_CULL_FACE); //glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); // Reloads texture and bind ResMaster.freeTexPages(); ResMaster.loadTexPages(); ResMaster.cacheGridsVertices(); // Flush vbo id's Uint32 index; for (index = 0;index < ResMaster.m_pieCount;index++) { ResMaster.getPieAt(index)->flushVBOPolys(); } SDL_Event newEvent; newEvent.type = SDL_VIDEORESIZE; newEvent.resize.w = g_Screen.m_width; newEvent.resize.h = g_Screen.m_height; SDL_PushEvent(&newEvent); } } // Send event to AntTweakBar handled = TwEventSDL(&event); // If event has not been handled by AntTweakBar, process it if( !handled ) { switch( event.type ) { case SDL_KEYUP: case SDL_KEYDOWN: inputKeyEvent(event.key, event.type); break; case SDL_MOUSEMOTION: inputMotionMouseEvent(event.motion); break; case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONDOWN: inputButtonMouseEvent(event.button, event.type); break; case SDL_QUIT: // Window is closed bQuit = true; break; case SDL_VIDEORESIZE: // Window size has changed // Resize SDL video mode g_Screen.m_width = event.resize.w; g_Screen.m_height = event.resize.h; if( !g_Screen.setVideoMode() ) fprintf(stderr, "WARNING: Video mode set failed: %s", SDL_GetError()); // Resize OpenGL viewport glViewport(0, 0, g_Screen.m_width, g_Screen.m_height); if (ResMaster.isTextureMapperUp()) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, g_Screen.m_width, 0, g_Screen.m_height, -1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } else { // Restore OpenGL states (SDL seems to lost them) glEnable(GL_DEPTH_TEST); glEnable(GL_TEXTURE_2D); gluPerspective(30, (double)g_Screen.m_width/g_Screen.m_height, 1, 1000); gluLookAt(0,0,250, 0,0,0, 0,1,0); //glEnable(GL_LIGHTING); //glEnable(GL_LIGHT0); //glEnable(GL_NORMALIZE); //glEnable(GL_COLOR_MATERIAL); } glDisable(GL_CULL_FACE); //glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); // Reloads texture and bind ResMaster.freeTexPages(); ResMaster.loadTexPages(); ResMaster.cacheGridsVertices(); // Flush vbo id's Uint32 index; for (index = 0;index < ResMaster.m_pieCount;index++) { ResMaster.getPieAt(index)->flushVBOPolys(); } // TwWindowSize has been called by TwEventSDL, so it is not necessary to call it again here. break; } } else { // Resets all keys and buttons inputInitialize(); // Input in TwBars rebuilds vbo's switch( event.type ) { case SDL_KEYUP: case SDL_KEYDOWN: case SDL_MOUSEMOTION: case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONDOWN: // Flush vbo id's Uint32 index; for (index = 0;index < ResMaster.m_pieCount;index++) { CPieInternal *temp = ResMaster.getPieAt(index); if (temp) { temp->flushVBOPolys(); } } break; default: break; } } } glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0f,0.0f,0.0f); glColor4ub(255, 255, 255, 255); ResMaster.logic(); ResMaster.draw(); ResMaster.updateInput(); // Draw tweak bars TwDraw(); // Present frame buffer SDL_GL_SwapBuffers(); SDL_Delay(10); } // Remove TW bars //removeBars(); // Terminate AntTweakBar TwTerminate(); // Terminate SDL SDL_Quit(); ResMaster.~CResMaster(); return 1; }
static void cdfpoly(cdCtxCanvas *ctxcanvas, int mode, cdfPoint* poly, int n) { int i; if (mode == CD_CLIP) return; if (mode == CD_BEZIER) { int i, prec = 100; double* points = (double*)malloc(n * 3 * sizeof(double)); for(i = 0; i < n; i++) { points[i*3+0] = poly[i].x; points[i*3+1] = poly[i].y; points[i*3+2] = 0; } glMap1d(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, n, points); glEnable(GL_MAP1_VERTEX_3); glMapGrid1d(prec, 0.0, 1.0); glEvalMesh1(GL_LINE, 0, prec); glDisable(GL_MAP1_VERTEX_3); free(points); return; } if (mode == CD_PATH) { cdfSimPolyPath(ctxcanvas->canvas, poly, n); return; } switch (mode) { case CD_CLOSED_LINES : glBegin(GL_LINE_LOOP); break; case CD_OPEN_LINES : glBegin(GL_LINE_STRIP); break; case CD_FILL : if(ctxcanvas->canvas->back_opacity == CD_OPAQUE && glIsEnabled(GL_POLYGON_STIPPLE)) { glDisable(GL_POLYGON_STIPPLE); glColor4ub(cdRed(ctxcanvas->canvas->background), cdGreen(ctxcanvas->canvas->background), cdBlue(ctxcanvas->canvas->background), cdAlpha(ctxcanvas->canvas->background)); glBegin(GL_POLYGON); for(i = 0; i < n; i++) glVertex2d(poly[i].x, poly[i].y); glEnd(); /* restore the foreground color */ glColor4ub(cdRed(ctxcanvas->canvas->foreground), cdGreen(ctxcanvas->canvas->foreground), cdBlue(ctxcanvas->canvas->foreground), cdAlpha(ctxcanvas->canvas->foreground)); glEnable(GL_POLYGON_STIPPLE); } glBegin(GL_POLYGON); break; } for(i = 0; i < n; i++) glVertex2d(poly[i].x, poly[i].y); glEnd(); (void)ctxcanvas; }
void render(Game *game) { if(!start_flag) { float w, h; glClear(GL_COLOR_BUFFER_BIT); //Pop default matrix onto current matrix glMatrixMode(GL_MODELVIEW); //Save default matrix again glPushMatrix(); //push ragdoll matrix glTranslatef(0.f, gCameraY, 0.f); //Vec *c = &game->character.s.center; w = 49; h = 79; glColor3f(1.0, 1.0, 1.0); if (sky) { glBindTexture(GL_TEXTURE_2D, skyTexture); glBegin(GL_QUADS); int ybottom = game->altitude - yres; glTexCoord2f(0.0f, 1.0f); glVertex2i(0, ybottom); glTexCoord2f(0.0f, 0.0f); glVertex2i(0, game->altitude); glTexCoord2f(1.0f, 0.0f); glVertex2i(xres, game->altitude); glTexCoord2f(1.0f, 1.0f); glVertex2i(xres, ybottom); glEnd(); } //glBindTexture(GL_TEXTURE_2D, characterTexture); glBindTexture(GL_TEXTURE_2D, silhouetteTexture); glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_GREATER, 0.0f); glColor4ub(255,255,255,255); glBegin(GL_QUADS); /* if (game->character.velocity.x < 0) { glTexCoord2f(0.0f, 1.0f); glVertex2i(c->x-w, c->y-h); glTexCoord2f(0.0f, 0.0f); glVertex2i(c->x-w, c->y+h); glTexCoord2f(0.5f, 0.0f); glVertex2i(c->x+w, c->y+h); glTexCoord2f(0.5f, 1.0f); glVertex2i(c->x+w, c->y-h); } if (game->character.velocity.x >= 0) { glTexCoord2f(0.5f, 1.0f); glVertex2i(c->x-w, c->y-h); glTexCoord2f(0.5f, 0.0f); glVertex2i(c->x-w, c->y+h); glTexCoord2f(1.0f, 0.0f); glVertex2i(c->x+w, c->y+h); glTexCoord2f(1.0f, 1.0f); glVertex2i(c->x+w, c->y-h); } glEnd(); */ int i = STARTING_ALTITUDE; while (i > 0) { if ((game->altitude < (i + 400)) && (game->altitude > (i - 400))) { Rect r; char cstr[10]; r.left = xres - 50; r.bot = i - yres/2; r.center = xres - 50; r.width = 500; r.height = 100; sprintf (cstr, "%d", i); strcat (cstr, "ft"); ggprint16(&r, 16, 0xdd4814, "%s", cstr); } i = i - 100; } //glPopMatrix(); //draw body glPushMatrix(); Shape *s1 = &game->body; glColor3ubv(s1->color); glTranslatef(s1->center[0], s1->center[1], 0.0f); //glRotatef(-s1->rot, 0.0f, 0.1f, 0.0f); w = s1->width; h = s1->height/2.0; glBegin(GL_QUADS); glVertex2i(-w, -h); glVertex2i(-w, h); glVertex2i( w, h); glVertex2i( w, -h); glEnd(); //head w = s1->width - 10; h = 20; glBegin(GL_QUADS); glVertex2f(-(float)w, h+5); glVertex2f(-(float)w, h+30); glVertex2f( (float)w, h+30); glVertex2f( (float)w, h+5); glEnd(); // //draw right arm --------------------------------------------------------- glPushMatrix(); Shape *s2 = &game->rarm1; glColor3ubv(s2->color); glTranslatef(s2->center[0], s2->center[1], 0.0f); glRotatef(-s2->rot, 0.0f, 0.0f, 1.0f); w = s2->width; h = s2->height; glBegin(GL_QUADS); glVertex2i(-w, 0); glVertex2i(-w, h); glVertex2i( w, h); glVertex2i( w, 0); glEnd(); // //draw lower arm --------------------------------------------------------- Shape *s3 = &game->rarm2; glColor3ubv(s3->color); glTranslatef(s3->center[0], s3->center[1], 0.0f); glRotatef(-s3->rot, 0.0f, 0.0f, 1.0f); w = s3->width; h = s3->height; glBegin(GL_QUADS); glVertex2i(-w, 0); glVertex2i(-w, h); glVertex2i( w, h); glVertex2i( w, 0); glEnd(); glPopMatrix(); // //draw left arm glPushMatrix(); Shape *s4 = &game->larm1; glColor3ubv(s4->color); glTranslatef(s4->center[0]+20, s4->center[1]+20, 0.0f); glRotatef(-s4->rot, 0.0f, 0.0f, 1.0f); w = s4->width; h = s4->height; glBegin(GL_QUADS); glVertex2i(-w, 0); glVertex2i(-w, h); glVertex2i( w, h); glVertex2i( w, 0); glEnd(); //draw lower left arm Shape *s5 = &game->larm2; glColor3ubv(s5->color); glTranslatef(s5->center[0], s5->center[1], 0.0f); glRotatef(-s5->rot, 0.0f, 0.0f, 1.0f); w = s5->width; h = s5->height; glBegin(GL_QUADS); glVertex2i(-w, 0); glVertex2i(-w, h); glVertex2i( w, h); glVertex2i( w, 0); glEnd(); glPopMatrix(); //draw right quad glPushMatrix(); Shape *s6 = &game->rleg1; glColor3ubv(s6->color); glTranslatef(s6->center[0], s6->center[1]-43, 0.0f); glRotatef(-s6->rot-105, 0.0f, 0.0f, 1.0f); w = s6->width; h = s6->height+5; glBegin(GL_QUADS); glVertex2i(-w, 0); glVertex2i(-w, h); glVertex2i( w, h); glVertex2i( w, 0); glEnd(); //draw right shin Shape *s7 = &game->rleg2; glColor3ubv(s7->color); glTranslatef(s7->center[0], s7->center[1]+8, 0.0f); glRotatef(-s7->rot-75, 0.0f, 0.0f, 1.0f); glRotatef(0.0, 1.0f, 0.0f, 0.0f); w = s7->width; h = s7->height+5; glBegin(GL_QUADS); glVertex2i(-w, 0); glVertex2i(-w, h); glVertex2i( w, h); glVertex2i( w, 0); glEnd(); glPopMatrix(); //draw left quad glPushMatrix(); Shape *s8 = &game->lleg1; glColor3ubv(s8->color); glTranslatef(s8->center[0]+20, s8->center[1]-23, 0.0f); glRotatef(-s8->rot+150, 0.0f, 0.0f, 1.0f); w = s8->width; h = s8->height+5; glBegin(GL_QUADS); glVertex2i(-w, 0); glVertex2i(-w, h); glVertex2i( w, h); glVertex2i( w, 0); glEnd(); //draw left shin Shape *s9 = &game->lleg2; glColor3ubv(s9->color); glTranslatef(s9->center[0], s9->center[1]+5, 0.0f); glRotatef(-s9->rot+70, 0.0f, 0.0f, 1.0f); glRotatef(0.0, 1.0f, 0.0f, 0.0f); w = s9->width; h = s9->height+5; glBegin(GL_QUADS); glVertex2i(-w, 0); glVertex2i(-w, h); glVertex2i( w, h); glVertex2i( w, 0); glEnd(); glPopMatrix(); glPopMatrix(); //pop body matrix glPopMatrix(); w = 3; h = 3; Vec v0 = {s2->center[0], s2->center[1], 0.0}; Vec v1; //rotate the shoulder by the body rotation. trans_vector(s1->m, v0, v1); glColor3ub(255,255,255); //offset shoulder by body position v1[0] += s1->center[0]; v1[1] += s1->center[1]; //rotate left arm Vec v5 = {s4->center[0]+20, s4->center[1]+20, 0.0}; Vec v7; trans_vector(s1->m, v5, v7); glColor3ub(255,255,255); //offset shoulder by body position v7[0] += s1->center[0]; v7[1] += s1->center[1]; //rotate right quad Vec v8 = {s6->center[0]-20, s6->center[1]-20, 0.0}; Vec v10; trans_vector(s1->m, v8, v10); glColor3ub(255,255,255); //offset hip by body position v10[0] += s1->center[0]; v10[1] += s1->center[1]; //rotate left quad Vec v11 = {s8->center[0]+20, s8->center[1]-20, 0.0}; Vec v13; trans_vector(s1->m, v11, v13); glColor3ub(255,255,255); //offset hip by body position v13[0] += s1->center[0]; v13[1] += s1->center[1]; } if(start_flag) { glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); //glPopMatrix(); glPushMatrix(); glColor3f(1.0, 1.0, 1.0); if (sky) { glBindTexture(GL_TEXTURE_2D, skyTexture); glBegin(GL_QUADS); int ybottom = game->altitude - yres; glTexCoord2f(0.0f, 1.0f); glVertex2i(0, ybottom); glTexCoord2f(0.0f, 0.0f); glVertex2i(0, game->altitude); glTexCoord2f(1.0f, 0.0f); glVertex2i(xres, game->altitude); glTexCoord2f(1.0f, 1.0f); glVertex2i(xres, ybottom); glEnd(); } glPopMatrix(); Rect start; Rect click; start.centerx = xres/2; start.centery = game->altitude - 200; start.bot = game->altitude - 200; start.width = 500; start.height = 100; start.center = xres/2 + 200; start.left = start.centerx; start.right = start.centerx; start.top = game->altitude - 200; click.centerx = xres/2; click.centery = game->altitude - 400; click.bot = game->altitude - 400; click.width = 500; click.height = 100; click.center = xres/2; click.left = click.centerx; click.right = click.centerx; click.top = game->altitude - 400; ggprint16(&start, 1000, 0x00fff000, "PARASHOOT!"); ggprint16(&click, 1000, 0x00fff000, "Click to start"); } }
void RulerMark::glCommands(double units) { glDisable(GL_POLYGON_OFFSET_FILL); double half_width = width/2; double dpos = (double)pos; if(units > 25.0) { dpos *= 2.54; // position of the tenth of an inch, in mm } if(wxGetApp().GetPixelScale() < 10) { // draw a line glBegin(GL_LINES); glVertex2d(dpos, 0.0); glVertex2d(dpos, -length); glEnd(); } else { // draw triangles double p[5][3] = { {dpos, 0.0, 0.0}, {dpos - half_width, -half_width, 0.0}, {dpos - half_width, -length, 0.0}, {dpos + half_width, -length, 0.0}, {dpos + half_width, -half_width, 0.0} }; glBegin(GL_TRIANGLES); glVertex3dv(p[0]); glVertex3dv(p[1]); glVertex3dv(p[4]); glVertex3dv(p[1]); glVertex3dv(p[2]); glVertex3dv(p[4]); glVertex3dv(p[2]); glVertex3dv(p[3]); glVertex3dv(p[4]); glEnd(); } // draw text if(pos == 0) { wxString str = _T("cm"); if(units > 25.0)str = _T("inches"); glPushMatrix(); glTranslated(dpos + half_width, -length + 2.05, 0.0); glColor4ub(0, 0, 0, 255); wxGetApp().render_text(str); glPopMatrix(); } else if(pos % 10 == 0) { float text_width, text_height; wxString str = wxString::Format(_T("%d"), pos/10); if(!wxGetApp().get_text_size(str, &text_width, &text_height))return; glPushMatrix(); glTranslated(dpos - half_width - text_width, -length + 2.05, 0.0); wxGetApp().render_text(str); glPopMatrix(); } glEnable(GL_POLYGON_OFFSET_FILL); }
void CSlideShowPic::Render(float *x, float *y, CBaseTexture* pTexture, color_t color) { #ifdef HAS_DX static const DWORD FVF_VERTEX = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1; Vertex vertex[5]; for (int i = 0; i < 4; i++) { vertex[i].pos = XMFLOAT3( x[i], y[i], 0); CD3DHelper::XMStoreColor(&vertex[i].color, color); vertex[i].texCoord = XMFLOAT2(0.0f, 0.0f); vertex[i].texCoord2 = XMFLOAT2(0.0f, 0.0f); } if (pTexture) { vertex[1].texCoord.x = vertex[2].texCoord.x = (float) pTexture->GetWidth() / pTexture->GetTextureWidth(); vertex[2].texCoord.y = vertex[3].texCoord.y = (float) pTexture->GetHeight() / pTexture->GetTextureHeight(); } else { vertex[1].texCoord.x = vertex[2].texCoord.x = 1.0f; vertex[2].texCoord.y = vertex[3].texCoord.y = 1.0f; } vertex[4] = vertex[0]; // Not used when pTexture != NULL CGUIShaderDX* pGUIShader = g_Windowing.GetGUIShader(); pGUIShader->Begin(SHADER_METHOD_RENDER_TEXTURE_BLEND); // Set state to render the image if (pTexture) { pTexture->LoadToGPU(); CDXTexture* dxTexture = reinterpret_cast<CDXTexture*>(pTexture); ID3D11ShaderResourceView* shaderRes = dxTexture->GetShaderResource(); pGUIShader->SetShaderViews(1, &shaderRes); pGUIShader->DrawQuad(vertex[0], vertex[1], vertex[2], vertex[3]); } else { if (!UpdateVertexBuffer(vertex)) return; ID3D11DeviceContext* pContext = g_Windowing.Get3D11Context(); unsigned stride = sizeof(Vertex); unsigned offset = 0; pContext->IASetVertexBuffers(0, 1, &m_vb, &stride, &offset); pContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP); pGUIShader->Draw(5, 0); pGUIShader->RestoreBuffers(); } #elif defined(HAS_GL) if (pTexture) { int unit = 0; pTexture->LoadToGPU(); pTexture->BindToUnit(unit++); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); // Turn Blending On // diffuse coloring glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE); glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE0); glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR); glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PRIMARY_COLOR); glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR); if(g_Windowing.UseLimitedColor()) { // compress range pTexture->BindToUnit(unit++); // dummy bind const GLfloat rgba1[4] = {(235.0 - 16.0f) / 255.0f, (235.0 - 16.0f) / 255.0f, (235.0 - 16.0f) / 255.0f, 1.0f}; glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE , GL_COMBINE); glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, rgba1); glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB , GL_MODULATE); glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_RGB , GL_PREVIOUS); glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE1_RGB , GL_CONSTANT); glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB , GL_SRC_COLOR); glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_RGB , GL_SRC_COLOR); glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA , GL_REPLACE); glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA , GL_PREVIOUS); // transition pTexture->BindToUnit(unit++); // dummy bind const GLfloat rgba2[4] = {16.0f / 255.0f, 16.0f / 255.0f, 16.0f / 255.0f, 0.0f}; glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE , GL_COMBINE); glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, rgba2); glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB , GL_ADD); glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_RGB , GL_PREVIOUS); glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE1_RGB , GL_CONSTANT); glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB , GL_SRC_COLOR); glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_RGB , GL_SRC_COLOR); glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA , GL_REPLACE); glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA , GL_PREVIOUS); } } else glDisable(GL_TEXTURE_2D); glPolygonMode(GL_FRONT_AND_BACK, pTexture ? GL_FILL : GL_LINE); glBegin(GL_QUADS); float u1 = 0, u2 = 1, v1 = 0, v2 = 1; if (pTexture) { u2 = (float)pTexture->GetWidth() / pTexture->GetTextureWidth(); v2 = (float)pTexture->GetHeight() / pTexture->GetTextureHeight(); } glColor4ub((GLubyte)GET_R(color), (GLubyte)GET_G(color), (GLubyte)GET_B(color), (GLubyte)GET_A(color)); glTexCoord2f(u1, v1); glVertex3f(x[0], y[0], 0); // Bottom-left vertex (corner) glColor4ub((GLubyte)GET_R(color), (GLubyte)GET_G(color), (GLubyte)GET_B(color), (GLubyte)GET_A(color)); glTexCoord2f(u2, v1); glVertex3f(x[1], y[1], 0); // Bottom-right vertex (corner) glColor4ub((GLubyte)GET_R(color), (GLubyte)GET_G(color), (GLubyte)GET_B(color), (GLubyte)GET_A(color)); glTexCoord2f(u2, v2); glVertex3f(x[2], y[2], 0); // Top-right vertex (corner) glColor4ub((GLubyte)GET_R(color), (GLubyte)GET_G(color), (GLubyte)GET_B(color), (GLubyte)GET_A(color)); glTexCoord2f(u1, v2); glVertex3f(x[3], y[3], 0); glEnd(); #elif defined(HAS_GLES) if (pTexture) { pTexture->LoadToGPU(); pTexture->BindToUnit(0); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); // Turn Blending On g_Windowing.EnableGUIShader(SM_TEXTURE); } else { glDisable(GL_TEXTURE_2D); g_Windowing.EnableGUIShader(SM_DEFAULT); } float u1 = 0, u2 = 1, v1 = 0, v2 = 1; if (pTexture) { u2 = (float)pTexture->GetWidth() / pTexture->GetTextureWidth(); v2 = (float)pTexture->GetHeight() / pTexture->GetTextureHeight(); } GLubyte col[4]; GLfloat ver[4][3]; GLfloat tex[4][2]; GLubyte idx[4] = {0, 1, 3, 2}; //determines order of triangle strip GLint posLoc = g_Windowing.GUIShaderGetPos(); GLint tex0Loc = g_Windowing.GUIShaderGetCoord0(); GLint uniColLoc= g_Windowing.GUIShaderGetUniCol(); glVertexAttribPointer(posLoc, 3, GL_FLOAT, 0, 0, ver); glVertexAttribPointer(tex0Loc, 2, GL_FLOAT, 0, 0, tex); glEnableVertexAttribArray(posLoc); glEnableVertexAttribArray(tex0Loc); // Setup Colour values col[0] = (GLubyte)GET_R(color); col[1] = (GLubyte)GET_G(color); col[2] = (GLubyte)GET_B(color); col[3] = (GLubyte)GET_A(color); for (int i=0; i<4; i++) { // Setup vertex position values ver[i][0] = x[i]; ver[i][1] = y[i]; ver[i][2] = 0.0f; } // Setup texture coordinates tex[0][0] = tex[3][0] = u1; tex[0][1] = tex[1][1] = v1; tex[1][0] = tex[2][0] = u2; tex[2][1] = tex[3][1] = v2; glUniform4f(uniColLoc,(col[0] / 255.0f), (col[1] / 255.0f), (col[2] / 255.0f), (col[3] / 255.0f)); glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, idx); glDisableVertexAttribArray(posLoc); glDisableVertexAttribArray(tex0Loc); g_Windowing.DisableGUIShader(); #else // SDL render g_Windowing.BlitToScreen(m_pImage, NULL, NULL); #endif }
static void draw_seq_extensions(Scene *scene, ARegion *ar, Sequence *seq) { float x1, x2, y1, y2, pixely, a; unsigned char col[3], blendcol[3]; View2D *v2d= &ar->v2d; if(seq->type >= SEQ_EFFECT) return; x1= seq->startdisp; x2= seq->enddisp; y1= seq->machine+SEQ_STRIP_OFSBOTTOM; y2= seq->machine+SEQ_STRIP_OFSTOP; pixely = (v2d->cur.ymax - v2d->cur.ymin)/(v2d->mask.ymax - v2d->mask.ymin); if(pixely <= 0) return; /* can happen when the view is split/resized */ blendcol[0] = blendcol[1] = blendcol[2] = 120; if(seq->startofs) { glEnable( GL_BLEND ); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); get_seq_color3ubv(scene, seq, col); if (seq->flag & SELECT) { UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.3, -40); glColor4ub(col[0], col[1], col[2], 170); } else { UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.6, 0); glColor4ub(col[0], col[1], col[2], 110); } glRectf((float)(seq->start), y1-SEQ_STRIP_OFSBOTTOM, x1, y1); if (seq->flag & SELECT) glColor4ub(col[0], col[1], col[2], 255); else glColor4ub(col[0], col[1], col[2], 160); fdrawbox((float)(seq->start), y1-SEQ_STRIP_OFSBOTTOM, x1, y1); //outline glDisable( GL_BLEND ); } if(seq->endofs) { glEnable( GL_BLEND ); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); get_seq_color3ubv(scene, seq, col); if (seq->flag & SELECT) { UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.3, -40); glColor4ub(col[0], col[1], col[2], 170); } else { UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.6, 0); glColor4ub(col[0], col[1], col[2], 110); } glRectf(x2, y2, (float)(seq->start+seq->len), y2+SEQ_STRIP_OFSBOTTOM); if (seq->flag & SELECT) glColor4ub(col[0], col[1], col[2], 255); else glColor4ub(col[0], col[1], col[2], 160); fdrawbox(x2, y2, (float)(seq->start+seq->len), y2+SEQ_STRIP_OFSBOTTOM); //outline glDisable( GL_BLEND ); } if(seq->startstill) { get_seq_color3ubv(scene, seq, col); UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.75, 40); glColor3ubv((GLubyte *)col); draw_shadedstrip(seq, col, x1, y1, (float)(seq->start), y2); /* feint pinstripes, helps see exactly which is extended and which isn't, * especially when the extension is very small */ if (seq->flag & SELECT) UI_GetColorPtrBlendShade3ubv(col, col, col, 0.0, 24); else UI_GetColorPtrShade3ubv(col, col, -16); glColor3ubv((GLubyte *)col); for(a=y1; a< y2; a+= pixely * 2.0f) { fdrawline(x1, a, (float)(seq->start), a); } } if(seq->endstill) { get_seq_color3ubv(scene, seq, col); UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.75, 40); glColor3ubv((GLubyte *)col); draw_shadedstrip(seq, col, (float)(seq->start+seq->len), y1, x2, y2); /* feint pinstripes, helps see exactly which is extended and which isn't, * especially when the extension is very small */ if (seq->flag & SELECT) UI_GetColorPtrShade3ubv(col, col, 24); else UI_GetColorPtrShade3ubv(col, col, -16); glColor3ubv((GLubyte *)col); for(a=y1; a< y2; a+= pixely * 2.0f) { fdrawline((float)(seq->start+seq->len), a, x2, a); } } }
void GfxOpenGL::drawModel(Model *m) { glEnable(GL_DEPTH_TEST); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f,(GLfloat)_screenWidth/(GLfloat)_screenHeight,0.01f,10.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glColor4ub(255, 255, 255, 255); gluLookAt( 0, 0, 1, 0, 0, 0, 0, 1, 0 ); glPushMatrix(); glTranslatef((_cameraX/(float)_screenWidth), -(_cameraY/(float)_screenHeight), (_cameraZ/(float)_screenHeight)); glRotatef(_rotY, 1, 0, 0); glRotatef(_rotX, 0, 1, 0); for (uint j = 0; j < m->_numPolygons; j++) { Polygon *p = &m->_polygons[j]; glBegin(GL_POLYGON); for (int i = 0; i < m->_polygons->_num; ++i) { uint32 vert = p->_data[i]; if (vert > m->_numVerticies || vert == 0) { break; } glColor4ub(_palette->_palette[p->_colour]._r, _palette->_palette[p->_colour]._g, _palette->_palette[p->_colour]._b, 255); Vertex *v = &m->_verticies[vert]; if (v->_bone == 0) { continue; } Math::Vector3d mv = v->getPos(m); Normal *n = &m->_normals[vert]; glNormal3f(n->_x, n->_y, n->_z); glVertex3fv(mv.getData()); } glEnd(); } for (uint j = 0; j < m->_numPoints; j++) { Point *p = &m->_points[j]; glColor4ub(_palette->_palette[p->_colour]._r, _palette->_palette[p->_colour]._g, _palette->_palette[p->_colour]._b, 255); Vertex *v1 = &m->_verticies[p->_v1]; Math::Vector3d vec1 = v1->getPos(m); Vertex *v2 = &m->_verticies[p->_v2]; Math::Vector3d vec2 = v2->getPos(m); glBegin(GL_LINES); glVertex3fv(vec1.getData()); glVertex3fv(vec2.getData()); glEnd(); } for (uint j = 0; j < m->_numSpheres; j++) { Sphere *s = &m->_spheres[j]; Vertex *v = &m->_verticies[s->_vertex]; Math::Vector3d vec = v->getPos(m); glColor4ub(_palette->_palette[s->_colour]._r, _palette->_palette[s->_colour]._g, _palette->_palette[s->_colour]._b, 255); glPushMatrix(); glTranslatef(vec.x(), vec.y(), vec.z()); drawSphere(s->_size, 8, 8); glPopMatrix(); } glPopMatrix(); glDisable(GL_DEPTH_TEST); }
void draw_image_seq(const bContext* C, Scene *scene, ARegion *ar, SpaceSeq *sseq, int cfra, int frame_ofs) { struct Main *bmain= CTX_data_main(C); struct ImBuf *ibuf= NULL; struct ImBuf *scope= NULL; struct View2D *v2d = &ar->v2d; int rectx, recty; float viewrectx, viewrecty; float render_size = 0.0; float proxy_size = 100.0; GLuint texid; GLuint last_texid; SeqRenderData context; render_size = sseq->render_size; if (render_size == 0) { render_size = scene->r.size; } else { proxy_size = render_size; } if (render_size < 0) { return; } viewrectx = (render_size*(float)scene->r.xsch)/100.0f; viewrecty = (render_size*(float)scene->r.ysch)/100.0f; rectx = viewrectx + 0.5f; recty = viewrecty + 0.5f; if (sseq->mainb == SEQ_DRAW_IMG_IMBUF) { viewrectx *= scene->r.xasp / scene->r.yasp; viewrectx /= proxy_size / 100.0f; viewrecty /= proxy_size / 100.0f; } if(frame_ofs == 0) { /* XXX TODO: take color from theme */ glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); } /* without this colors can flicker from previous opengl state */ glColor4ub(255, 255, 255, 255); UI_view2d_totRect_set(v2d, viewrectx + 0.5f, viewrecty + 0.5f); UI_view2d_curRect_validate(v2d); /* only initialize the preview if a render is in progress */ if(G.rendering) return; context = seq_new_render_data(bmain, scene, rectx, recty, proxy_size); if (special_seq_update) ibuf= give_ibuf_seq_direct(context, cfra + frame_ofs, special_seq_update); else if (!U.prefetchframes) // XXX || (G.f & G_PLAYANIM) == 0) { ibuf= (ImBuf *)give_ibuf_seq(context, cfra + frame_ofs, sseq->chanshown); else ibuf= (ImBuf *)give_ibuf_seq_threaded(context, cfra + frame_ofs, sseq->chanshown); if(ibuf==NULL) return; if(ibuf->rect==NULL && ibuf->rect_float == NULL) return; switch(sseq->mainb) { case SEQ_DRAW_IMG_IMBUF: if (sseq->zebra != 0) { scope = make_zebra_view_from_ibuf(ibuf, sseq->zebra); } break; case SEQ_DRAW_IMG_WAVEFORM: if ((sseq->flag & SEQ_DRAW_COLOR_SEPERATED) != 0) { scope = make_sep_waveform_view_from_ibuf(ibuf); } else { scope = make_waveform_view_from_ibuf(ibuf); } break; case SEQ_DRAW_IMG_VECTORSCOPE: scope = make_vectorscope_view_from_ibuf(ibuf); break; case SEQ_DRAW_IMG_HISTOGRAM: scope = make_histogram_view_from_ibuf(ibuf); break; } if (scope) { IMB_freeImBuf(ibuf); ibuf = scope; } if(ibuf->rect_float && ibuf->rect==NULL) { IMB_rect_from_float(ibuf); } /* setting up the view - actual drawing starts here */ UI_view2d_view_ortho(v2d); last_texid= glaGetOneInteger(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D); glGenTextures(1, (GLuint *)&texid); glBindTexture(GL_TEXTURE_2D, texid); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, ibuf->x, ibuf->y, 0, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect); glBegin(GL_QUADS); if(frame_ofs) { rctf tot_clip; tot_clip.xmin= v2d->tot.xmin + (ABS(v2d->tot.xmax - v2d->tot.xmin) * scene->ed->over_border.xmin); tot_clip.ymin= v2d->tot.ymin + (ABS(v2d->tot.ymax - v2d->tot.ymin) * scene->ed->over_border.ymin); tot_clip.xmax= v2d->tot.xmin + (ABS(v2d->tot.xmax - v2d->tot.xmin) * scene->ed->over_border.xmax); tot_clip.ymax= v2d->tot.ymin + (ABS(v2d->tot.ymax - v2d->tot.ymin) * scene->ed->over_border.ymax); glTexCoord2f(scene->ed->over_border.xmin, scene->ed->over_border.ymin); glVertex2f(tot_clip.xmin, tot_clip.ymin); glTexCoord2f(scene->ed->over_border.xmin, scene->ed->over_border.ymax); glVertex2f(tot_clip.xmin, tot_clip.ymax); glTexCoord2f(scene->ed->over_border.xmax, scene->ed->over_border.ymax); glVertex2f(tot_clip.xmax, tot_clip.ymax); glTexCoord2f(scene->ed->over_border.xmax, scene->ed->over_border.ymin); glVertex2f(tot_clip.xmax, tot_clip.ymin); } else { glTexCoord2f(0.0f, 0.0f); glVertex2f(v2d->tot.xmin, v2d->tot.ymin); glTexCoord2f(0.0f, 1.0f); glVertex2f(v2d->tot.xmin, v2d->tot.ymax); glTexCoord2f(1.0f, 1.0f); glVertex2f(v2d->tot.xmax, v2d->tot.ymax); glTexCoord2f(1.0f, 0.0f); glVertex2f(v2d->tot.xmax, v2d->tot.ymin); } glEnd( ); glBindTexture(GL_TEXTURE_2D, last_texid); glDisable(GL_TEXTURE_2D); glDeleteTextures(1, &texid); if(sseq->mainb == SEQ_DRAW_IMG_IMBUF) { float x1 = v2d->tot.xmin; float y1 = v2d->tot.ymin; float x2 = v2d->tot.xmax; float y2 = v2d->tot.ymax; /* border */ setlinestyle(3); UI_ThemeColorBlendShade(TH_WIRE, TH_BACK, 1.0, 0); glBegin(GL_LINE_LOOP); glVertex2f(x1-0.5f, y1-0.5f); glVertex2f(x1-0.5f, y2+0.5f); glVertex2f(x2+0.5f, y2+0.5f); glVertex2f(x2+0.5f, y1-0.5f); glEnd(); /* safety border */ if ((sseq->flag & SEQ_DRAW_SAFE_MARGINS) != 0) { float fac= 0.1; float a= fac*(x2-x1); x1+= a; x2-= a; a= fac*(y2-y1); y1+= a; y2-= a; glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); uiSetRoundBox(UI_CNR_ALL); uiDrawBox(GL_LINE_LOOP, x1, y1, x2, y2, 12.0); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); } setlinestyle(0); } /* draw grease-pencil (image aligned) */ // if (sseq->flag & SEQ_DRAW_GPENCIL) // XXX draw_gpencil_2dimage(sa, ibuf); IMB_freeImBuf(ibuf); /* draw grease-pencil (screen aligned) */ // if (sseq->flag & SEQ_DRAW_GPENCIL) // XXX draw_gpencil_view2d(sa, 0); /* ortho at pixel level */ UI_view2d_view_restore(C); }
void GfxOpenGL::drawBlock(Block *block, int32 x, int32 y, int32 z) { int xb = x; int yb = y; int zb = z; x = (xb - zb) * 24 + 288; y = ((xb + zb) * 12) - (yb * 15) + 215; GLuint texNum; if (block->_renderData == NULL) { block->_renderData = new GLint; glGenTextures(1, &texNum); *(GLuint *)(block->_renderData) = texNum; GLint format = GL_RGBA; GLint type = GL_UNSIGNED_BYTE; byte *pixels = new byte[block->_width * block->_height * 4]; for (int i = 0; i < block->_width * block->_height; ++i) { byte val = block->_data[i]; pixels[i*4 + 0] = _palette->_palette[val]._r; pixels[i*4 + 1] = _palette->_palette[val]._g; pixels[i*4 + 2] = _palette->_palette[val]._b; if (val == 0) { pixels[i*4 + 3] = 0; } else { pixels[i*4 + 3] = 255; } } glBindTexture(GL_TEXTURE_2D, texNum); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexImage2D(GL_TEXTURE_2D, 0, format, block->_width, block->_height, 0, format, type, pixels); } texNum = *(GLuint *)block->_renderData; int w = block->_width; int h = block->_height; x += block->_offsetX; y += block->_offsetY; if (x + _cameraX > _screenWidth || x + _cameraX < -48 || y + _cameraY > _screenHeight || y + _cameraY < -40) { return; } glColor4ub(255, 255, 255, 255); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, _screenWidth, _screenHeight, 0, 0, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_GREATER, 0.5); glDisable(GL_LIGHTING); glEnable(GL_TEXTURE_2D); glPushMatrix(); glTranslatef(_cameraX, _cameraY, 0.0f); glBindTexture(GL_TEXTURE_2D, texNum); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex2f(x * _scaleW, y * _scaleH); glTexCoord2f(1.0f, 0.0f); glVertex2f((x + w) * _scaleW, y * _scaleH); glTexCoord2f(1.0f, 1.0f); glVertex2f((x + w) * _scaleW, (y + h) * _scaleH); glTexCoord2f(0.0f, 1.0f); glVertex2f(x * _scaleW, (y + h) * _scaleH); glEnd(); glPopMatrix(); glDisable(GL_TEXTURE_2D); glDisable(GL_ALPHA_TEST); }
//=========================================================== void GlBox::draw(float lod,Camera *) { bool canUseGlew=OpenGlConfigManager::getInst().canUseGlew(); if(canUseGlew) { if(!generated) { GLfloat newCubeCoordArrays[72]; for(unsigned int i=0; i<24; ++i) { newCubeCoordArrays[i*3]=cubeCoordArrays[i*3]*size[0]+position[0]; newCubeCoordArrays[i*3+1]=cubeCoordArrays[i*3+1]*size[1]+position[1]; newCubeCoordArrays[i*3+2]=cubeCoordArrays[i*3+2]*size[2]+position[2]; } glGenBuffers(5,buffers); glBindBuffer(GL_ARRAY_BUFFER, buffers[0]); glBufferData(GL_ARRAY_BUFFER, sizeof(newCubeCoordArrays),newCubeCoordArrays, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, buffers[1]); glBufferData(GL_ARRAY_BUFFER, sizeof(cubeNormalArrays),cubeNormalArrays, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, buffers[2]); glBufferData(GL_ARRAY_BUFFER, sizeof(cubeTexArrays),cubeTexArrays, GL_STATIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[3]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(cubeIndices), cubeIndices, GL_STATIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[4]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(cubeOutlineIndices), cubeOutlineIndices, GL_STATIC_DRAW); generated=true; } } else { if(!generated) { newCubeCoordArrays= new GLfloat[72]; for(unsigned int i=0; i<24; ++i) { newCubeCoordArrays[i*3]=cubeCoordArrays[i*3]*size[0]+position[0]; newCubeCoordArrays[i*3+1]=cubeCoordArrays[i*3+1]*size[1]+position[1]; newCubeCoordArrays[i*3+2]=cubeCoordArrays[i*3+2]*size[2]+position[2]; } generated=true; } } glEnable(GL_LIGHTING); glEnableClientState(GL_VERTEX_ARRAY); if(canUseGlew) { glBindBuffer(GL_ARRAY_BUFFER, buffers[0]); glVertexPointer(3, GL_FLOAT, 3*sizeof(GLfloat), BUFFER_OFFSET(0)); } else { glVertexPointer(3, GL_FLOAT, 3*sizeof(GLfloat), newCubeCoordArrays); } if(filled) { setMaterial(fillColors[0]); glEnableClientState(GL_NORMAL_ARRAY); if(canUseGlew) { glBindBuffer(GL_ARRAY_BUFFER, buffers[1]); glNormalPointer(GL_FLOAT, 3*sizeof(GLfloat), BUFFER_OFFSET(0)); } else { glNormalPointer(GL_FLOAT, 3*sizeof(GLfloat), cubeNormalArrays); } if(textureName!="") { GlTextureManager::getInst().activateTexture(textureName); glEnableClientState(GL_TEXTURE_COORD_ARRAY); if(canUseGlew) { glBindBuffer(GL_ARRAY_BUFFER, buffers[2]); glTexCoordPointer(2,GL_FLOAT, 2*sizeof(GLfloat), BUFFER_OFFSET(0)); } else { glTexCoordPointer(2,GL_FLOAT, 2*sizeof(GLfloat), cubeTexArrays); } } OpenGlConfigManager::getInst().activatePolygonAntiAliasing(); if(canUseGlew) { glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[3]); glDrawElements(GL_QUADS, 24, GL_UNSIGNED_BYTE, BUFFER_OFFSET(0)); } else { glDrawElements(GL_QUADS, 24, GL_UNSIGNED_BYTE, cubeIndices); } OpenGlConfigManager::getInst().desactivatePolygonAntiAliasing(); glDisableClientState(GL_NORMAL_ARRAY); if(textureName!="") { GlTextureManager::getInst().desactivateTexture(); glDisableClientState(GL_TEXTURE_COORD_ARRAY); } } if(outlined && outlineSize!=0) { if((outlineSize<1 && lod>=20) || (lod>(20/outlineSize))) { glDisable(GL_LIGHTING); glColor4ub(outlineColors[0][0],outlineColors[0][1],outlineColors[0][2],outlineColors[0][3]); glLineWidth(outlineSize); OpenGlConfigManager::getInst().activateLineAndPointAntiAliasing(); if(canUseGlew) { glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[4]); glDrawElements(GL_LINES, 24, GL_UNSIGNED_BYTE, BUFFER_OFFSET(0)); } else { glDrawElements(GL_LINES, 24, GL_UNSIGNED_BYTE, cubeOutlineIndices); } OpenGlConfigManager::getInst().desactivateLineAndPointAntiAliasing(); glEnable(GL_LIGHTING); } } glDisableClientState(GL_VERTEX_ARRAY); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); }
void drawMissile(Game * game) { // if(!game->setMissiles) // return; if(!game->setMissiles) { if(game->missiles.numExp == -1) makeMissilesExp(game); else drawMissilesExp(game); return; } // used to allow non textures objects to maintain their color glBindTexture(GL_TEXTURE_2D, 0); //cout << "missile checked" << endl; float x = game->missiles.position.x; float y = game->missiles.position.y; // 12 missiles on spritesheet 1/12 is 0.083 float x_i = 1.0/12.0; // 3 missiles on spritesheet, 2 big 1 small // 1 big missiles has a height of 134px and spritetexture's height is 380 so 134/380 = 0.352... float y_i = 0.352632; float angle = game->missiles.angle; //cout << "angle :" << angle << endl; int wid = 3*game->player.width; int height = 2*game->player.height; drawThrust(angle, x, y, height); glPushMatrix(); glTranslatef(x, y, 0); glRotatef(angle,0,0.0,-1.0); //glBindTexture(GL_TEXTURE_2D, missileTexture); glBindTexture(GL_TEXTURE_2D, silhouetteTextureMissile); glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_GREATER, 0.0f); glColor4ub(255,255,255,255); int x_frame = game->missiles.nextframe; float toplvl = 0; if(game->missiles.nextframe > 23) { game->missiles.nextframe = 0; toplvl = 0; x_frame = 0; } else if(game->missiles.nextframe > 11) { //cout << x_frame << endl; toplvl = y_i; x_frame -= 12; } glBegin(GL_QUADS); glTexCoord2f( x_frame*x_i, toplvl + y_i); glVertex2i(-wid, -height); // bottom left glTexCoord2f( x_frame*x_i, toplvl); glVertex2i(-wid,height); //top left glTexCoord2f(x_i + x_frame*x_i,toplvl); glVertex2i( wid,height); // top right glTexCoord2f(x_i + x_frame*x_i, toplvl + y_i); glVertex2i( wid, -height); // bottom right glEnd(); glPopMatrix(); glDisable(GL_ALPHA_TEST); }