void AlignPairWidget::drawPickedPoints(std::vector<vcg::Point3f> &pointVec, vcg::Color4b color) { glPushAttrib(GL_ENABLE_BIT | GL_POINT_BIT | GL_CURRENT_BIT | GL_DEPTH_BUFFER_BIT); glDisable(GL_LIGHTING); glDisable(GL_TEXTURE); glDepthFunc(GL_ALWAYS); //glDisable(GL_DEPTH_TEST); for(uint i=0; i<pointVec.size();++i) { vcg::Point3f &pt =pointVec[i]; glPointSize(5.0); glColor(vcg::Color4b::Black); glBegin(GL_POINTS); glVertex(pt); glEnd(); glPointSize(3.0); glColor(color); glBegin(GL_POINTS); glVertex(pt); glEnd(); renderText( pt[0],pt[1],pt[2], QString("%1").arg(i) ); } glPopAttrib(); }
void UIRendering::uiRender() { Shader &shader = manager->getSystem<Files>()->loadFile<Shader>("shaders/UI/text"); // Enable blending glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Disable depth test glDisable(GL_DEPTH_TEST); // Use the text rendering shader shader.use(); // Set font texture location shader.setUniform("font", 0); // Get 1/2 screen size Display::Handle display = manager->getSystem<Display>(); float sx = 2.0f / display->getWidth(); float sy = 2.0f / display->getHeight(); // Render UILabels for (UILabel::Handle &label : manager->getWorld().entities.getAllComponents<UILabel>(true)) { // Set uniforms shader.setUniform("fontColor", label->getFontColor()); // Render text renderText(label->getText().c_str(), label->getScreenPosition().x, label->getScreenPosition().y, sx, sy, label->getFont().c_str(), label->getFontSize()); } // Disable blending glDisable(GL_BLEND); // Enable depth test glEnable(GL_DEPTH_TEST); }
void CTrueTypeFont::renderText(SDL_Surface * surface, const std::string & data, const SDL_Color & color, const Point & pos) const { if (color.r != 0 && color.g != 0 && color.b != 0) // not black - add shadow { SDL_Color black = { 0, 0, 0, SDL_ALPHA_OPAQUE}; renderText(surface, data, black, Point(pos.x + 1, pos.y + 1)); } if (!data.empty()) { SDL_Surface * rendered; if (blended) rendered = TTF_RenderText_Blended(font.get(), data.c_str(), color); else rendered = TTF_RenderText_Solid(font.get(), data.c_str(), color); assert(rendered); Rect rect(pos.x, pos.y, rendered->w, rendered->h); SDL_BlitSurface(rendered, nullptr, surface, &rect); SDL_FreeSurface(rendered); } }
void Render::drawTable() { int stepY = qMin((height() - 1)/33, 14); qglColor(QColor(255, 255, 200, 192)); glBegin(GL_QUADS); glVertex2f(5, 1); glVertex2f(135, 1); glVertex2f(135, 33*stepY); glVertex2f(5, 33*stepY); glEnd(); qglColor(Qt::gray); glVertexPointer(2, GL_FLOAT, 0, tableBoard); glEnableClientState(GL_VERTEX_ARRAY); glDrawArrays(GL_LINES, 0, 76); glDisableClientState(GL_VERTEX_ARRAY); qglColor(Qt::black); font.setPixelSize(12); QFontMetrics fm(font); int y = 2 + fm.ascent(); renderText(15, y, "#", font); renderText(40, y, "Score", font); renderText(90, y, "Time", font); y += stepY; GeneticAlgorithm *algorithm = world->getAlgorithm(); for (int i = 0; i < 32; i++) { qglColor(Qt::black); if (!algorithm->getCarNum() && algorithm->getGenerationNum()) { switch (algorithm->getOffspringsCount(i)) { case 0: qglColor(Qt::red); break; case 1: qglColor(Qt::black); break; case 2: qglColor(Qt::darkGreen); break; } } renderText(15, y + i*stepY, QString::number(i), font); float score = algorithm->getScore(i); if (score >= 0) { renderText(40, y + i*stepY, QString::number(score, '0', 1), font); int ss = algorithm->getTime(i); QTime time(0, ss/60, ss%60); renderText(90, y + i*stepY, time.toString("m:ss"), font); } } }
void TesseractWidget::paintGL() { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(75,aspect,.1,1000); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(TheWorld->Myself->Position.x,TheWorld->Myself->Position.y,TheWorld->Myself->Position.z,TheWorld->Myself->LookAt.x,TheWorld->Myself->LookAt.y,TheWorld->Myself->LookAt.z,TheWorld->Myself->HeadVector.x,TheWorld->Myself->HeadVector.y,TheWorld->Myself->HeadVector.z); emit TheWorld->drawBeginSignal(); for (QMap<int,Bnode>::iterator it=TheWorld->Blocks.begin(); it!=TheWorld->Blocks.end(); ++it) { bool Cancel=0; emit TheWorld->drawBlockSignal(it,Cancel); if (Cancel==0) { if (it.value().PointedAt==0) DrawBlock(it.value(),2); else DrawBlock(it.value(),3); } } if (creatingblock) DrawBlock(Bnode(currentblocktype,(TheWorld->Myself->LookAt+tempc)/2,((TheWorld->Myself->LookAt-tempc)/2).Abs()),1); for (QMap<int,Player>::iterator it=TheWorld->Players.begin(); it!=TheWorld->Players.end(); ++it) if (it!=TheWorld->Myself) DrawPlayer(it.value()); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); emit TheWorld->drawDoneSignal(); SetColor(TheWorld->BlockTypes[currentblocktype].Color); renderText(20,20,currentblocktype); glEnable(GL_LIGHTING); glEnable(GL_DEPTH_TEST); glFlush(); }
void locWmGlDisplay::DrawLocalisation(const Localisation& localisation) { if(drawBestModelOnly) { const KF model = localisation.getBestModel(); DrawModel(model); } else { QString displayString("Model %1 (%2%)"); for(int modelID = 0; modelID < Localisation::c_MAX_MODELS; modelID++) { const KF model = localisation.getModel(modelID); if(model.isActive) { DrawModel(model); glDisable(GL_DEPTH_TEST); // Turn Z Buffer testing Off glColor4ub(255,255,255,255); renderText(model.getState(KF::selfX), model.getState(KF::selfY),1,displayString.arg(modelID).arg(model.alpha*100,0,'f',1)); glEnable(GL_DEPTH_TEST); // Turn Z Buffer testing On } } } }
//---------------------------------------------------------------------------- // Callback method called when window readraw is necessary or // when glutPostRedisplay() was called. void Window::displayCallback(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear color and depth buffers camera->configureCamera(); for (std::vector<DirectionalLight*>::iterator it = lights.begin(); it != lights.end(); ++it) (*it)->configureLight(); root->updateVisibility(camera->getMatrix()); root->render(camera->getMatrix()); //if (Window::debug) { std::ostringstream os; os << "FPS: " << fps_counter->getCount() << ", " << "Objects: " << ObjectCounter::getCount(); renderText(os.str().c_str()); } fps_counter->count(); ObjectCounter::endFrame(); glFlush(); glutSwapBuffers(); }
void drawCircle(int cx, int cy, float r, float g, float b,char *label) { float radius = 100; float step; float x,y; float angle = 0; int i; glColor3f(r,g,b); step = 1.0; angle = 270-step/2; glBegin(GL_POLYGON); for (i=0;i<360;i++) { x = cx+cos(angle*M_PI/180)*radius; y = cy+sin(angle*M_PI/180)*radius; glVertex2f(x,y); angle+=step; } glEnd(); glColor3f(0,0,0); renderText(cx-10,cy,label); }
void Render::drawText() { font.setPixelSize(24); QFontMetrics fmScore(font); Car *car = world->getCar(); QString str; qglColor(Qt::red); str = tr("Score: %1").arg(QString::number(car->getMaxPossition(), '0', 1)); renderText(this->width()/2 - fmScore.width(str)/2, height()/6*5, str, font); font.setPixelSize(14); QFontMetrics fm(font); int ss = 5*60 - car->getTime(); QTime time(0, ss/60, ss%60); str = tr("Time: %1").arg(time.toString("m:ss")); renderText(width() - fm.width(str) - 5, 20, str, font); str = tr("Torque: %1").arg(QString::number(car->getTorque(), '0', 1)); renderText(width() - fm.width(str) - 5, 34, str, font); str = tr("Speed: %1").arg(QString::number(car->getSpeed(), '0', 1)); renderText(width() - fm.width(str) - 5, 48, str, font); font.setPixelSize(16); QFontMetrics fmGeneration(font); int generationNumber = world->getAlgorithm()->getGenerationNum(); str = tr("Generation: %1").arg(QString::number(generationNumber)); renderText(width()/2 - fmGeneration.width(str)/2, 20, str, font); qglColor(Qt::blue); if (speed == 0) { str = tr("[PAUSE]"); font.setPixelSize(32); QFontMetrics fmPause(font); renderText(width()/2 - fmPause.width(str)/2, height()/2, str, font); } else if (speed != 2) { str = tr("Playback speed: %1x").arg(QString::number(speed/2.0, '0', 1)); font.setPixelSize(14); renderText(width() - fm.width(str) - 5, 62, str, font); } }
void Font::renderText(const string& text, float x, float y, float width, float height) throw(runtime_error) { renderText(UTF8_to_UTF16(text), x, y, width, height); }
void GLWidget::paintGL() { //glMatrixMode(GL_PROJECTION); //glLoadIdentity(); // glMatrixMode(GL_MODELVIEW); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); gluLookAt( _eye.x, _eye.y, _eye.z, _center.x, _center.y, _center.z, _up.x, _up.y, _up.z ); //gluLookAt( 0,0,6 , // _eye.x, _eye.y, _eye.z, // 0,0,0 , //_center.x, _center.y, _center.z, _up.x, _up.y, _up.z ); // 0,1,0); //glPushMatrix(); BOOST_FOREACH( GLData* g, glObjects ) { // draw each object //glLoadIdentity(); //glTranslatef( g->pos.x, g->pos.y , g->pos.z ); // apply a transformation-matrix here !? if ( !g->bind() ) // bind the vbo assert(0); // void glPolygonMode(GLenum face, GLenum mode); // face = GL_FRONT | GL_BACK | GL_FRONT_AND_BACK // mode = GL_POINT, GL_LINE, GL_FILL glPolygonMode( g->polygonMode_face, g->polygonMode_mode ); glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); // coords/vert, type, stride, pointer/offset glVertexPointer(3, GLData::coordinate_type, sizeof( GLData::vertex_type ), BUFFER_OFFSET(GLData::vertex_offset)); glColorPointer(3, GLData::coordinate_type, sizeof( GLData::vertex_type ), BUFFER_OFFSET(GLData::color_offset)); // color is offset 12-bytes from position glNormalPointer( GLData::coordinate_type, sizeof( GLData::vertex_type ), BUFFER_OFFSET(GLData::normal_offset)); // mode idx-count type indices*/offset glDrawElements( g->type , g->polygonCount() , GLData::index_type, 0); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); g->release(); } // calculate and display FPS (FIXME: does not work) int msecs = - QTime::currentTime().msecsTo( _lastFrameTime ); if (msecs == 0) msecs = 1; float fps = (float)1000/(float)msecs; QString fps_str; fps_str = QString("%1 FPS, eye=%2, center=%3, up=%4").arg(fps).arg(_eye.str()).arg(_center.str()).arg(_up.str()); renderText( 10, 20, fps_str ); _lastFrameTime = QTime::currentTime(); QString dir_str; dir_str = QString("dir x = %1 dir y = %2 norm(y)= %3 ").arg(_dirx.str()).arg(_diry.str()).arg(_diry.norm()); renderText( 10, 50, dir_str ); }
// the main function int main (int argc, char **argv) { Init(); SetupCubeMap(); // load our shaders and compile them.. create a program and link it GLuint glShaderV = glCreateShader(GL_VERTEX_SHADER); GLuint glShaderF = glCreateShader(GL_FRAGMENT_SHADER); const GLchar* vShaderSource = loadFile("skybox.vert.hlsl"); const GLchar* fShaderSource = loadFile("skybox.frag.hlsl"); glShaderSource(glShaderV, 1, &vShaderSource, NULL); glShaderSource(glShaderF, 1, &fShaderSource, NULL); glCompileShader(glShaderV); CheckShaderCompilation(glShaderV); glCompileShader(glShaderF); CheckShaderCompilation(glShaderF); delete[] vShaderSource; delete[] fShaderSource; GLuint cubeMapProg = glCreateProgram(); glAttachShader(cubeMapProg, glShaderV); glAttachShader(cubeMapProg, glShaderF); glLinkProgram(cubeMapProg); glUseProgram(cubeMapProg); int vlength, flength; char vlog[2048], flog[2048]; glGetShaderInfoLog(glShaderV, 2048, &vlength, vlog); glGetShaderInfoLog(glShaderF, 2048, &flength, flog); std::cout << vlog << std::endl << std::endl << flog << std::endl << std::endl; // load shaders for the keyboard geometry glShaderV = glCreateShader (GL_VERTEX_SHADER); glShaderF = glCreateShader (GL_FRAGMENT_SHADER); const GLchar * mVSource = loadFile ("model.vert.hlsl"); const GLchar * mFSource = loadFile ("model.frag.hlsl"); glShaderSource(glShaderV, 1, &mVSource, NULL); glShaderSource(glShaderF, 1, &mFSource, NULL); delete [] mVSource; delete [] mFSource; glCompileShader(glShaderV); CheckShaderCompilation(glShaderV); glCompileShader(glShaderF); CheckShaderCompilation(glShaderF); GLuint modelProg = glCreateProgram(); glAttachShader(modelProg, glShaderV); glAttachShader(modelProg, glShaderF); glLinkProgram(modelProg); glUseProgram(modelProg); glGetShaderInfoLog(glShaderV, 2048, &vlength, vlog); glGetShaderInfoLog(glShaderF, 2048, &flength, flog); std::cout << vlog << std::endl << std::endl << flog << std::endl << std::endl; // load texture with letters on keyboard SDL_Surface *keySurface = IMG_Load ("keys.png"); // I made this image with GIMP GLuint keys_texture; glActiveTexture (GL_TEXTURE0); glEnable (GL_TEXTURE_2D); glGenTextures (1, &keys_texture); glBindTexture (GL_TEXTURE_2D, keys_texture); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, keySurface->w, keySurface->h, 0, keySurface->format->BytesPerPixel == 4? GL_RGBA: GL_RGB, GL_UNSIGNED_BYTE, keySurface->pixels); glBindTexture (GL_TEXTURE_2D, 0); SDL_FreeSurface (keySurface); GLint uniform_keys = glGetUniformLocation (modelProg, "keys"); // load premade bitmap font // http://www.amanithvg.com/testsuite/amanithvg_sre/data/font_bitmap.png SDL_Surface *bmf = IMG_Load ("font_bitmap.png"); GLuint bmf_texture; glActiveTexture(GL_TEXTURE0); glEnable (GL_TEXTURE_2D); glGenTextures (1, &bmf_texture); glBindTexture (GL_TEXTURE_2D, bmf_texture); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, bmf->w, bmf->h, 0, bmf->format->BytesPerPixel == 4? GL_RGBA: GL_RGB, GL_UNSIGNED_BYTE, bmf->pixels); glBindTexture (GL_TEXTURE_2D, 0); SDL_FreeSurface (bmf); // grab the pvm matrix and vertex location from our shader program GLint PVM = glGetUniformLocation(cubeMapProg, "PVM"); GLint vertex = glGetAttribLocation(cubeMapProg, "vertex"); // these won't change for now glm::mat4 Projection = glm::perspective(45.0f, (float)WIDTH / (float)HEIGHT, 0.1f, 100.0f); glm::mat4 View = glm::mat4(1.0f); glm::mat4 Model = glm::scale(glm::mat4(1.0f),glm::vec3(50,50,50)); // cube vertices for vertex buffer object GLfloat cube_vertices[] = { -1.0, 1.0, 1.0, -1.0, -1.0, 1.0, 1.0, -1.0, 1.0, 1.0, 1.0, 1.0, -1.0, 1.0, -1.0, -1.0, -1.0, -1.0, 1.0, -1.0, -1.0, 1.0, 1.0, -1.0, }; // vertex array buffer GLuint vbo_cube_vertices; glGenBuffers(1, &vbo_cube_vertices); glBindBuffer(GL_ARRAY_BUFFER, vbo_cube_vertices); glBufferData(GL_ARRAY_BUFFER, sizeof(cube_vertices), cube_vertices, GL_STATIC_DRAW); glEnableVertexAttribArray(vertex); glVertexAttribPointer(vertex, 3, GL_FLOAT, GL_FALSE, 0, 0); // cube indices for index buffer object GLushort cube_indices[] = { 0, 1, 2, 3, 3, 2, 6, 7, 7, 6, 5, 4, 4, 5, 1, 0, 0, 3, 7, 4, 1, 2, 6, 5, }; // index array buffer GLuint ibo_cube_indices; glGenBuffers(1, &ibo_cube_indices); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo_cube_indices); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(cube_indices), cube_indices, GL_STATIC_DRAW); // vars float alpha = 0.f, beta = 0.f, gamma = 50.f; int locX = 0, locY = 0, pressedX = 0, pressedY = 0; float origX = 0.f, origY = 0.f; bool done = false; bool mouse_down = false; char * ch = NULL; unsigned int num_ticks = 0; // for handling events SDL_Event event; // the game loop while(!done) { // get the current time... might be useful. num_ticks = SDL_GetTicks(); // process inputs while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_QUIT: done = true; break; case SDL_MOUSEMOTION: locX = event.motion.x; locY = event.motion.y; break; case SDL_MOUSEBUTTONDOWN: mouse_down = true; pressedX = event.button.x; pressedY = event.button.y; switch (event.button.button) { case SDL_BUTTON_LEFT: doSelection(event.button.x, HEIGHT - event.button.y); break; } break; case SDL_MOUSEBUTTONUP: if (mouse_down) { mouse_down = false; origY = alpha; origX = beta; } switch (event.button.button) { case SDL_BUTTON_WHEELUP: gamma += 10.0; break; case SDL_BUTTON_WHEELDOWN: gamma -= 10.0; if (gamma < 10.0) gamma = 10.0; break; case SDL_BUTTON_LEFT: //just set all keys back to up for (int i = 0; i < KEYDOWN_ARRAY_SIZE; ++i) g_keysdown_arr[i] = false; break; } break; case SDL_KEYDOWN: ch = SDL_GetKeyName(event.key.keysym.sym); g_keysdown_arr[(unsigned char)*ch] = true; g_text.push_back(*ch); break; case SDL_KEYUP: ch = SDL_GetKeyName(event.key.keysym.sym); g_keysdown_arr[(unsigned char)*ch] = false; break; default: break; } } // do updates if (mouse_down) { alpha = origY + locY - pressedY; beta = origX + locX - pressedX; } // this should add a subtle sensation of movement to the scene //alpha += .005*sin(0.0005*(double)num_ticks); //beta += .005*cos(0.0005*(double)num_ticks); // this marks the start of the code that draws glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // set the program for the cubemap glUseProgram(cubeMapProg); // uniforms for sky box include the sampler and the MVP matrix glActiveTexture(GL_TEXTURE0); glEnable(GL_TEXTURE_CUBE_MAP); glBindTexture(GL_TEXTURE_CUBE_MAP, cubemap_texture); // set up the ModelViewProj matrix for the cube map glm::mat4 RotateX = glm::rotate(glm::mat4(1.0f), alpha, glm::vec3(-1.0f, 0.0f, 0.0f)); glm::mat4 RotateY = glm::rotate(RotateX, beta, glm::vec3(0.0f, 1.0f, 0.0f)); glm::mat4 M = Projection * View * Model * RotateY; glUniformMatrix4fv(PVM, 1, GL_FALSE, glm::value_ptr(M)); // bind vertex array and index array glBindBuffer(GL_ARRAY_BUFFER, vbo_cube_vertices); glEnableVertexAttribArray(vertex); glVertexAttribPointer(vertex, 3, GL_FLOAT, GL_FALSE, 0, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo_cube_indices); // draw cubemap glDrawElements(GL_QUADS, sizeof(cube_indices)/sizeof(GLushort), GL_UNSIGNED_SHORT, 0); // clean up OpenGL state for cubemap glDisable (GL_TEXTURE_CUBE_MAP); glDisableVertexAttribArray (vertex); // clear depth buffer because sky box is infinitely far away glClear (GL_DEPTH_BUFFER_BIT); // use program for rendering keyboard glUseProgram(modelProg); // enable blending for translucency glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // enable back face culling to make translucent keys look better glEnable (GL_CULL_FACE); glCullFace (GL_BACK); // set up projection matrix for keyboard glMatrixMode (GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0, (float)WIDTH/(float)HEIGHT, 0.1, 1000.0); // set up modelview matrix for keyboard glMatrixMode (GL_MODELVIEW); glLoadIdentity(); gluLookAt (0.f, 0.f, gamma, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f); glRotatef (-alpha, 1, 0, 0); glRotatef (beta, 0, 1, 0); // set the texture for the keys glActiveTexture (GL_TEXTURE0); glEnable (GL_TEXTURE_2D); glBindTexture (GL_TEXTURE_2D, keys_texture); glUniform1i (uniform_keys, 0); // draw the keyboard drawKeyboard(); // clean up OpenGL state for keyboard glDisable (GL_BLEND); glDisable (GL_CULL_FACE); // now we print the text onto the screen // clear depth again glClear (GL_DEPTH_BUFFER_BIT); // render text to screen using orthographic projection glMatrixMode (GL_PROJECTION); glPushMatrix(); glLoadIdentity(); gluOrtho2D (0, WIDTH, 0, HEIGHT); // scale and translate to get origin in upper left hand corner of screen glScalef(1, -1, 1); glTranslatef(0, -HEIGHT, 0); glMatrixMode (GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glUseProgram(0); // using fixed function for the text, shaders not necessary // draw a translucent text box at the top of the screen glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBegin (GL_QUADS); glColor4f (1.0, 1.0, 1.0, 0.5); glVertex2f (0.0, 0.0); glVertex2f (0.0, 100.0); glVertex2f (WIDTH, 100.0); glVertex2f (WIDTH, 0.0); glEnd (); glDisable (GL_BLEND); // draw the text glActiveTexture (GL_TEXTURE0); glEnable (GL_TEXTURE_2D); glBindTexture (GL_TEXTURE_2D, bmf_texture); glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); renderText(); glMatrixMode (GL_PROJECTION); glPopMatrix (); glMatrixMode (GL_MODELVIEW); glPopMatrix(); glDisable (GL_TEXTURE_2D); glDisable (GL_BLEND); // finally, swap buffers SDL_GL_SwapBuffers(); } return 0; }
void PCViewerWidget::paintGL() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(xLook, yLook, zLook, 0,0,0, 0,1,0); glRotatef(-90,1,0,0); glRotatef(90,0,0,1); glTranslatef(0.1,0.1,0); // glTranslated(0,0,-1); // glRotatef(-90,0,1,0); // glRotatef(90,1,0,0); // // Draw Axis // float a = 100; // glLineWidth(2); // glBegin(GL_LINES);{ // glColor4f(1,0,0,1); // glVertex3f(0,0,0); // glVertex3f(.1,0,0); // glColor4f(0,1,0,1); // glVertex3f(0,0,0); // glVertex3f(0,.1,0); // glColor4f(0,0,1,1); // glVertex3f(0,0,0); // glVertex3f(0,0,.1); // } // glEnd(); // // Draw Grid // glLineWidth(1); // glColor4f(1,1,1,0.3); // glBegin(GL_LINES); // for(int i=0;i<20;i++){ // glVertex3f(i*.1-1, -1, 0); // glVertex3f(i*.1-1, 1, 0); // } // for(int i=0;i<20;i++){ // glVertex3f(-1,i*.1-1,0); // glVertex3f(1,i*.1-1,0); // } // glEnd(); // // Draw workspace // if(m_ws.bottom != m_ws.top){ // glLineWidth(2); // glColor4f(1,0,0,0.5); // glBegin(GL_LINE_STRIP);{ // glVertex3f(m_ws.left, m_ws.top, 0); // glVertex3f(m_ws.right, m_ws.top, 0); // glVertex3f(m_ws.right, m_ws.bottom, 0); // glVertex3f(m_ws.left, m_ws.bottom, 0); // glVertex3f(m_ws.left, m_ws.top, 0); // } glEnd(); // glBegin(GL_LINE_STRIP);{ // glVertex3f(m_ws.left+m_ws.margin, m_ws.top-m_ws.margin, 0); // glVertex3f(m_ws.right-m_ws.margin, m_ws.top-m_ws.margin, 0); // glVertex3f(m_ws.right-m_ws.margin, m_ws.bottom+m_ws.margin, 0); // glVertex3f(m_ws.left+m_ws.margin, m_ws.bottom+m_ws.margin, 0); // glVertex3f(m_ws.left+m_ws.margin, m_ws.top-m_ws.margin, 0); // } glEnd(); // } // Draw points if(m_showMode == SHOW_RAWDATA){ if(m_cloud->size() != 0){ glPointSize(2); glColor4f(0.,0.,0.,1.); glBegin(GL_POINTS); for(int i=0;i<m_cloud->size();i++){ glVertex3f(m_cloud->points[i].x,m_cloud->points[i].y,m_cloud->points[i].z); } glEnd(); } } // Draw points plane if(m_showBGMode == SHOW_BACKGROUND_ON){ if(m_cloud_plane->size() != 0){ glPointSize(1.4); glColor4f(0.,0.,0.,1.); glBegin(GL_POINTS); for(int i=0;i<m_cloud_plane->size();i++){ glVertex3f(m_cloud_plane->points[i].x,m_cloud_plane->points[i].y,m_cloud_plane->points[i].z); } glEnd(); } } // Draw objects if(m_showMode == SHOW_SEGMENTS || m_showMode == SHOW_OBJECTS){ if(m_clouds_object.size()!=0){ for(int i=0;i<m_clouds_object.size();i++){ glPointSize(3.5); glColor4f(randRGB[i%20][0],randRGB[i%20][1],randRGB[i%20][2],1.); switch(i){ case 0: glColor4f(1,0,0,1.); break; case 1: glColor4f(0,0,1,1.); break; case 2: glColor4f(0,1,0,1.); break; case 3: glColor4f(0,1,1,1.); break; } glBegin(GL_POINTS); for(int j=0;j<m_clouds_object.at(i)->size();j++){ glVertex3f(m_clouds_object.at(i)->points[j].x,m_clouds_object.at(i)->points[j].y,m_clouds_object.at(i)->points[j].z); } glEnd(); } } } if(m_showMode == SHOW_OBJECTS){ // Draw statistic if(m_clouds_statistic.size() != 0){ for(int i=0;i<m_clouds_statistic.size();i++){ // mean value TOM_OBJECT statistic = m_clouds_statistic.at(i); int id = m_clouds_statistic.at(i).id; glPointSize(7); glColor4f(randRGB[i%20][0],randRGB[i%20][1],randRGB[i%20][2],1.); switch(i){ case 0: glColor4f(1,0,0,1.); break; case 1: glColor4f(0,0,1,1.); break; case 2: glColor4f(0,1,0,1.); break; case 3: glColor4f(0,1,1,1.); break; } glBegin(GL_POINTS); glVertex3f(statistic.mean[0],statistic.mean[1],statistic.mean[2]); glEnd(); // covariance -> ellipsoid double scale = 1; GLfloat mat[16]; GLUquadricObj *obj = gluNewQuadric(); gluQuadricDrawStyle( obj, GLU_LINE); // GLU_FILL // A homogeneous transformation matrix, in this order: // // 0 4 8 12 // 1 5 9 13 // 2 6 10 14 // 3 7 11 15 // mat[3] = mat[7] = mat[11] = 0; mat[15] = 1; mat[12] = mat[13] = mat[14] = 0; mat[0] = statistic.eigenvectors.col(0)[0]; mat[1] = statistic.eigenvectors.col(0)[1]; mat[2] = statistic.eigenvectors.col(0)[2]; // New X-axis mat[4] = statistic.eigenvectors.col(1)[0]; mat[5] = statistic.eigenvectors.col(1)[1]; mat[6] = statistic.eigenvectors.col(1)[2]; // New X-axis mat[8] = statistic.eigenvectors.col(2)[0]; mat[9] = statistic.eigenvectors.col(2)[1]; mat[10] = statistic.eigenvectors.col(2)[2]; // New X-axis glPushMatrix(); glTranslatef(statistic.mean[0], statistic.mean[1], statistic.mean[2]); glMultMatrixf( mat ); glScalef(sqrt(statistic.eigenvalues[0])*scale, sqrt(statistic.eigenvalues[1])*scale, sqrt(statistic.eigenvalues[2])*scale); gluSphere( obj, 1, 10, 10); glPopMatrix(); gluDeleteQuadric(obj); glColor4f(1,1,1,1); QFont font("Times", 50, QFont::Bold); // renderText(statistic.mean[0], statistic.mean[1], statistic.mean[2], QString::number(i), font); } } } // Draw tracks if(m_showMode == SHOW_TRACKS || m_showMode == SHOW_TRACKCLOUDS){ if(m_tracks.size() != 0){ for(int i=0;i<m_tracks.size();i++){ TOM_OBJECT object = m_tracks.at(i).ptrLast(); int id = m_tracks.at(i).num(); if(m_showMode == SHOW_TRACKS){ // mean value glPointSize(7); glColor4f(randRGB[id%20][0],randRGB[id%20][1],randRGB[id%20][2],1.); switch(id){ case 1: glColor4f(1,0,0,1.); break; case 2: glColor4f(0,0,1,1.); break; case 3: glColor4f(0,1,0,1.); break; case 4: glColor4f(0,1,1,1.); break; } glBegin(GL_POINTS); glVertex3f(object.mean[0],object.mean[1],object.mean[2]); glEnd(); // covariance -> ellipsoid double scale = 1; GLfloat mat[16]; GLUquadricObj *obj = gluNewQuadric(); gluQuadricDrawStyle( obj, GLU_LINE); // GLU_FILL // A homogeneous transformation matrix, in this order: // // 0 4 8 12 // 1 5 9 13 // 2 6 10 14 // 3 7 11 15 // mat[3] = mat[7] = mat[11] = 0; mat[15] = 1; mat[12] = mat[13] = mat[14] = 0; mat[0] = object.eigenvectors.col(0)[0]; mat[1] = object.eigenvectors.col(0)[1]; mat[2] = object.eigenvectors.col(0)[2]; // New X-axis mat[4] = object.eigenvectors.col(1)[0]; mat[5] = object.eigenvectors.col(1)[1]; mat[6] = object.eigenvectors.col(1)[2]; // New X-axis mat[8] = object.eigenvectors.col(2)[0]; mat[9] = object.eigenvectors.col(2)[1]; mat[10] = object.eigenvectors.col(2)[2]; // New X-axis glPushMatrix(); glTranslatef(object.mean[0], object.mean[1], object.mean[2]); glMultMatrixf( mat ); glScalef(sqrt(object.eigenvalues[0])*scale, sqrt(object.eigenvalues[1])*scale, sqrt(object.eigenvalues[2])*scale); gluSphere( obj, 1, 10, 10); glPopMatrix(); gluDeleteQuadric(obj); glColor4f(0,0,0,1); QFont font("Times", 30, QFont::Bold); renderText(object.mean[0], object.mean[1], object.mean[2], QString::number(id), font); } // draw point cloud glPointSize(3.5); glColor4f(randRGB[id%20][0],randRGB[id%20][1],randRGB[id%20][2],1.); switch(id){ case 1: glColor4f(1,0,0,1.); break; case 2: glColor4f(0,0,1,1.); break; case 3: glColor4f(0,1,0,1.); break; case 4: glColor4f(0,1,1,1.); break; } glBegin(GL_POINTS); for(int k=0;k<m_tracks.at(i).getCloud().size();k++){ glVertex3f(m_tracks.at(i).getCloud().points[k].x,m_tracks.at(i).getCloud().points[k].y,m_tracks.at(i).getCloud().points[k].z); } glEnd(); // draw points // for(int j=0;j<m_tracks.at(i).size();j++){ // glPointSize(2); // glColor4f(randRGB[i%20][0],randRGB[i%20][1],randRGB[i%20][2],1.); // glBegin(GL_POINTS); // for(int k=0;k<m_tracks.at(i).ptrAt(j).cloud.size();k++){ // glVertex3f(m_tracks.at(i).ptrAt(j).cloud.points[k].x,m_tracks.at(i).ptrAt(j).cloud.points[k].y,m_tracks.at(i).ptrAt(j).cloud.points[k].z); // } // glEnd(); // } } } } // Draw convex hull points if(m_hulls.size() != 0){ for(int i=0;i<m_hulls.size();i++){ Polyhedron_3 poly = m_hulls.at(i); // draw points // Polyhedron_3::Vertex_iterator it; // glPointSize(7); // glColor4f(randRGB[i][0],randRGB[i][0],randRGB[i][0],0.5); // glBegin(GL_POINTS); // for(it = poly.vertices_begin(); it != poly.vertices_end(); ++it){ // glVertex3f(it->point()[0],it->point()[1],it->point()[2]); // } // glEnd(); // draw edges glColor4f(1,1,1,0.3); glBegin(GL_LINES); Polyhedron_3::Halfedge_iterator it_edge; for(it_edge = poly.halfedges_begin(); it_edge != poly.halfedges_end(); ++it_edge){ Polyhedron_3::Halfedge_handle h = it_edge->prev(); Polyhedron_3::Vertex_handle vs = h->vertex(); Polyhedron_3::Vertex_handle ve = it_edge->vertex(); glVertex3f(vs->point()[0],vs->point()[1],vs->point()[2]); glVertex3f(ve->point()[0],ve->point()[1],ve->point()[2]); } glEnd(); } } if(m_tCloudA.size() != 0){ // draw point cloud glPointSize(2); glColor4f(1,0,0,1.); glBegin(GL_POINTS); for(int k=0;k<m_tCloudA.size();k++){ glVertex3f(m_tCloudA.points[k].x,m_tCloudA.points[k].y,m_tCloudA.points[k].z); } glEnd(); } if(m_tCloudB.size() != 0){ // draw point cloud glPointSize(2); glColor4f(0,0,1,1.); glBegin(GL_POINTS); for(int k=0;k<m_tCloudB.size();k++){ glVertex3f(m_tCloudB.points[k].x,m_tCloudB.points[k].y,m_tCloudB.points[k].z); } glEnd(); } }
void IFont::renderTextCenter(SDL_Surface * surface, const std::string & data, const SDL_Color & color, const Point & pos) const { Point size(getStringWidth(data), getLineHeight()); renderText(surface, data, color, pos - size / 2); }
void IFont::renderTextLeft(SDL_Surface * surface, const std::string & data, const SDL_Color & color, const Point & pos) const { renderText(surface, data, color, pos); }
void renderHUD(struct renderstate *render, struct simulation *sim, struct universe *univ) { float pixelsPerMeter = univ->scale * render->scale; int scale_size = 100; char text[256]; SDL_Color text_colour = { 255, 255, 255, 255 }; SDL_SetRenderDrawColor(render->renderer, 255, 255, 255, 255); // Draw the scale in the bottom right corner SDL_RenderDrawLine(render->renderer, render->width - 10, render->height - 10, render->width - 10, render->height - 20); SDL_RenderDrawLine(render->renderer, render->width - 10, render->height - 15, render->width - 10 - scale_size, render->height - 15); SDL_RenderDrawLine(render->renderer, render->width - 10 - scale_size, render->height - 10, render->width - 10 - scale_size, render->height - 20); sprintf(text, "%.2fm", (1 / pixelsPerMeter) * scale_size); renderText(render, render->font_small, text, render->width - 10 - (scale_size / 2), render->height - 25, FONT_CENTER, text_colour); // Fidelity sprintf(text, "%dx", univ->fidelity); renderText(render, render->font_small, text, 10, 30, FONT_LEFT, text_colour); // Draw the seconds/second sprintf(text, "%.2fs/s", render->fps * univ->speed); renderText(render, render->font_small, text, 10, 45, FONT_LEFT, text_colour); // Draw the FPS sprintf(text, "%d frame/s", render->fps); renderText(render, render->font_small, text, 10, 60, FONT_LEFT, text_colour); // Draw the pause symbol if (sim->paused) { SDL_Rect rect; SDL_SetRenderDrawColor(render->renderer, 255, 0, 0, 255); rect.x = 10; rect.y = 10; rect.w = 6; rect.h = 16; SDL_RenderFillRect(render->renderer, &rect); rect.x = 20; SDL_RenderFillRect(render->renderer, &rect); } // Draw the saving text if (sim->savingTime > -1) { sim->savingTime--; strcpy(text, "Saving..."); renderText(render, render->font_large, text, render->width / 2, render->height / 2, FONT_CENTER, text_colour); } }
size dx11render::renderText(int flags, const font *fnt, const point& p, const color& col, const boost::format& fmt) { renderText(flags, fnt, p, col, boost::str(fmt)); }
/////////////////////////////////////////////////////////////////////////////// // Function Name: paintGL() // Description: Paint the OpenGL widget (run on a timer). // Modified: 03/02/2010 // Author: Tom Calloway /////////////////////////////////////////////////////////////////////////////// void GLWidget::paintGL() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); // Draw the background. glDrawPixels(glBkImage.width(), glBkImage.height(), GL_RGBA, GL_UNSIGNED_BYTE, glBkImage.bits()); for (int i = 0; i < map.cellsTall; i++) { for (int j = 0; j < map.cellsWide; j++) { // Draw the grid. drawGridBox(i, j); // Assume no unit at the beginning. mapGrid[i][j].isUnit = false; } } for (int i = 0; i < MAX_UNITS; i++) { // Draw the units. updateUnit(unit[i]); mapGrid[unit[i].vLocation][unit[i].hLocation].unit = unit[i]; mapGrid[unit[i].vLocation][unit[i].hLocation].isUnit = true; // Update the action time (unitTest). if (unit[i].actionTime >= 100) { unit[i].actionTime = 0; } unit[i].actionTime += 0.005 * unit[i].actionRate; } for (int i = 0; i < map.cellsTall; i++) { for (int j = 0; j < map.cellsWide; j++) { if (mapGrid[i][j].isSelected && mapGrid[i][j].isUnit) { // Draw information header. glColor4f( 0.0f, 0.0f, 0.0f, 0.8f ); glBegin (GL_QUADS); glVertex3f (15, GLWidget::height() - 20, 0.0); glVertex3f (15 + 250, GLWidget::height() - 20, 0.0); glVertex3f (15 + 250, GLWidget::height() - 20 - 100, 0.0); glVertex3f (15, GLWidget::height() - 20 - 100, 0.0); glEnd(); qglColor(Qt::white); char *tmpString = (char*)malloc(256); string displayString = ""; int vLoc = GLWidget::height() - 40; // Unit name. QFont nameFont = GLWidget::font(); nameFont.setBold(true); renderText(30, vLoc, 0.0, mapGrid[i][j].unit.name.c_str(), nameFont); vLoc -= 15; // Unit hit points. itoa(mapGrid[i][j].unit.hitPoints, tmpString, 10); displayString = "Hit Points: "; displayString.append(tmpString); renderText(30, vLoc, 0.0, displayString.c_str()); vLoc -= 15; // Unit attack power. itoa(mapGrid[i][j].unit.attackPower, tmpString, 10); displayString = "Attack Power: "; displayString.append(tmpString); renderText(30, vLoc, 0.0, displayString.c_str()); vLoc -= 15; } } } }
void CameraWidget::paintGL() { // Clear the screen // ::glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // If the image is empty, we are done // if (glImage.isNull()) { return; } // Set the viewport // ::glViewport(0, 0, width(), height()); // Set the projection matrix // ::glMatrixMode (GL_PROJECTION); ::glLoadIdentity(); ::glOrtho(0, width(), 0, height(), -1, 1); // Set the modelview matrix // ::glMatrixMode(GL_MODELVIEW); ::glLoadIdentity(); // Account for scale into the window // const float wRatio = static_cast<float>(width()) / glImage.width(); const float hRatio = static_cast<float>(height()) / glImage.height(); ::glScalef(wRatio, hRatio, 1); // Draw the image as a textured quad // ::glColor3f(1,1,1); ::glEnable(GL_TEXTURE_2D); ::glBindTexture(GL_TEXTURE_2D, mTextureId); ::glBegin(GL_QUADS); { ::glTexCoord2i(0, 0); ::glVertex2i( 0, 0); ::glTexCoord2i(0, 1); ::glVertex2i( 0, glImage.height()); ::glTexCoord2i(1, 1); ::glVertex2i(glImage.width(), glImage.height()); ::glTexCoord2i(1, 0); ::glVertex2i(glImage.width(), 0); } ::glEnd(); ::glDisable(GL_TEXTURE_2D); // Draw a circle // ::glColor3f(1,1,1); ::glBegin(GL_LINE_LOOP); for (int i = 0; i < 360; i += 10) { const float ang = i * 3.14159 / 180.0; const float x = 30 * ::cos(ang) + glImage.width() - 30; const float y = 30 * ::sin(ang) + glImage.height() - 30; ::glVertex2f(x,y); } ::glEnd(); // Mark up // renderText(width() - 27, 10, "N"); renderText(width() - 8, 30, "E"); renderText(width() - 42, 30, "W"); renderText(width() - 27, 45, "S"); // Draw the compass arrow // ::glColor3f(1,0,0); ::glBegin(GL_LINES); const float ang = mHeading * 3.14159 / 180.0; const float x1 = glImage.width() - 30; const float y1 = glImage.height() - 30; const float x2 = 30 * ::cos(ang) + x1; const float y2 = 30 * ::sin(ang) + y1; ::glVertex2f(x1,y1); ::glVertex2f(x2,y2); ::glEnd(); // Overlay the heading on the image // }
void Frame::renderSprites(Graphics::ManagedSurface &surface, bool renderTrail) { for (uint16 i = 0; i < CHANNEL_COUNT; i++) { if (_sprites[i]->_enabled) { if ((_sprites[i]->_trails == 0 && renderTrail) || (_sprites[i]->_trails == 1 && !renderTrail)) continue; Cast *cast; if (!_vm->_currentScore->_casts.contains(_sprites[i]->_castId)) { if (!_vm->getSharedCasts()->contains(_sprites[i]->_castId)) { warning("Cast id %d not found", _sprites[i]->_castId); continue; } else { cast = _vm->getSharedCasts()->getVal(_sprites[i]->_castId); } } else { cast = _vm->_currentScore->_casts[_sprites[i]->_castId]; } if (cast->type == kCastText) { renderText(surface, i); continue; } Image::ImageDecoder *img = getImageFrom(_sprites[i]->_castId); if (!img) { warning("Image with id %d not found", _sprites[i]->_castId); continue; } if (!img->getSurface()) { //TODO //BMPDecoder doesnt cover all BITD resources (not all have first two bytes 'BM') //Some BITD's first two bytes 0x6 0x0 warning("Can not load image %d", _sprites[i]->_castId); continue; } uint32 regX = static_cast<BitmapCast *>(_sprites[i]->_cast)->regX; uint32 regY = static_cast<BitmapCast *>(_sprites[i]->_cast)->regY; uint32 rectLeft = static_cast<BitmapCast *>(_sprites[i]->_cast)->initialRect.left; uint32 rectTop = static_cast<BitmapCast *>(_sprites[i]->_cast)->initialRect.top; int x = _sprites[i]->_startPoint.x - regX + rectLeft; int y = _sprites[i]->_startPoint.y - regY + rectTop; int height = _sprites[i]->_height; int width = _sprites[i]->_width; Common::Rect drawRect = Common::Rect(x, y, x + width, y + height); _drawRects.push_back(drawRect); switch (_sprites[i]->_ink) { case kInkTypeCopy: surface.blitFrom(*img->getSurface(), Common::Point(x, y)); break; case kInkTypeTransparent: //FIXME: is it always white (last entry in pallette)? surface.transBlitFrom(*img->getSurface(), Common::Point(x, y), _vm->getPaletteColorCount() - 1); break; case kInkTypeBackgndTrans: drawBackgndTransSprite(surface, *img->getSurface(), drawRect); break; case kInkTypeMatte: drawMatteSprite(surface, *img->getSurface(), drawRect); break; case kInkTypeGhost: drawGhostSprite(surface, *img->getSurface(), drawRect); break; case kInkTypeReverse: drawReverseSprite(surface, *img->getSurface(), drawRect); break; default: warning("Unhandled ink type %d", _sprites[i]->_ink); surface.blitFrom(*img->getSurface(), Common::Point(x, y)); break; } } } }
void VCanvas::drawData() { //drawing particles QMapIterator<int, VCell *> i(*drawingData); qglColor(Qt::red); while (i.hasNext()) { i.next(); if (1) { const VPoint *pParticle = i.value()->getParticle(); glBegin(GL_POINTS); glVertex3f(pParticle->x, pParticle->y, pParticle->z); glEnd(); if (areParticlesNumbersVisible) renderText(pParticle->x + 0.05 / defaultScaling, pParticle->y + 0.05 / defaultScaling, pParticle->z + 0.05 / defaultScaling, QString::number(i.key() + 1)); } } //drawing faces i = QMapIterator<int, VCell *>(*drawingData); glEnable(GL_BLEND); glDepthMask(GL_FALSE); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); while (i.hasNext()) { i.next(); if (i.value()->getVisibility()) { qglColor(*i.value()->getColor()); int fc = i.value()->faceCount(); for (int j = 0; j < fc; ++j) { //glLoadName(i); const QList<VPoint> *pFace = i.value()->getFace(j); glBegin(GL_POLYGON); for (int j = 0; j < pFace->size(); ++j) { glVertex3f(pFace->at(j).x, pFace->at(j).y, pFace->at(j).z); } glEnd(); } } } glDepthMask(GL_TRUE); //drawing face' wires i = QMapIterator<int, VCell *>(*drawingData); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); qglColor(Qt::black); while (i.hasNext()) { i.next(); if (i.value()->getVisibility()) { int fc = i.value()->faceCount(); for (int j = 0; j < fc; ++j) { //glLoadName(i); const QList<VPoint> *pFace = i.value()->getFace(j); glBegin(GL_LINE_LOOP); for (int j = 0; j < pFace->size(); ++j) { glVertex3f(pFace->at(j).x, pFace->at(j).y, pFace->at(j).z); } glEnd(); } } } glDisable(GL_BLEND); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); }
void VCanvas::drawAxes(GLdouble length) { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glPushMatrix(); qglColor(Qt::darkCyan); renderText(length, 0.1, 0.0, QChar('x')); for (GLdouble i = 1; i <= length-1; i = i + 1.0) { glBegin(GL_POINTS); glVertex3f(i, 0.0, 0.0); glVertex3f(-i, 0.0, 0.0); glEnd(); if ((int)i % 1 == 0) { renderText(i, 0.1, 0.0, QString::number(i)); renderText(-i, 0.1, 0.0, QString::number(-i)); } } glBegin(GL_LINES); glVertex3f(-length, 0.0, 0.0); glVertex3f(length, 0.0, 0.0); glEnd(); //glPopMatrix(); //glPushMatrix(); qglColor(Qt::darkYellow); renderText(0.1, length, 0.0, QChar('y')); for (GLdouble i = 1; i <= length-1; i = i + 1.0) { glBegin(GL_POINTS); glVertex3f(0.0, i, 0.0); glVertex3f(0.0, -i, 0.0); glEnd(); if ((int)i % 1 == 0) { renderText(0.1, i, 0.0, QString::number(i)); renderText(0.1, -i, 0.0, QString::number(-i)); } } glBegin(GL_LINES); glVertex3f(0.0, - length, 0.0); glVertex3f(0.0, length, 0.0); glEnd(); //glPopMatrix(); //glPushMatrix(); qglColor(Qt::darkMagenta); renderText(0.0, 0.1, length, QChar('z')); for (GLdouble i = 1; i <= length-1; i = i + 1.0) { glBegin(GL_POINTS); glVertex3f(0.0, 0.0, i); glVertex3f(0.0, 0.0, -i); glEnd(); if ((int)i % 1 == 0) { renderText(0.0, 0.1, i, QString::number(i)); renderText(0.0, 0.1, -i, QString::number(-i)); } } glBegin(GL_LINES); glVertex3f(0.0, 0.0, -length); glVertex3f(0.0, 0.0, length); glEnd(); glPopMatrix(); glDisable(GL_BLEND); }
void Minesweeper::renderFlagText(){ stringstream message; message << setw(3) << setfill('0') << flagsQuantity; renderText(getTextSurface(message.str().c_str()),0,0, WIDTH+WIDTH/2,HEIGHT); }
void GLWidget::draw() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if(m_using_bloom) { m_fbo->bind(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } glMatrixMode(GL_MODELVIEW); glLoadIdentity(); m_zpos = sin(m_counter/500.0)*20; m_ypos = cos(m_counter/500.0)*20; m_counter++; glDisable(GL_DEPTH_TEST); cam->transformCamera(); glPushMatrix(); glLoadIdentity(); glRotatef(-cam->pitch, 1.0,0.0,0.0); glRotatef(-cam->yaw, 0.0,1.0,0.0); skybox->draw(); lighting(); if(m_using_bloom && m_bloom_not_broken) { glBindRenderbuffer(GL_RENDERBUFFER, m_depthBuf); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT32, width(), height()); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_depthBuf); } glEnable(GL_DEPTH_TEST); if(m_displaying_particles) { m_particles->draw(); } if(m_toon_lighting) { m_toonShader->bind(); } else { m_plainShader->bind(); } change_current_chunk(); if(m_fps_camera) { glTranslatef(-2.5, 0, -2.5); glPopMatrix(); } else { glTranslatef(0.0, 0.0, -7.0); glRotatef(m_xrot, 1.0, 0.0, 0.0); glRotatef(m_yrot, 0.0, 1.0, 0.0); glScalef(0.5, 0.5, 0.5); glScalef(m_zoom, m_zoom, m_zoom); } glPushMatrix(); if(!m_fps_camera) { glTranslatef(m_map->curx-2.5, 0.0, m_map->curz-2.5); } m_nchunk->draw(); m_nwchunk->draw(); m_wchunk->draw(); m_swchunk->draw(); m_schunk->draw(); m_sechunk->draw(); m_echunk->draw(); m_nechunk->draw(); m_centerchunk->draw(); glPopMatrix(); glLoadIdentity(); char cameraLocation[100]; sprintf(cameraLocation, "x:%2.3f y:%2.3f z:%2.3f yaw:%2.3f pitch:%2.3f", cam->x, cam->y, cam->z, cam->yaw, cam->pitch); glColor3f(1.0,1.0,1.0); renderText(0,30, cameraLocation); char chunkloc[80]; sprintf(chunkloc, "Chunk (%4i, %4i)", m_map->curx, m_map->curz); renderText(0,50, chunkloc); if(m_toon_lighting) { m_toonShader->release(); } else { m_plainShader->release(); } if(m_using_bloom) { m_fbo->release(); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0); m_bloomShader->draw(m_fbo->texture(), m_width); } }
int main(int argc, char **argv){ if (SDL_Init(SDL_INIT_EVERYTHING) != 0){ logSDLError(std::cout, "SDL_Init"); return 1; } if (TTF_Init() != 0){ logSDLError(std::cout, "TTF_Init"); return 1; } SDL_Window *window = SDL_CreateWindow("Hello World!", 100, 100, SCREEN_WIDTH, GRID_HEIGHT + HUD_HEIGHT, SDL_WINDOW_SHOWN); if (window == nullptr){ logSDLError(std::cout, "CreateWindow"); SDL_Quit(); return 2; } SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); if (renderer == nullptr){ logSDLError(std::cout, "CreateRenderer"); SDL_DestroyWindow(window); SDL_Quit(); return 3; } //The textures we'll be using SDL_Texture *background = loadTexture("res/game_bg.jpg", renderer); SDL_Texture *image = loadTexture("res/Blue.png", renderer); SDL_Texture *blueGem = loadTexture("res/Blue.png", renderer); SDL_Texture *greenGem = loadTexture("res/Green.png", renderer); SDL_Texture *purpleGem = loadTexture("res/Purple.png", renderer); SDL_Texture *redGem = loadTexture("res/Red.png", renderer); SDL_Texture *yellowGem = loadTexture("res/Yellow.png", renderer); SDL_Texture *gems[] = {blueGem, greenGem, purpleGem, redGem, yellowGem}; SDL_Texture *cursorYellowImg = loadTexture("res/cursor_yellow.png", renderer); SDL_Texture *cursorGreenImg = loadTexture("res/cursor_green.png", renderer); //Make sure they both loaded ok if (background == nullptr || image == nullptr){ SDL_DestroyRenderer(renderer); SDL_DestroyWindow(window); SDL_Quit(); return 4; } //We'll render the string "TTF fonts are cool!" in white //Color is in RGB format SDL_Color color = { 255, 255, 255 }; SDL_Texture *textImage; TTF_Font* font = loadFont("res/sample.ttf", 32); //Our event structure SDL_Event e; //For tracking if we want to quit bool quit = false; int gameState = GAMESTATE_TITLE_SCREEN; int** pGridArray; gem* pGemsArray = new gem[NUM_ROWS * NUM_COLUMNS]; int score; int mouseX = 0; int mouseY = 0; int numGemsSelected = 0; int selectedGems[2][2] = {{-1, -1}, {-1, -1}}; bool gemSelected = false; int cursorRow = 0; int cursorColumn = 0; bool foundMatch = false; int thisRow, thisColumn; bool gemsDropping; bool cancelSwap = false; bool mouseDown = false; int dragStartX; int dragStartY; bool dragStarted = false; time_t timer; time_t startTime; std::ostringstream os; while (!quit) { switch (gameState) { case GAMESTATE_TITLE_SCREEN: break; case GAMESTATE_INIT: for (int i = 0; i < NUM_ROWS*NUM_COLUMNS; i++) { pGemsArray[i].state = GEMSTATE_IDLE; } pGridArray = initGrid(pGemsArray); score = 0; startTime = time(0); gameState = GAMESTATE_INITIAL_CHECK_MATCH; break; case GAMESTATE_INITIAL_CHECK_MATCH: SDL_Delay(1000); checkMatchAllRows(pGridArray, pGemsArray, &score); gameState = GAMESTATE_CHECKDROP; break; case GAMESTATE_CHECK_MATCH: foundMatch = false; for (int row = NUM_ROWS-1; row >= 0; row--) { for (int column = 0; column < NUM_COLUMNS; column++) { if (pGemsArray[pGridArray[row][column]].prevState == GEMSTATE_FALL) { foundMatch = checkMatchAfterSwap(pGridArray, pGemsArray, &pGemsArray[pGridArray[row][column]], &score); } } } gameState = GAMESTATE_CHECKDROP; for (int row = NUM_ROWS-1; row >= 0; row--) { for (int column = 0; column < NUM_COLUMNS; column++) { pGemsArray[pGridArray[row][column]].prevState = -1; } } break; case GAMESTATE_AWAIT_INPUT: if (gemSelected) { if (numGemsSelected < 2) { numGemsSelected++; } else { numGemsSelected = 0; } cursorRow = (mouseY-HUD_HEIGHT) / ROW_HEIGHT; cursorColumn = mouseX / COLUMN_WIDTH; // Store the location of the selected gem selectedGems[numGemsSelected-1][ROW] = cursorRow; selectedGems[numGemsSelected-1][COLUMN] = cursorColumn; gemSelected = false; // Check if ready to swap if (numGemsSelected == 2) { int state = checkSwapGems((int*)selectedGems); state = setSwapGems(state, pGemsArray, pGridArray, selectedGems[0][ROW], selectedGems[0][COLUMN], selectedGems[1][ROW], selectedGems[1][COLUMN]); if (state == -1) { // Remove all cursors numGemsSelected = 0; // Set new cursor to this position cursorRow = (mouseY-HUD_HEIGHT) / ROW_HEIGHT; cursorColumn = mouseX / COLUMN_WIDTH; // Store the location of the selected gem selectedGems[numGemsSelected-1][ROW] = cursorRow; selectedGems[numGemsSelected-1][COLUMN] = cursorColumn; gemSelected = true; } else { gameState = state; } } } break; case GAMESTATE_SWAP_LEFT: case GAMESTATE_SWAP_RIGHT: thisRow = selectedGems[0][ROW]; if (gameState == GAMESTATE_SWAP_LEFT) thisColumn = selectedGems[0][COLUMN]; else thisColumn = selectedGems[1][COLUMN]; pGemsArray[pGridArray[thisRow][thisColumn]].x += pGemsArray[pGridArray[thisRow][thisColumn]].velocity; pGemsArray[pGridArray[thisRow][thisColumn-1]].x += pGemsArray[pGridArray[thisRow][thisColumn-1]].velocity; if (pGemsArray[pGridArray[thisRow][thisColumn]].x <= -COLUMN_WIDTH) { numGemsSelected = 0; // Swap with other gem int temp = pGridArray[thisRow][thisColumn]; pGridArray[thisRow][thisColumn] = pGridArray[thisRow][thisColumn-1]; pGridArray[thisRow][thisColumn-1] = temp; pGemsArray[pGridArray[thisRow][thisColumn]].velocity = 0; pGemsArray[pGridArray[thisRow][thisColumn]].x = 0; pGemsArray[pGridArray[thisRow][thisColumn]].column++; pGemsArray[pGridArray[thisRow][thisColumn]].state = GEMSTATE_IDLE; pGemsArray[pGridArray[thisRow][thisColumn-1]].velocity = 0; pGemsArray[pGridArray[thisRow][thisColumn-1]].x = 0; pGemsArray[pGridArray[thisRow][thisColumn-1]].column--; pGemsArray[pGridArray[thisRow][thisColumn-1]].state = GEMSTATE_IDLE; bool foundMatch = false; bool foundMatch2 = false; if (!cancelSwap) { foundMatch = checkMatchAfterSwap(pGridArray, pGemsArray, &pGemsArray[pGridArray[thisRow][thisColumn]], &score); foundMatch2 = checkMatchAfterSwap(pGridArray, pGemsArray, &pGemsArray[pGridArray[thisRow][thisColumn-1]], &score); } if (foundMatch || foundMatch2) { gameState = GAMESTATE_CHECKDROP; } else { if (cancelSwap) { // Gems have gone back to their original positions after cancelling the swap cancelSwap = false; gameState = GAMESTATE_AWAIT_INPUT; } else { // Swap the gems back to their original positions gameState = setSwapGems(gameState, pGemsArray, pGridArray, selectedGems[0][ROW], selectedGems[0][COLUMN], selectedGems[1][ROW], selectedGems[1][COLUMN]); cancelSwap = true; } } } break; case GAMESTATE_SWAP_UP: case GAMESTATE_SWAP_DOWN: thisColumn = selectedGems[0][COLUMN]; if (gameState == GAMESTATE_SWAP_UP) thisRow = selectedGems[0][ROW]; else thisRow = selectedGems[1][ROW]; pGemsArray[pGridArray[thisRow][thisColumn]].y += pGemsArray[pGridArray[thisRow][thisColumn]].velocity; pGemsArray[pGridArray[thisRow-1][thisColumn]].y += pGemsArray[pGridArray[thisRow-1][thisColumn]].velocity; if (pGemsArray[pGridArray[thisRow][thisColumn]].y <= -ROW_HEIGHT) { numGemsSelected = 0; // Swap with other gem int temp = pGridArray[thisRow][thisColumn]; pGridArray[thisRow][thisColumn] = pGridArray[thisRow-1][thisColumn]; pGridArray[thisRow-1][thisColumn] = temp; pGemsArray[pGridArray[thisRow][thisColumn]].velocity = 0; pGemsArray[pGridArray[thisRow][thisColumn]].y = 0; pGemsArray[pGridArray[thisRow][thisColumn]].row++; pGemsArray[pGridArray[thisRow][thisColumn]].state = GEMSTATE_IDLE; pGemsArray[pGridArray[thisRow-1][thisColumn]].velocity = 0; pGemsArray[pGridArray[thisRow-1][thisColumn]].y = 0; pGemsArray[pGridArray[thisRow-1][thisColumn]].row--; pGemsArray[pGridArray[thisRow-1][thisColumn]].state = GEMSTATE_IDLE; bool foundMatch = false; bool foundMatch2 = false; if (!cancelSwap) { foundMatch = checkMatchAfterSwap(pGridArray, pGemsArray, &pGemsArray[pGridArray[thisRow][thisColumn]], &score); foundMatch2 = checkMatchAfterSwap(pGridArray, pGemsArray, &pGemsArray[pGridArray[thisRow-1][thisColumn]], &score); } if (foundMatch || foundMatch2) { gameState = GAMESTATE_CHECKDROP; } else { if (cancelSwap) { // Gems have gone back to their original positions after cancelling the swap cancelSwap = false; gameState = GAMESTATE_AWAIT_INPUT; } else { // Swap the gems back to their original positions gameState = setSwapGems(gameState, pGemsArray, pGridArray, selectedGems[0][ROW], selectedGems[0][COLUMN], selectedGems[1][ROW], selectedGems[1][COLUMN]); cancelSwap = true; } } } break; case GAMESTATE_CHECKDROP: if (checkDrop(pGridArray, pGemsArray)) { gameState = GAMESTATE_DROP; } else { gameState = GAMESTATE_ADD_GEMS; } break; case GAMESTATE_DROP: // Check if any more gems are dropping gemsDropping = false; for (int i = 0; i < NUM_ROWS * NUM_COLUMNS; i++) { if (pGemsArray[i].state == GEMSTATE_FALL || pGemsArray[i].state == GEMSTATE_ENTER || pGemsArray[i].state == GEMSTATE_BOUNCE) { gemsDropping = true; break; } } if (!gemsDropping) { gameState = GAMESTATE_CHECK_MATCH; } break; case GAMESTATE_GAME_OVER: if (timer - startTime >= GAME_OVER_TIMEOUT) { gameState = GAMESTATE_TITLE_SCREEN; startTime = time(0); } break; case GAMESTATE_ADD_GEMS: srand(time(NULL)); bool gemsAdded = false; // Find empty columns for (int column = 0; column < NUM_COLUMNS; column++) { // Find empty spaces in this column starting from top int row = 0; while (pGemsArray[pGridArray[row][column]].type == -1) { pGemsArray[pGridArray[row][column]].type = rand() % NUM_GEM_TYPES; pGemsArray[pGridArray[row][column]].state = GEMSTATE_ENTER; pGemsArray[pGridArray[row][column]].row = 0; pGemsArray[pGridArray[row][column]].column = column; pGemsArray[pGridArray[row][column]].y = -(ROW_HEIGHT+10)*(NUM_ROWS - row); pGemsArray[pGridArray[row][column]].velocity = 1; pGemsArray[pGridArray[row][column]].dropToRow = row; pGemsArray[pGridArray[row][column]].prevState = GEMSTATE_FALL; row++; gemsAdded = true; } } numGemsSelected = 0; if (gemsAdded) { gameState = GAMESTATE_DROP; } else { gameState = GAMESTATE_AWAIT_INPUT; } break; } if (gameState != GAMESTATE_TITLE_SCREEN) { for (int row = NUM_ROWS-1; row >= 0; row--) { for (int column = 0; column < NUM_COLUMNS; column++) { gem* thisGem = &pGemsArray[pGridArray[row][column]]; switch (pGemsArray[pGridArray[row][column]].state) { case GEMSTATE_IDLE: break; case GEMSTATE_FALL: case GEMSTATE_ENTER: if ((pGemsArray[pGridArray[row][column]].type != -1 && pGemsArray[pGridArray[row+1][column]].type == -1) || pGemsArray[pGridArray[row][column]].state == GEMSTATE_ENTER) { dropGem(pGridArray, &pGemsArray[pGridArray[row][column]], pGemsArray); } break; case GEMSTATE_BOUNCE: thisGem->y += thisGem->velocity; thisGem->velocity--; if (thisGem->y <= 0) { thisGem->y = 0; thisGem->velocity = 0; thisGem->state = GEMSTATE_IDLE; } break; } } } } timer = time(0); if (gameState != GAMESTATE_TITLE_SCREEN && gameState != GAMESTATE_GAME_OVER && timer - startTime >= TIMEOUT) { gameState = GAMESTATE_GAME_OVER; startTime = time(0); } //Read user input & handle it //Read any events that occured, for now we'll just quit if any event occurs while (SDL_PollEvent(&e)){ //If user closes the window if (e.type == SDL_QUIT){ quit = true; } //If user clicks the mouse if (e.type == SDL_MOUSEBUTTONDOWN){ if (gameState == GAMESTATE_TITLE_SCREEN) { gameState = GAMESTATE_INIT; } else { mouseX = e.button.x; mouseY = e.button.y; mouseDown = true; dragStartX = mouseX; dragStartY = mouseY; dragStarted = false; } } if (e.type == SDL_MOUSEBUTTONUP){ if (gameState != GAMESTATE_TITLE_SCREEN) { mouseDown = false; gemSelected = true; } } if (e.type == SDL_MOUSEMOTION && mouseDown) { if (e.motion.xrel < 0) // Dragged left { if (mouseX - e.motion.x > DRAG_DEAD_ZONE && !dragStarted) { // Start a new selection numGemsSelected = 0; dragStarted = true; gemSelected = true; } else if (mouseX - e.motion.x > DRAG_DEAD_ZONE && dragStarted) { // Select next gem mouseX -= COLUMN_WIDTH; mouseDown = false; gemSelected = true; } } else if (e.motion.xrel > 0) // Dragged right { if (e.motion.x - mouseX > DRAG_DEAD_ZONE && !dragStarted) { numGemsSelected = 0; dragStarted = true; gemSelected = true; } else if (e.motion.x - mouseX > DRAG_DEAD_ZONE && dragStarted) { mouseX += COLUMN_WIDTH; mouseDown = false; gemSelected = true; } } else if (e.motion.yrel < 0) // Dragged up { if (mouseY - e.motion.y > DRAG_DEAD_ZONE && !dragStarted) { numGemsSelected = 0; dragStarted = true; gemSelected = true; } else if (mouseY - e.motion.y > DRAG_DEAD_ZONE && dragStarted) { mouseY -= ROW_HEIGHT; mouseDown = false; gemSelected = true; } } else if (e.motion.yrel > 0) // Dragged down { if (e.motion.y - mouseY > DRAG_DEAD_ZONE && !dragStarted) { numGemsSelected = 0; dragStarted = true; gemSelected = true; } else if (e.motion.y - mouseY > DRAG_DEAD_ZONE && dragStarted) { mouseY += ROW_HEIGHT; mouseDown = false; gemSelected = true; } } } } //Render scene //First clear the renderer SDL_RenderClear(renderer); //Get the width and height from the texture so we know how much to move x,y by //to tile it correctly int bW, bH; SDL_QueryTexture(background, NULL, NULL, &bW, &bH); int x; int y; //Draw the background renderTexture(background, renderer, 0, 0); if (gameState != GAMESTATE_TITLE_SCREEN && gameState != GAMESTATE_INIT) { // Draw the gems // int rowHeight = GRID_HEIGHT / NUM_ROWS; int gemWidth, gemHeight; SDL_QueryTexture(gems[0], NULL, NULL, &gemWidth, &gemHeight); // Draw cursors if (numGemsSelected > 0) { int cursorWidth, cursorHeight; SDL_QueryTexture(cursorYellowImg, NULL, NULL, &cursorWidth, &cursorHeight); renderTexture(cursorYellowImg, renderer, selectedGems[0][COLUMN] * COLUMN_WIDTH + COLUMN_WIDTH/2 - cursorWidth/2, selectedGems[0][ROW] * ROW_HEIGHT + ROW_HEIGHT/2 - cursorHeight/2 + HUD_HEIGHT); if (numGemsSelected == 2) { renderTexture(cursorGreenImg, renderer, selectedGems[1][COLUMN] * COLUMN_WIDTH + COLUMN_WIDTH/2 - cursorWidth/2, selectedGems[1][ROW] * ROW_HEIGHT + ROW_HEIGHT/2 - cursorHeight/2 + HUD_HEIGHT); } } for (int i = 0; i < NUM_ROWS * NUM_COLUMNS; i++) { if (pGemsArray[i].type != -1) { x = COLUMN_WIDTH * pGemsArray[i].column + COLUMN_WIDTH/2 - gemWidth/2; y = ROW_HEIGHT * pGemsArray[i].row + ROW_HEIGHT/2 - gemHeight/2 + HUD_HEIGHT; renderTexture(gems[pGemsArray[i].type], renderer, x + pGemsArray[i].x, y + pGemsArray[i].y); } } } // Draw text int iW, iH; switch (gameState) { case GAMESTATE_TITLE_SCREEN: os.str(""); os.clear(); os << "Click mouse to start"; textImage = renderText(os.str(), font, color, renderer); if (textImage == nullptr){ return 1; } SDL_QueryTexture(textImage, NULL, NULL, &iW, &iH); SDL_QueryTexture(textImage, NULL, NULL, &iW, &iH); x = SCREEN_WIDTH/2 - iW/2; y = GRID_HEIGHT/2; renderTexture(textImage, renderer, x, y); break; case GAMESTATE_GAME_OVER: os.str(""); os.clear(); os << "GAME OVER. Your score is " << score; textImage = renderText(os.str(), font, color, renderer); if (textImage == nullptr){ return 1; } SDL_QueryTexture(textImage, NULL, NULL, &iW, &iH); SDL_QueryTexture(textImage, NULL, NULL, &iW, &iH); x = SCREEN_WIDTH/2 - iW/2; y = GRID_HEIGHT/2; renderTexture(textImage, renderer, x, y); break; default: os.str(""); os.clear(); os << "Score " << score; textImage = renderText(os.str(), font, color, renderer); if (textImage == nullptr){ return 1; } x = 10; y = 10; renderTexture(textImage, renderer, x, y); // drawText("Score ", score, renderer, textImage, font, color, 10, 10); os.str(""); os.clear(); os << "Time " << (TIMEOUT - (timer - startTime)); textImage = renderText(os.str(), font, color, renderer); if (textImage == nullptr){ return 1; } //Get the texture w/h so we can position it correctly on the screen SDL_QueryTexture(textImage, NULL, NULL, &iW, &iH); SDL_QueryTexture(textImage, NULL, NULL, &iW, &iH); x = SCREEN_WIDTH -10 - iW; renderTexture(textImage, renderer, x, y); // drawText seems to always draw to the left of the screen so commented out // drawText("Time ", timer - startTime, renderer, textImage, font, color, 100, 10); break; } //Update the screen SDL_RenderPresent(renderer); } //Clean up our objects and quit SDL_DestroyTexture(background); SDL_DestroyTexture(image); SDL_DestroyTexture(blueGem); SDL_DestroyTexture(greenGem); SDL_DestroyTexture(purpleGem); SDL_DestroyTexture(redGem); SDL_DestroyTexture(yellowGem); for (int i = 0; i < sizeof(*gems); i++) { gems[i] = NULL; } for (int row = 0; row < NUM_ROWS; row++) { delete [] pGridArray[row]; } delete [] pGridArray; delete [] pGemsArray; SDL_DestroyRenderer(renderer); SDL_DestroyWindow(window); SDL_Quit(); return 0; }
/** * \brief Painting function of the primitive interface * * Called by the parent frame whenever a primitive redraw is required. * \param drawSurface Pointer to a graphical surface where the primitive should * draw itself to. * \param paintArea The rectangular area of the parent frame surface that * should be re-painted by the primitive. */ void GuiMultiTextBox::onPaint(GuiSurface *drawSurface, s_rect_t &paintArea) { lock(); // return immediately if the primitive is not visible if(!isVisible) { unlock(); return; } // check if the multi-line text is rendered if(!isRendered) { // render the text and flip the flag renderText(); isRendered = true; } // sanity check, do we have any data to draw? if(fontData == NULL || numLines == 0) { unlock(); return; } // loop through all lines of text for(int i = 0; i < numLines; i ++) { s_font_t* font = fontData[i]; if (fontData[i] == NULL) continue; int ox = 0; switch(horzAlign) { case LEFT: ox = 0; break; case RIGHT: ox = drawArea.w - font->glyph.img->w; break; case HCENTER: ox = (drawArea.w - font->glyph.img->w) / 2; break; } s_rect_t textArea = { drawArea.x + ox, drawArea.y + i * fontSize, drawArea.w - ox, fontSize}; s_rect_t surfRect; if(s_region_rect_intersect(&paintArea, &textArea, &surfRect)) continue; s_rect_t sourceRect = { surfRect.x - textArea.x, surfRect.y - textArea.y, surfRect.w, surfRect.h }; #ifdef DEBUG printf("GuiMultiTextBox::onPaint: line <%d> %d, %d, %d, %d to %d, %d\n", i, font->glyph.img->x, font->glyph.img->y, font->glyph.img->w, font->glyph.img->h, surfRect.x, surfRect.y); #endif drawSurface->drawImagePart(surfRect.x, surfRect.y, &sourceRect, font->glyph.img); } unlock(); }
void GLWidget::drawInfo() { renderText(10,10,QString("Camera controls:"),QFont("Courier",11,4)); renderText(10,20,QString("-----------------"),QFont("Courier",9,2)); renderText(10,30,QString("Zoom In: W"),QFont("Courier",9,2)); renderText(10,40,QString("Zoom Out: S"),QFont("Courier",9,2)); renderText(10,50,QString("Rotate right: D"),QFont("Courier",9,2)); renderText(10,60,QString("Rotate left: A"),QFont("Courier",9,2)); renderText(10,70,QString("Rotate up: Q"),QFont("Courier",9,2)); renderText(10,80,QString("Rotate down: E"),QFont("Courier",9,2)); renderText(10,110,QString("Forklift controls:"),QFont("Courier",11,4)); renderText(10,120,QString("-----------------"),QFont("Courier",9,2)); renderText(10,130,QString("Run: O"),QFont("Courier",9,2)); renderText(10,140,QString("Back: L"),QFont("Courier",9,2)); renderText(10,170,QString("Arm controls:"),QFont("Courier",11,4)); renderText(10,180,QString("-----------------"),QFont("Courier",9,2)); renderText(10,190,QString("Put Up Arm: I"),QFont("Courier",9,2)); renderText(10,200,QString("Put Down Arm: K"),QFont("Courier",9,2)); }
void drawLine(char *p,int x1, int y1,int x2, int y2, int cc) { int i; float r[5] = {0.2,1.0,0.9,0.2,0.9}; float g[5] = {0.2,1.0,0.2,0.9,0.5}; float b[5] = {0.9,0.2,0.3,0.3,0.9}; for (i=0;i<5;i++) { if (p[i]=='1') { glColor3f(r[i],g[i],b[i]); glBegin(GL_QUADS); glVertex2f(x1,y1+50-i*23); glVertex2f(x1,y1+42-i*23); glVertex2f(x2,y1+42-i*23); glVertex2f(x2,y1+50-i*23); glEnd(); if (i>1) { glBegin(GL_TRIANGLES); glVertex2f(x2,y1+54-i*23); glVertex2f(x2,y1+38-i*23); glVertex2f(x2+20,y1+46-i*23); glEnd(); } glColor3f( 0.0f, 0.0f, 0.0f ); if (cc==1) renderText((x1+x2)/2-100,y1+54-i*23,s[i]); else if (cc==0) renderText((x1+x2)/2-10,y1+80-i*23,ss[i]); else renderText((x1+x2)/2+30,y1+10-i*23,ss[i]); } } for (i=5;i<8;i++) { if (p[i]=='1') { glColor3f(r[i-3],g[i-3],b[i-3]); glBegin(GL_QUADS); glVertex2f(x1,y1+50-(i-3)*23); glVertex2f(x1,y1+42-(i-3)*23); glVertex2f(x2,y1+42-(i-3)*23); glVertex2f(x2,y1+50-(i-3)*23); glEnd(); glBegin(GL_TRIANGLES); glVertex2f(x1,y1+38-(i-3)*23); glVertex2f(x1,y1+54-(i-3)*23); glVertex2f(x1-20,y1+46-(i-3)*23); glEnd(); glColor3f( 0.0f, 0.0f, 0.0f ); if (cc==1) renderText((x1+x2)/2-100,y1+54-(i-3)*23,s[i-3]); else if (cc==0) renderText((x1+x2)/2-10,y1+80-(i-3)*23,ss[i-3]); else renderText((x1+x2)/2+30,y1+10-(i-3)*23,ss[i-3]); } } }
void Renderer::renderText(std::string text, const SDL_Point &point, const SDL_Color &color, float scale) { renderText(text, point, color, scale, scale); }
void characterDesigner::render(drawer *draw) { cr->render(draw, SCREENWIDTH * 0.5f, SCREENHEIGHT * 0.5f - cr->getMaskHeight()); for (unsigned int i = 0; i <= data.size(); i++) { std::string name; switch(i) { case 0: name = "ROLE "; break; case 1: name = "GENDER "; break; case 2: name = "HAT "; break; case 3: name = "COLORATION "; break; case 4: name = "HAIR STYLE "; break; case 5: name = "HAIR COLOR "; break; case 6: name = "DONE"; break; } switch(i) { case 0: name += global_data->getLine(global_data->getValue(DATA_LIST, 1, data[i])); break; case 1: if (data[i] == 0) name += "MALE"; else name += "FEMALE"; break; case 2: name += global_data->getLine(global_data->getValue(DATA_LIST, 2, data[i] * 2 + 1)); break; case 6: break; //nothing default: name += std::to_string((long double) data[i]); break; } sf::Color c; if (i == y) c = INTERFACE_ACTIVECOLOR; else c = INTERFACE_INACTIVECOLOR; renderText(draw, name, c, 30.0f, 40.0f * i); } //make the description text std::string descText; switch(y) { case 0: descText = global_data->getLine(global_data->getValue(DATA_LIST, 1, data[y]) + 1); break; case 1: descText = "NOBODY CARES ABOUT GENDER DOWN IN THE UNDERGROUND^THEY ARE ALL TOO BUSY TRYING TO KILL YOU"; break; case 2: descText = global_data->getLine(global_data->getValue(DATA_LIST, 2, data[y] * 2 + 1) + 1); break; default: descText = ""; break; } renderText(draw, descText, INTERFACE_ACTIVECOLOR, SCREENWIDTH / 2, SCREENHEIGHT / 2, false, SCREENWIDTH / 2); }