void render(Game *game) { float w, h; glClear(GL_COLOR_BUFFER_BIT); //Draw shapes... static int firsttime = 1; static int verts[60][2]; static int n = 60; glColor3ub(50, 150,50); if(firsttime){ float angle = 0; float inc = (3.14459 * 2.0) / (float)n; for(int i = 0; i < n; i++){ verts[i][0] = cos(angle) * game->circle.radius + game->circle.center.x; verts[i][1] = sin(angle) * game->circle.radius + game->circle.center.y; angle += inc; } firsttime = 0; } glPushMatrix(); glBegin(GL_TRIANGLE_FAN); for(int i = 0; i < n; i++){ glVertex2i(verts[i][0], verts[i][1]); } glEnd(); glPopMatrix(); Rect rect; rect.bot=WINDOW_HEIGHT-30; rect.left=0; rect.center=0; ggprint16(&rect, 50, 0x00ffffff,"Waterfall Model"); //Draw the boxes here for(int j = 0; j < NUM_BOXES; j++){ Shape *s; glColor3ub(44,70,80); s = &game->box[j]; glPushMatrix(); glTranslatef(s->center.x, s->center.y, s->center.z); w = s->width; h = s->height; glBegin(GL_QUADS); glVertex2i(-w,-h); glVertex2i(-w, h); glVertex2i( w, h); glVertex2i( w,-h); glEnd(); glPopMatrix(); } //draw all particles here for(int i=0; i < game->n; i++){ int red = rand() % 20; int green = rand() % 100; int blue = rand() % 255; glPushMatrix(); glColor3ub(red,green, blue); Vec *c = &game->particle[i].s.center; w = 2; h = 2; glBegin(GL_QUADS); glVertex2i(c->x-w, c->y-h); glVertex2i(c->x-w, c->y+h); glVertex2i(c->x+w, c->y+h); glVertex2i(c->x+w, c->y-h); glEnd(); glPopMatrix(); } int bot = 240; int left = 55; int center = 0; Rect rect2; rect2.bot=bot; rect2.left=left; rect2.center=center; ggprint12(&rect2, 37, 0x00ffffff,"Requirements"); Rect rect3; rect3.bot=bot-30; rect3.left=left+75; rect3.center=center; ggprint12(&rect3, 37, 0x00ffffff,"Design"); Rect rect4; rect4.bot=bot - 60; rect4.left= left + 130; rect4.center=0; ggprint12(&rect4, 37, 0x10ffffff,"Coding"); Rect rect5; rect5.bot= bot -90; rect5.left= left + 180; rect5.center=0; ggprint12(&rect5, 37, 0x00ffffff,"Testing"); Rect rect6; rect6.bot= bot - 120; rect6.left= left + 210; rect6.center=0; ggprint12(&rect6, 37, 0x00ffffff,"Maintenance"); }
void CSM3GroundDrawer::Draw(const DrawPass::e& drawPass) { if (wireframe) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); } terrain::RenderContext* currc = rc; tr->SetShaderParams(sky->GetLight()->GetLightDir(), currc->cam->pos); if (shadowHandler->shadowsLoaded) { terrain::ShadowMapParams params; params.mid[0] = shadowHandler->GetShadowParams().x; params.mid[1] = shadowHandler->GetShadowParams().y; params.f_a = shadowHandler->GetShadowParams().z; params.f_b = shadowHandler->GetShadowParams().w; params.shadowMap = shadowHandler->shadowTexture; for (int a = 0; a < 16; a++) params.shadowMatrix[a] = shadowHandler->shadowMatrix[a]; tr->SetShadowParams(¶ms); } tr->SetActiveContext(currc); glEnable(GL_CULL_FACE); glFrontFace(GL_CW); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glEnable(GL_LIGHTING); glLightfv(GL_LIGHT0, GL_POSITION, sky->GetLight()->GetLightDir()); float d[4] = {0.0f, 0.0f, 0.0f, 1.0f}; const float z[] = {0.0f, 0.0f, 0.0f, 1.0f}; for (int a = 0; a < 3; a++) d[a] = mapInfo->light.groundSunColor[a]; glLightfv(GL_LIGHT0, GL_DIFFUSE, d); for (int a = 0; a < 3; a++) d[a] = mapInfo->light.groundAmbientColor[a]; glLightfv(GL_LIGHT0, GL_AMBIENT, d); for (int a = 0; a < 3; a++) d[a] = mapInfo->light.groundSpecularColor[a]; glLightfv(GL_LIGHT0, GL_SPECULAR, d); for (int a = 0; a < 4; a++) d[a] = 0.0f; glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, d); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, z); glDisable(GL_LIGHT1); glEnable(GL_LIGHT0); glEnable(GL_RESCALE_NORMAL); // glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION,dir.getf()); // glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 90.0f); /* const float ambient[] = { 0.4f, 0.4f, 0.4f, 1.0f }; const float diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f }; glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1); const float md[] = { 1.0f, 1.0f, 1.0f, 1.0f }; glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, md); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, md); glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 10.0f);*/ ///////////////////// tr->Draw(); glDisable(GL_LIGHT0); glDisable(GL_LIGHTING); if (wireframe) { glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); } if (drawMode != drawNormal) { glEnable(GL_BLEND); glDepthMask(GL_FALSE); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(0.0f, -10.0f); glColor4f(1.0f, 1.0f, 1.0f, 0.5f); tr->DrawOverlayTexture(infoTex); glDisable(GL_POLYGON_OFFSET_FILL); glDepthMask(GL_TRUE); glDisable(GL_BLEND); } glFrontFace(GL_CCW); glDisable(GL_CULL_FACE); glColor3ub(255, 255, 255); DrawObjects(drawPass); glActiveTextureARB(GL_TEXTURE0_ARB); glDisable(GL_TEXTURE_2D); }
void KinectImpl::drawNuiSkeleton(int width, int height, int playerID) { int scaleX = width; int scaleY = height; long x=0,y=0; unsigned short depth=0; float fx=0,fy=0; long cx=0,cy=0; float display_posf[NUI_SKELETON_POSITION_COUNT][2]; for (int i = 0; i < NUI_SKELETON_POSITION_COUNT; i++) { switch(showedTextureIndex){ case IMAGE_TEXTURE: NuiTransformSkeletonToDepthImage( skels[playerID][i], &x, &y, &depth); NuiImageGetColorPixelCoordinatesFromDepthPixel(NUI_IMAGE_RESOLUTION_640x480, NULL, x, y, depth, &cx, &cy); display_posf[i][0] = 1.0f - (cx / 640.0f) * 2.0f; display_posf[i][1] = 1.0f - (cy / 480.0f) * 2.0f; break; case DEPTH_TEXTURE: NuiTransformSkeletonToDepthImage( skels[playerID][i], &fx, &fy); display_posf[i][0] = 1.0f - fx / 320.0f * 2.0f; display_posf[i][1] = 1.0f - fy / 240.0f * 2.0f; break; default: break; } } glColor3ub(255, 255, 0); glLineWidth(6); glBegin(GL_LINE_STRIP); glVertex2f( display_posf[NUI_SKELETON_POSITION_HIP_CENTER][0], display_posf[NUI_SKELETON_POSITION_HIP_CENTER][1]); glVertex2f( display_posf[NUI_SKELETON_POSITION_SPINE][0], display_posf[NUI_SKELETON_POSITION_SPINE][1]); glVertex2f( display_posf[NUI_SKELETON_POSITION_SHOULDER_CENTER][0], display_posf[NUI_SKELETON_POSITION_SHOULDER_CENTER][1]); glVertex2f( display_posf[NUI_SKELETON_POSITION_HEAD][0], display_posf[NUI_SKELETON_POSITION_HEAD][1]); glEnd(); glBegin(GL_LINE_STRIP); glVertex2f( display_posf[NUI_SKELETON_POSITION_SHOULDER_CENTER][0], display_posf[NUI_SKELETON_POSITION_SHOULDER_CENTER][1]); glVertex2f( display_posf[NUI_SKELETON_POSITION_SHOULDER_LEFT][0], display_posf[NUI_SKELETON_POSITION_SHOULDER_LEFT][1]); glVertex2f( display_posf[NUI_SKELETON_POSITION_ELBOW_LEFT][0], display_posf[NUI_SKELETON_POSITION_ELBOW_LEFT][1]); glVertex2f( display_posf[NUI_SKELETON_POSITION_WRIST_LEFT][0], display_posf[NUI_SKELETON_POSITION_WRIST_LEFT][1]); glVertex2f( display_posf[NUI_SKELETON_POSITION_HAND_LEFT][0], display_posf[NUI_SKELETON_POSITION_HAND_LEFT][1]); glEnd(); glBegin(GL_LINE_STRIP); glVertex2f( display_posf[NUI_SKELETON_POSITION_SHOULDER_CENTER][0], display_posf[NUI_SKELETON_POSITION_SHOULDER_CENTER][1]); glVertex2f( display_posf[NUI_SKELETON_POSITION_SHOULDER_RIGHT][0], display_posf[NUI_SKELETON_POSITION_SHOULDER_RIGHT][1]); glVertex2f( display_posf[NUI_SKELETON_POSITION_ELBOW_RIGHT][0], display_posf[NUI_SKELETON_POSITION_ELBOW_RIGHT][1]); glVertex2f( display_posf[NUI_SKELETON_POSITION_WRIST_RIGHT][0], display_posf[NUI_SKELETON_POSITION_WRIST_RIGHT][1]); glVertex2f( display_posf[NUI_SKELETON_POSITION_HAND_RIGHT][0], display_posf[NUI_SKELETON_POSITION_HAND_RIGHT][1]); glEnd(); glBegin(GL_LINE_STRIP); glVertex2f( display_posf[NUI_SKELETON_POSITION_HIP_CENTER][0], display_posf[NUI_SKELETON_POSITION_HIP_CENTER][1]); glVertex2f( display_posf[NUI_SKELETON_POSITION_HIP_LEFT][0], display_posf[NUI_SKELETON_POSITION_HIP_LEFT][1]); glVertex2f( display_posf[NUI_SKELETON_POSITION_KNEE_LEFT][0], display_posf[NUI_SKELETON_POSITION_KNEE_LEFT][1]); glVertex2f( display_posf[NUI_SKELETON_POSITION_ANKLE_LEFT][0], display_posf[NUI_SKELETON_POSITION_ANKLE_LEFT][1]); glVertex2f( display_posf[NUI_SKELETON_POSITION_FOOT_LEFT][0], display_posf[NUI_SKELETON_POSITION_FOOT_LEFT][1]); glEnd(); glBegin(GL_LINE_STRIP); glVertex2f( display_posf[NUI_SKELETON_POSITION_HIP_CENTER][0], display_posf[NUI_SKELETON_POSITION_HIP_CENTER][1]); glVertex2f( display_posf[NUI_SKELETON_POSITION_HIP_RIGHT][0], display_posf[NUI_SKELETON_POSITION_HIP_RIGHT][1]); glVertex2f( display_posf[NUI_SKELETON_POSITION_KNEE_RIGHT][0], display_posf[NUI_SKELETON_POSITION_KNEE_RIGHT][1]); glVertex2f( display_posf[NUI_SKELETON_POSITION_ANKLE_RIGHT][0], display_posf[NUI_SKELETON_POSITION_ANKLE_RIGHT][1]); glVertex2f( display_posf[NUI_SKELETON_POSITION_FOOT_RIGHT][0], display_posf[NUI_SKELETON_POSITION_FOOT_RIGHT][1]); glEnd(); glColor3ub(0, 0, 0); }
void dna() { float cx = 250, cy = 215, r=100; glLineWidth(5.0); glPushMatrix(); glRotatef(45, 0, 0, -1); glPushMatrix(); glTranslatef(cx, cy, 0); glRotatef(theta, 0.0, 1.0, 0.0); glColor3ub(52, 152, 219); drawHelixStrand(0, cy, r, 0); glColor3ub(231, 76, 60); drawHelixStrand(0, cy, r, 138); drawHelixLine(0, cy, r, 138); glTranslatef(-cx, -cy, 0); glPopMatrix(); glPopMatrix(); theta+=0.75; glColor3ub(52, 73, 94); output(25, 540, "DNA is a molecule that encodes the genetic instructions", fonts[2]); output(25, 520, "used in the development and functioning of", fonts[2]); output(25, 500, "all known living organisms.", fonts[2]); glBegin(GL_LINES); glColor3ub(231, 76, 60); glVertex2f(25, 450); glVertex2f(45, 430); glColor3ub(52, 152, 219); glVertex2f(45, 450); glVertex2f(25, 430); glEnd(); glColor3ub(52, 73, 94); output(70, 435, "Helix Strands", fonts[2]); drawSphere(35, 400, 0); output(70, 395, "Phosphate Base", fonts[2]); glBegin(GL_LINES); glColor3ub(46, 204, 113); glVertex2f(25, 360); glVertex2f(50, 360); glEnd(); glColor3ub(52, 73, 94); output(70, 355, "Adenine", fonts[2]); glBegin(GL_LINES); glColor3ub(249, 148, 6); glVertex2f(25, 320); glVertex2f(50, 320); glEnd(); glColor3ub(52, 73, 94); output(70, 315, "Thymine", fonts[2]); glBegin(GL_LINES); glColor3ub(249, 191, 59); glVertex2f(25, 280); glVertex2f(50, 280); glEnd(); glColor3ub(52, 73, 94); output(70, 275, "Cytosine", fonts[2]); glBegin(GL_LINES); glColor3ub(155, 89, 182); glVertex2f(25, 240); glVertex2f(50, 240); glEnd(); glColor3ub(52, 73, 94); output(70, 235, "Guanine", fonts[2]); }
void cytosineGuanine() { float hex1[6][2], hex2[6][2]; float rx=512; //radius and color declarations GLubyte red[] = {15, 231, 76, 60}; //oxygen GLubyte green[] = {20, 39, 174, 96}; //carbon GLubyte blue[] = {20, 52, 152, 219}; //nitrogen GLubyte yellow[] = {10, 241, 196, 15}; //hydrogen getHexagonPoints(hex1, -192, 350, 75); getHexagonPoints(hex2, 192, 350, 75); glPushMatrix(); glTranslatef(rx, 0, 0); glRotatef(theta, 0.0, 1.0, 0.0); //hexagon 1 drawAtom(hex1[0][0], hex1[0][1], 0, green); drawAtom(hex1[1][0], hex1[1][1], 0, blue); drawAtom(hex1[2][0], hex1[2][1], 0, green); drawAtom(hex1[3][0], hex1[3][1], 0, green); drawAtom(hex1[4][0], hex1[4][1], 0, green); drawAtom(hex1[5][0], hex1[5][1], 0, blue); drawBondLine(hex1[0][0],hex1[0][1],0, hex1[1][0],hex1[1][1],0); drawBondLine(hex1[1][0],hex1[1][1],0, hex1[2][0],hex1[2][1],0); drawBondLine(hex1[2][0],hex1[2][1],0, hex1[3][0],hex1[3][1],0); drawBondLine(hex1[3][0],hex1[3][1],0, hex1[4][0],hex1[4][1],0); drawBondLine(hex1[4][0],hex1[4][1],0, hex1[5][0],hex1[5][1],0); drawBondLine(hex1[5][0],hex1[5][1],0, hex1[0][0],hex1[0][1],0); drawAtom(hex1[0][0], hex1[0][1]-50, 0, red); drawBondLine(hex1[0][0],hex1[0][1],0, hex1[0][0],hex1[0][1]-50,0); drawAtom(hex1[2][0]+50, hex1[2][1]+25, -50, blue); drawBondLine(hex1[2][0],hex1[2][1],0, hex1[2][0]+50,hex1[2][1]+25,-50); drawAtom(hex1[2][0]+50,hex1[2][1]+67.5, -50, yellow); drawBondLine(hex1[2][0]+50,hex1[2][1]+25,-50, hex1[2][0]+50,hex1[2][1]+67.5,-50); drawAtom(hex1[2][0]+85,hex1[2][1],-50, yellow); drawBondLine(hex1[2][0]+50,hex1[2][1]+25,-50, hex1[2][0]+85,hex1[2][1],-50); drawAtom(hex1[3][0],hex1[3][1]+25, -50, yellow); drawBondLine(hex1[3][0],hex1[3][1],0, hex1[3][0],hex1[3][1]+25,-50); drawAtom(hex1[4][0]-15,hex1[4][1]+15, 50, yellow); drawBondLine(hex1[4][0],hex1[4][1],0, hex1[4][0]-15,hex1[4][1]+15,50); //hexagon 2 drawAtom(hex2[0][0], hex2[0][1], 0, blue); drawAtom(hex2[1][0], hex2[1][1], 0, green); drawAtom(hex2[2][0], hex2[2][1], 0, green); drawAtom(hex2[3][0], hex2[3][1], 0, green); drawAtom(hex2[4][0], hex2[4][1], 0, blue); drawAtom(hex2[5][0], hex2[5][1], 0, green); drawBondLine(hex2[0][0],hex2[0][1],0, hex2[1][0],hex2[1][1],0); drawBondLine(hex2[1][0],hex2[1][1],0, hex2[2][0],hex2[2][1],0); drawBondLine(hex2[2][0],hex2[2][1],0, hex2[3][0],hex2[3][1],0); drawBondLine(hex2[3][0],hex2[3][1],0, hex2[4][0],hex2[4][1],0); drawBondLine(hex2[4][0],hex2[4][1],0, hex2[5][0],hex2[5][1],0); drawBondLine(hex2[5][0],hex2[5][1],0, hex2[0][0],hex2[0][1],0); drawAtom(hex2[1][0]+50, hex2[0][1]+25, 50, blue); drawBondLine(hex2[1][0],hex2[1][1],0, hex2[1][0]+50,hex2[0][1]+25,50); drawAtom(hex2[2][0]+50, hex2[3][1]-25, 50, blue); drawBondLine(hex2[2][0],hex2[2][1],0, hex2[2][0]+50,hex2[3][1]-25,50); drawAtom(hex2[2][0]+100,hex2[2][1]-37.5,75, green); drawBondLine(hex2[1][0]+50, hex2[0][1]+25, 50, hex2[2][0]+100,hex2[2][1]-37.5,75); drawBondLine(hex2[2][0]+50, hex2[3][1]-25, 50, hex2[2][0]+100,hex2[2][1]-37.5,75); drawAtom(hex2[2][0]+142.5,hex2[2][1]-37.5,75, yellow); drawBondLine(hex2[2][0]+100,hex2[2][1]-37.5,75, hex2[2][0]+142.5,hex2[2][1]-37.5,75); drawAtom(hex2[3][0], hex2[3][1]+50, 0, red); drawBondLine(hex2[3][0],hex2[3][1],0, hex2[3][0],hex2[3][1]+50,0); drawAtom(hex2[4][0]-25, hex2[4][1]+25, 0, yellow); drawBondLine(hex2[4][0],hex2[4][1],0, hex2[4][0]-25,hex2[4][1]+25,0); drawAtom(hex2[5][0]-50, hex2[0][1]+25, 50, blue); drawBondLine(hex2[5][0],hex2[5][1],0, hex2[5][0]-50,hex2[0][1]+25,50); drawAtom(hex2[5][0]-50, hex2[0][1]-15, 50, yellow); drawBondLine(hex2[5][0]-50,hex2[0][1]+25,50, hex2[5][0]-50,hex2[0][1]-15,50); drawAtom(hex2[5][0]-85, hex2[0][1]+60, 50, yellow); drawBondLine(hex2[5][0]-50,hex2[0][1]+25,50, hex2[5][0]-85,hex2[0][1]+60,50); //H-bonds glLineWidth(1.5); glBegin(GL_LINES); glVertex3f(hex1[0][0],hex1[0][1]-50,0); glVertex3f(hex2[5][0]-85,hex2[0][1]+60,50); glVertex3f(hex1[1][0],hex1[1][1],0); glVertex3f(hex2[4][0]-25,hex2[4][1]+25,0); glVertex3f(hex1[2][0]+85,hex1[2][1],-50); glVertex3f(hex2[3][0],hex2[3][1]+50,0); glEnd(); glTranslatef(-rx, 0, 0); glPopMatrix(); theta+=0.25; drawLegend(); glColor3ub(52, 73, 94); output(300, 190, "Cytosine recognizes specific DNA sequences and catalyzes", fonts[2]); output(300, 170, "the transfer of a methyl group.", fonts[2]); output(300, 130, "Guanine can carry energy and if bound to special receptors,", fonts[2]); output(300, 110, "can help carry signals from one part of the cell to another.", fonts[2]); }
void world_display(void) { GLfloat pos[] = { 0.0, 0.0, 1.0, 0.0 }; double length; float l[3]; l[0] = at[0] - eye[0]; l[1] = at[0] - eye[1]; l[2] = at[0] - eye[2]; length = normalize(l); invert(modelview, inverse); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if (world_draw) { glEnable(GL_LIGHTING); glPushMatrix(); glMultMatrixd(inverse); glLightfv(GL_LIGHT0, GL_POSITION, pos); glPopMatrix(); drawmodel(); glDisable(GL_LIGHTING); } glPushMatrix(); glMultMatrixd(inverse); glLightfv(GL_LIGHT0, GL_POSITION, pos); /* draw the axis and eye vector */ glPushMatrix(); glColor3ub(0, 0, 255); glBegin(GL_LINE_STRIP); glVertex3f(0.0, 0.0, 0.0); glVertex3f(0.0, 0.0, -1.0*length); glVertex3f(0.1, 0.0, -0.9*length); glVertex3f(-0.1, 0.0, -0.9*length); glVertex3f(0.0, 0.0, -1.0*length); glVertex3f(0.0, 0.1, -0.9*length); glVertex3f(0.0, -0.1, -0.9*length); glVertex3f(0.0, 0.0, -1.0*length); glEnd(); glColor3ub(255, 255, 0); glRasterPos3f(0.0, 0.0, -1.1*length); glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, 'e'); glColor3ub(255, 0, 0); glScalef(0.4, 0.4, 0.4); drawaxes(); glPopMatrix(); invert(projection, inverse); glMultMatrixd(inverse); /* draw the viewing frustum */ glColor3f(0.2, 0.2, 0.2); glBegin(GL_QUADS); glVertex3i(1, 1, 1); glVertex3i(-1, 1, 1); glVertex3i(-1, -1, 1); glVertex3i(1, -1, 1); glEnd(); glColor3ub(128, 196, 128); glBegin(GL_LINES); glVertex3i(1, 1, -1); glVertex3i(1, 1, 1); glVertex3i(-1, 1, -1); glVertex3i(-1, 1, 1); glVertex3i(-1, -1, -1); glVertex3i(-1, -1, 1); glVertex3i(1, -1, -1); glVertex3i(1, -1, 1); glEnd(); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(0.2, 0.2, 0.4, 0.5); glBegin(GL_QUADS); glVertex3i(1, 1, -1); glVertex3i(-1, 1, -1); glVertex3i(-1, -1, -1); glVertex3i(1, -1, -1); glEnd(); glDisable(GL_BLEND); glPopMatrix(); glutSwapBuffers(); }
void invRTSGame::selection(int height) { if(pause_game || !picking_enable) return; mouse_over = NULL; // draw a black terrain if(draw_map) { glColor3ub(0, 0, 0); drawgrid->draw(fow, false); terrainPoint(); } if(selection_unit) return; if(sinput->mousebutton == SDL_BUTTON_LEFT && sinput->mousestate == 1) { startMouseSelX = sinput->mousex; startMouseSelY = sinput->mousey; startAreaSelX = terrainX; startAreaSelZ = terrainZ; areaSel = true; } else if(sinput->mousebutton == SDL_BUTTON_LEFT && sinput->mousestate == 2) { startMouseSelX = endMouseSelX; startMouseSelY = endMouseSelY; endAreaSelX = terrainX; endAreaSelZ = terrainZ; areaSel = false; } if(areaSel) { endMouseSelX = sinput->mousex; endMouseSelY = sinput->mousey; endAreaSelX = terrainX; endAreaSelZ = terrainZ; } int deltaX = endMouseSelX - startMouseSelX; int deltaY = endMouseSelY - startMouseSelY; if(areaSel && (deltaX * deltaY) > 5 * 5) { selectEntityInArea(); } // TODO : Optimize this !! else{ Uint8 limitcolor = 1; nb_selected = 0; entities.rewind(); while(!entities.isEnd()) { invEntity* e = entities.current(); if(e->mdef->selectable) { glColor3ub(limitcolor++, 0, 0); // draw the box glPushMatrix(); glTranslatef(e->pos.x, 0.f, e->pos.z); drawCube(e->mdef->bx, 2.5f, e->mdef->bz); glPopMatrix(); } entities.next(); } int selected_color = picking(sinput->mousex, height - sinput->mousey); limitcolor = 1; entities.rewind(); while(!entities.isEnd()) { if(entities.current()->mdef->selectable && selected_color == limitcolor++) { nb_selected = 1; mouse_over = entities.current(); break; } entities.next(); } if(sinput->mousebutton == SDL_BUTTON_LEFT && sinput->mousestate == 1) { if(nb_selected) { nb_selectedl = 1; selectedl[0] = mouse_over; } } if(sinput->mousebutton == SDL_BUTTON_RIGHT && sinput->mousestate == 1) { nb_selectedr = nb_selected; if(nb_selectedr) selectedr = mouse_over; if(nb_selectedr) { lua_pushnumber(mainL, selectedr->id); lua_setglobal(mainL, "target_unit"); } else { lua_pushnil(mainL); lua_setglobal(mainL, "target_unit"); } } } // notice lua lua_pushnumber(mainL, nb_selectedl); lua_setglobal(mainL, "nb_selected"); if(nb_selectedl) { lua_getglobal(mainL, "selected_units"); for(int i=0;i<nb_selectedl;i++) { lua_pushnumber(mainL, i+1); lua_pushnumber(mainL, selectedl[i]->id); lua_rawset(mainL, -3); } lua_pop(mainL, 1); } }
void RenderScene(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); glRotatef(xRot, 1.0f, 0.0f, 0.0f); glRotatef(yRot, 0.0f,1.0f,0.0f); glScalef(20.0f, 20.0f, 20.0f); glBegin(GL_TRIANGLES); //(0, 3, 2) // 0 glColor3ub((GLubyte)0, (GLubyte)0, (GLubyte)255); glVertex3f(-1.0f, -1.0f, -1.0f); // 3 glColor3ub((GLubyte)0, (GLubyte)255, (GLubyte)0); glVertex3f(1.0f, 1.0f, -1.0f); // 2 glColor3ub((GLubyte)255, (GLubyte)0, (GLubyte)0); glVertex3f(-1.0f, 1.0f, -1.0f); //(0, 1, 3) // 0 glColor3ub((GLubyte)0, (GLubyte)0, (GLubyte)255); glVertex3f(-1.0f, -1.0f, -1.0f); // 1 glColor3ub((GLubyte)255, (GLubyte)255, (GLubyte)0); glVertex3f(1.0f, -1.0f, -1.0f); // 3 glColor3ub((GLubyte)0, (GLubyte)255, (GLubyte)0); glVertex3f(1.0f, 1.0f, -1.0f); //(2, 6, 7) // 2 glColor3ub((GLubyte)255, (GLubyte)0, (GLubyte)0); glVertex3f(-1.0f, 1.0f, -1.0f); //6 glColor3ub((GLubyte)255, (GLubyte)0, (GLubyte)0); glVertex3f(1.0f, 1.0f, 1.0f); //7 glColor3ub((GLubyte)255, (GLubyte)255, (GLubyte) 0); glVertex3f(-1.0f, 1.0f, 1.0f); //(2, 3, 6) // 2 glColor3ub((GLubyte)255, (GLubyte)0, (GLubyte)0); glVertex3f(-1.0f, 1.0f, -1.0f); // 3 glColor3ub((GLubyte)0, (GLubyte)255, (GLubyte)0); glVertex3f(1.0f, 1.0f, -1.0f); //6 glColor3ub((GLubyte)255, (GLubyte)0, (GLubyte)0); glVertex3f(1.0f, 1.0f, 1.0f); //(7,4,5) //7 glColor3ub((GLubyte)255, (GLubyte)255, (GLubyte) 0); glVertex3f(-1.0f, 1.0f, 1.0f); //4 glColor3ub((GLubyte)0, (GLubyte)255, (GLubyte)0); glVertex3f(-1.0f, -1.0f, 1.0f); //5 glColor3ub((GLubyte)0, (GLubyte)0, (GLubyte)255); glVertex3f(1.0f, -1.0f, 1.0f); //(5,6,7) //5 glColor3ub((GLubyte)0, (GLubyte)0, (GLubyte)255); glVertex3f(1.0f, -1.0f, 1.0f); //6 glColor3ub((GLubyte)255, (GLubyte)0, (GLubyte)0); glVertex3f(1.0f, 1.0f, 1.0f); //7 glColor3ub((GLubyte)255, (GLubyte)255, (GLubyte) 0); glVertex3f(-1.0f, 1.0f, 1.0f); //(3,1,5) // 3 glColor3ub((GLubyte)0, (GLubyte)255, (GLubyte)0); glVertex3f(1.0f, 1.0f, -1.0f); // 1 glColor3ub((GLubyte)255, (GLubyte)255, (GLubyte)0); glVertex3f(1.0f, -1.0f, -1.0f); //5 glColor3ub((GLubyte)0, (GLubyte)0, (GLubyte)255); glVertex3f(1.0f, -1.0f, 1.0f); //(3,5,6) // 3 glColor3ub((GLubyte)0, (GLubyte)255, (GLubyte)0); glVertex3f(1.0f, 1.0f, -1.0f); //5 glColor3ub((GLubyte)0, (GLubyte)0, (GLubyte)255); glVertex3f(1.0f, -1.0f, 1.0f); //6 glColor3ub((GLubyte)255, (GLubyte)0, (GLubyte)0); glVertex3f(1.0f, 1.0f, 1.0f); //(7,4,2) //7 glColor3ub((GLubyte)255, (GLubyte)255, (GLubyte) 0); glVertex3f(-1.0f, 1.0f, 1.0f); //4 glColor3ub((GLubyte)0, (GLubyte)255, (GLubyte)0); glVertex3f(-1.0f, -1.0f, 1.0f); // 2 glColor3ub((GLubyte)255, (GLubyte)0, (GLubyte)0); glVertex3f(-1.0f, 1.0f, -1.0f); //(2,4,0) // 2 glColor3ub((GLubyte)255, (GLubyte)0, (GLubyte)0); glVertex3f(-1.0f, 1.0f, -1.0f); //4 glColor3ub((GLubyte)0, (GLubyte)255, (GLubyte)0); glVertex3f(-1.0f, -1.0f, 1.0f); // 0 glColor3ub((GLubyte)0, (GLubyte)0, (GLubyte)255); glVertex3f(-1.0f, -1.0f, -1.0f); //(4,0,1) //4 glColor3ub((GLubyte)0, (GLubyte)255, (GLubyte)0); glVertex3f(-1.0f, -1.0f, 1.0f); // 0 glColor3ub((GLubyte)0, (GLubyte)0, (GLubyte)255); glVertex3f(-1.0f, -1.0f, -1.0f); // 1 glColor3ub((GLubyte)255, (GLubyte)255, (GLubyte)0); glVertex3f(1.0f, -1.0f, -1.0f); //(4,1,5) //4 glColor3ub((GLubyte)0, (GLubyte)255, (GLubyte)0); glVertex3f(-1.0f, -1.0f, 1.0f); // 1 glColor3ub((GLubyte)255, (GLubyte)255, (GLubyte)0); glVertex3f(1.0f, -1.0f, -1.0f); //5 glColor3ub((GLubyte)0, (GLubyte)0, (GLubyte)255); glVertex3f(1.0f, -1.0f, 1.0f); glEnd(); // Flush drawing commands glPopMatrix(); glutSwapBuffers(); }
//-------------------------------------------------------------- // Name: CBRUTE_FORCE::Render - public // Description: Render the terrain height field // Arguments: None // Return Value: None //-------------------------------------------------------------- void CBRUTE_FORCE::Render( void ) { float fTexLeft, fTexBottom, fTexTop; int x, z; //reset the counting variables m_iVertsPerFrame= 0; m_iTrisPerFrame = 0; //cull non camera-facing polygons glEnable( GL_CULL_FACE ); if( m_bMultitexture && m_bDetailMapping && m_bTextureMapping ) { glDisable( GL_BLEND ); //bind the primary color texture to the first texture unit glActiveTextureARB( GL_TEXTURE0_ARB ); glEnable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, m_texture.GetID( ) ); //bind the detail color texture to the second texture unit glActiveTextureARB( GL_TEXTURE1_ARB ); glEnable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, m_detailMap.GetID( ) ); glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB ); glTexEnvi( GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 2 ); //loop through the Z-axis of the terrain for( z=0; z<m_iSize-1; z++ ) { //begin a new triangle strip glBegin( GL_TRIANGLE_STRIP ); //loop through the X-axis of the terrain //this is where the triangle strip is constructed for( x=0; x<m_iSize-1; x++ ) { //calculate the texture coordinates fTexLeft = ( float )x/m_iSize; fTexBottom= ( float )z/m_iSize; fTexTop = ( float )( z+1 )/m_iSize; //set the color with OpenGL, and render the point glColor3ub( 255, 255, 255 ); glMultiTexCoord2fARB( GL_TEXTURE0_ARB, fTexLeft, fTexBottom ); glMultiTexCoord2fARB( GL_TEXTURE1_ARB, fTexLeft*m_iRepeatDetailMap, fTexBottom*m_iRepeatDetailMap ); glVertex3f( ( float )x, GetScaledHeightAtPoint( x, z ), ( float )z ); //set the color with OpenGL, and render the point glColor3ub( 255, 255, 255 ); glMultiTexCoord2fARB( GL_TEXTURE0_ARB, fTexLeft, fTexTop ); glMultiTexCoord2fARB( GL_TEXTURE1_ARB, fTexLeft*m_iRepeatDetailMap, fTexTop*m_iRepeatDetailMap ); glVertex3f( ( float )x, GetScaledHeightAtPoint( x, z+1 ), ( float )z+1 ); //increase the vertex count by two (which is how many we sent to the API) m_iVertsPerFrame+= 2; //there are no triangles being rendered on the first X-loop, they just start the //triangle strip off if( x!= 0 ) m_iTrisPerFrame+= 2; } //end the triangle strip glEnd( ); } //unbind the texture occupying the second texture unit glActiveTextureARB( GL_TEXTURE1_ARB ); glDisable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, 0 ); //unbind the texture occupying the first texture unit glActiveTextureARB( GL_TEXTURE0_ARB ); glDisable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, 0 ); } //multitexturing is not enabled, which means we'll have to do a seperate texture //pass if detail mapping is needed else { if( m_bTextureMapping ) { //bind the primary color texture (FOR THE PRIMARY TEXTURE PASS) glActiveTextureARB( GL_TEXTURE0_ARB ); glEnable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, m_texture.GetID( ) ); //loop through the Z-axis of the terrain for( z=0; z<m_iSize-1; z++ ) { //begin a new triangle strip glBegin( GL_TRIANGLE_STRIP ); //loop through the X-axis of the terrain //this is where the triangle strip is constructed for( x=0; x<m_iSize-1; x++ ) { //calculate the texture coordinates fTexLeft = ( float )x/m_iSize; fTexBottom= ( float )z/m_iSize; fTexTop = ( float )( z+1 )/m_iSize; //set the color with OpenGL, and render the point glColor3ub( 255, 255, 255 ); glMultiTexCoord2fARB( GL_TEXTURE0_ARB, fTexLeft, fTexBottom ); glVertex3f( ( float )x, GetScaledHeightAtPoint( x, z ), ( float )z ); //set the color with OpenGL, and render the point glColor3ub( 255, 255, 255 ); glMultiTexCoord2fARB( GL_TEXTURE0_ARB, fTexLeft, fTexTop ); glVertex3f( ( float )x, GetScaledHeightAtPoint( x, z+1 ), ( float )z+1 ); //increase the vertex count by two (which is how many we sent to the API) m_iVertsPerFrame+= 2; //there are no triangles being rendered on the first X-loop, they just start the //triangle strip off if( x!= 0 ) m_iTrisPerFrame+= 2; } //end the triangle strip glEnd( ); } } //if the user wants detail mapping, we need to set some things up if( m_bDetailMapping ) { //bind the detail texture glActiveTextureARB( GL_TEXTURE0_ARB ); glEnable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, m_detailMap.GetID( ) ); //only use blending if a texture pass was made if( m_bTextureMapping ) { glEnable( GL_BLEND ); glBlendFunc( GL_ZERO, GL_SRC_COLOR ); } } //if there is no detail mapping, but a texture pass was made //then we don't need to continue else if( m_bTextureMapping ) return; //the user didn't want detail texturing nor color texturing, //but we still need to render the terrain else { //unbind the first texture unit glActiveTextureARB( GL_TEXTURE0_ARB ); glDisable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, 0 ); } //loop through the Z-axis of the terrain for( z=0; z<m_iSize-1; z++ ) { //begin a new triangle strip glBegin( GL_TRIANGLE_STRIP ); //loop through the X-axis of the terrain //this is where the triangle strip is constructed for( x=0; x<m_iSize-1; x++ ) { //calculate the texture coordinates fTexLeft = ( float )x/m_iSize; fTexBottom= ( float )z/m_iSize; fTexTop = ( float )( z+1 )/m_iSize; //set the color with OpenGL, and render the point glColor3ub( 255, 255, 255 ); glMultiTexCoord2fARB( GL_TEXTURE0_ARB, fTexLeft*m_iRepeatDetailMap, fTexBottom*m_iRepeatDetailMap ); glVertex3f( ( float )x, GetScaledHeightAtPoint( x, z ), ( float )z ); //set the color with OpenGL, and render the point glColor3ub( 255, 255, 255 ); glMultiTexCoord2fARB( GL_TEXTURE0_ARB, fTexLeft*m_iRepeatDetailMap, fTexTop*m_iRepeatDetailMap ); glVertex3f( ( float )x, GetScaledHeightAtPoint( x, z+1 ), ( float )z+1 ); //increase the vertex count by two (which is how many we sent to the API) m_iVertsPerFrame+= 2; //there are no triangles being rendered on the first X-loop, they just start the //triangle strip off if( x!= 0 ) m_iTrisPerFrame+= 2; } //end the triangle strip glEnd( ); } glDisable( GL_BLEND ); } }
void renderParticles() // main render function { int currentParticleType = PART_EMPTY; float tx = 640.0/screen_width; float ty = 480.0/screen_height; glBegin(GL_QUADS); for(int y = 0; y < screen_height; y++) { for(int x = 0; x < screen_width; x++) { float cx = tx*x; float cy = ty*y; currentParticleType = partAt(x,y).type; if(currentParticleType != PART_EMPTY ) { switch(currentParticleType) { case PART_EMPTY: break; case PART_FIRE: simFire(x,y); glColor3ub(255,32,32); break; case PART_PROPANE: simPropane(x,y); glColor3ub(255,255,255); break; case PART_WALL: simWall(x,y); glColor3ub(128,128,128); break; case PART_NAPALM: simNapalm(x,y); glColor3ub(128,128,0); break; case PART_WATER: simWater(x,y); glColor3ub(64,64,255); break; case PART_SAND: simSand(x,y); glColor3ub(255,255,130); break; case PART_GUNPOWDER: simGunPowder(x,y); glColor3ub(200,200,200); break; case PART_NITRO: simNitro(x,y); glColor3ub(25,230,25); break; case PART_STEAM: simSteam(x,y); glColor3ub(200,200,250); break; } } else { glColor3f(0,0,0); } glVertex2f(cx,cy); glVertex2f(cx+tx,cy); glVertex2f(cx+tx,cy+ty); glVertex2f(cx,cy+ty); } } glEnd(); }
void OpenglManager::writeFieldObjectsToDisplay(FieldObjects* AllObjects, GLDisplay::display displayId) { //! CLEAR DRAWING LIST if(displayStored[displayId]) { glDeleteLists(displays[displayId],1); } displays[displayId] = glGenLists(1); glNewList(displays[displayId],GL_COMPILE); // START OF LIST glDisable(GL_TEXTURE_2D); glLineWidth(2.0); // Line width //! DRAW STATIONARY OBJECTS: vector < StationaryObject > ::iterator statFOit; for(statFOit = AllObjects->stationaryFieldObjects.begin(); statFOit < AllObjects->stationaryFieldObjects.end(); ) { //! Check if the object is seen, if seen then continue to next Object if((*statFOit).isObjectVisible() == false) { ++statFOit; continue; } unsigned char r,g,b; if( (*statFOit).getID() == FieldObjects::FO_BLUE_LEFT_GOALPOST || (*statFOit).getID() == FieldObjects::FO_BLUE_RIGHT_GOALPOST ) { ClassIndex::getColourIndexAsRGB(ClassIndex::blue,r,g,b); glColor3ub(r,g,b); } else if( (*statFOit).getID() == FieldObjects::FO_YELLOW_LEFT_GOALPOST || (*statFOit).getID() == FieldObjects::FO_YELLOW_RIGHT_GOALPOST ) { ClassIndex::getColourIndexAsRGB(ClassIndex::yellow,r,g,b); glColor3ub(r,g,b); } else { ClassIndex::getColourIndexAsRGB(ClassIndex::white,r,g,b); glColor3ub(r,g,b); } if((*statFOit).getID() == FieldObjects::FO_CORNER_CENTRE_CIRCLE) { drawEllipse((*statFOit).ScreenX(),(*statFOit).ScreenY(), (*statFOit).getObjectWidth()/2, (*statFOit).getObjectHeight()/2); ++statFOit; continue; } int X = (*statFOit).ScreenX(); int Y = (*statFOit).ScreenY(); int ObjectWidth = (*statFOit).getObjectWidth(); int ObjectHeight = (*statFOit).getObjectHeight(); glBegin(GL_QUADS); // Start Lines glVertex2i( X-ObjectWidth/2, Y-ObjectHeight/2); //TOP LEFT glVertex2i( X+ObjectWidth/2, Y-ObjectHeight/2); //TOP RIGHT glVertex2i( X+ObjectWidth/2, Y+ObjectHeight/2); //BOTTOM RIGHT glVertex2i( X-ObjectWidth/2, Y+ObjectHeight/2); //BOTTOM LEFT glEnd(); //! Incrememnt to next object: ++statFOit; } //! DRAW MOBILE OBJECTS: vector < MobileObject > ::iterator mobileFOit; for(mobileFOit = AllObjects->mobileFieldObjects.begin(); mobileFOit < AllObjects->mobileFieldObjects.end(); ) { //! Check if the object is seen, if seen then continue to next Object if((*mobileFOit).isObjectVisible() == false) { ++mobileFOit; continue; } qDebug() << "Seen: Mobile: " <<(*mobileFOit).getID() ; unsigned char r,g,b; //CHECK IF BALL: if so Draw a circle if( (*mobileFOit).getID() == FieldObjects::FO_BALL) { ClassIndex::getColourIndexAsRGB(ClassIndex::orange,r,g,b); glColor3ub(r,g,b); int cx = (*mobileFOit).ScreenX(); int cy = (*mobileFOit).ScreenY(); int radius = (*mobileFOit).getObjectWidth()/2; int num_segments = 360; drawSolidCircle(cx, cy, radius, num_segments); ++mobileFOit; continue; } if( (*mobileFOit).getID() == FieldObjects::FO_BLUE_ROBOT_1 || (*mobileFOit).getID() == FieldObjects::FO_BLUE_ROBOT_2 || (*mobileFOit).getID() == FieldObjects::FO_BLUE_ROBOT_3 || (*mobileFOit).getID() == FieldObjects::FO_BLUE_ROBOT_4 ) { ClassIndex::getColourIndexAsRGB(ClassIndex::shadow_blue,r,g,b); glColor3ub(r,g,b); } else if( (*mobileFOit).getID() == FieldObjects::FO_PINK_ROBOT_1 || (*mobileFOit).getID() == FieldObjects::FO_PINK_ROBOT_2 || (*mobileFOit).getID() == FieldObjects::FO_PINK_ROBOT_3 || (*mobileFOit).getID() == FieldObjects::FO_PINK_ROBOT_4) { ClassIndex::getColourIndexAsRGB(ClassIndex::pink,r,g,b); glColor3ub(r,g,b); } int X = (*mobileFOit).ScreenX(); int Y = (*mobileFOit).ScreenY(); int ObjectWidth = (*mobileFOit).getObjectWidth(); int ObjectHeight = (*mobileFOit).getObjectHeight(); glBegin(GL_LINE_STRIP); // Start Lines glVertex2i( X-ObjectWidth/2, Y-ObjectHeight/2); glVertex2i( X-ObjectWidth/2, Y+ObjectHeight/2); glVertex2i( X+ObjectWidth/2, Y+ObjectHeight/2); glVertex2i( X+ObjectWidth/2, Y-ObjectHeight/2); glVertex2i( X-ObjectWidth/2, Y-ObjectHeight/2); glEnd(); //! Increment to next object ++mobileFOit; } //! DRAW AMBIGUOUS OBJECTS: Using itterator as size is unknown vector < AmbiguousObject > ::iterator ambigFOit; qDebug() <<"Size Of Ambig Objects: " << AllObjects->ambiguousFieldObjects.size(); for(ambigFOit = AllObjects->ambiguousFieldObjects.begin(); ambigFOit < AllObjects->ambiguousFieldObjects.end(); ) { //! Check if the object is seen, if seen then continue to next Object if((*ambigFOit).isObjectVisible() == false) { ++ambigFOit; continue; } qDebug() <<"Ambig Objects seen: " << (*ambigFOit).getID(); unsigned char r,g,b; if( (*ambigFOit).getID() == FieldObjects::FO_BLUE_ROBOT_UNKNOWN) { ClassIndex::getColourIndexAsRGB(ClassIndex::shadow_blue,r,g,b); glColor3ub(r,g,b); } else if( (*ambigFOit).getID() == FieldObjects::FO_PINK_ROBOT_UNKNOWN) { ClassIndex::getColourIndexAsRGB(ClassIndex::pink,r,g,b); glColor3ub(r,g,b); } else if( (*ambigFOit).getID() == FieldObjects::FO_BLUE_GOALPOST_UNKNOWN) { ClassIndex::getColourIndexAsRGB(ClassIndex::blue,r,g,b); glColor3ub(r,g,b); } else if( (*ambigFOit).getID() == FieldObjects::FO_YELLOW_GOALPOST_UNKNOWN) { ClassIndex::getColourIndexAsRGB(ClassIndex::yellow,r,g,b); glColor3ub(r,g,b); } else { ClassIndex::getColourIndexAsRGB(ClassIndex::white,r,g,b); glColor3ub(r,g,b); } int X = (*ambigFOit).ScreenX(); int Y = (*ambigFOit).ScreenY(); int ObjectWidth = (*ambigFOit).getObjectWidth(); int ObjectHeight = (*ambigFOit).getObjectHeight(); glBegin(GL_LINE_STRIP); // Start Lines glVertex2i( X-ObjectWidth/2, Y-ObjectHeight/2); glVertex2i( X-ObjectWidth/2, Y+ObjectHeight/2); glVertex2i( X+ObjectWidth/2, Y+ObjectHeight/2); glVertex2i( X+ObjectWidth/2, Y-ObjectHeight/2); glVertex2i( X-ObjectWidth/2, Y-ObjectHeight/2); glEnd(); //! Increment to next object ++ambigFOit; } //! UPDATE THE DISPLAY: glEnable(GL_TEXTURE_2D); glEndList(); // END OF LIST displayStored[displayId] = true; emit updatedDisplay(displayId, displays[displayId], width, height); }
void SCurve::Draw() { int i; glLineWidth( 1.0 ); // glColor3ub( 255, 0, 255 ); glBegin( GL_LINE_STRIP ); for ( i = 0 ; i < (int)m_UWTess.size() ; i++ ) { vec3d p = m_Surf->CompPnt( m_UWTess[i].x(), m_UWTess[i].y() ); glVertex3dv( p.data() ); } glEnd(); glPointSize( 2.0f ); glColor3ub( 255, 255, 0 ); glBegin( GL_POINTS ); for ( i = 0 ; i < (int)m_UWTess.size() ; i++ ) { vec3d p = m_Surf->CompPnt( m_UWTess[i].x(), m_UWTess[i].y() ); glVertex3dv( p.data() ); } glEnd(); //glPointSize( 8.0f ); //glColor3ub( 0, 255, 0 ); //glBegin( GL_POINTS ); //int num_sec = m_UWCrv.get_num_sections(); //int num_ctl = 3*(num_sec) + 1; //for ( i = 0 ; i < num_ctl ; i++ ) //{ // vec3d uw = m_UWCrv.get_pnt( i ); // vec3d p = m_Surf->CompPnt( uw.x(), uw.y() ); // glVertex3dv( p.data() ); //} //glEnd(); //glBegin( GL_LINE_STRIP ); //for ( i = 0 ; i < 100 ; i++ ) //{ // double u = (double)i/99.0; // vec3d uw = m_UWCrv.comp_pnt(u); // vec3d p = m_Surf->CompPnt( uw.x(), uw.y() ); // glVertex3dv( p.data() ); //} //glEnd(); //glPointSize( 4.0f ); //glColor3ub( 255, 255, 0 ); //glBegin( GL_POINTS ); //for ( i = 0 ; i < 100 ; i++ ) //{ // double u = (double)i/99.0; // vec3d uw = m_UWCrv.comp_pnt(u); // vec3d p = m_Surf->CompPnt( uw.x(), uw.y() ); // glVertex3dv( p.data() ); //} //glEnd(); }
void SceneTutorial21::Draw() { Scene::Draw(); int width = 640; int height = 480; glViewport(0, 0, width, height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0f, width, height, 0.0f, -1.0f, 1.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer glLoadIdentity(); // rendering fonts { glColor3d(1.0f, 0.5f, 1.0f); RenderBitmapString(GLUT_BITMAP_HELVETICA_18, 207, 24, "GRID CRAZY"); glColor3f(1.0f, 1.0f, 0.0f); RenderBitmapString(GLUT_BITMAP_HELVETICA_18, 20, 20, "Level:"); RenderBitmapString(GLUT_BITMAP_HELVETICA_18, 20, 40, "Stage:"); if( gameover ) { glColor3ub(rand()%255, rand()%255, rand()%255); RenderBitmapString(GLUT_BITMAP_HELVETICA_18, 472, 20, "GAME OVER"); RenderBitmapString(GLUT_BITMAP_HELVETICA_18, 456, 40, "PRESS SPACE"); } glColor3f(1.0f, 1.0f, 1.0f); } for (loop1=0; loop1<lives-1; loop1++) // Loop Through Lives Minus Current Life { glLoadIdentity(); // Reset The View glTranslatef(490+(loop1*40.0f),40.0f,0.0f); // Move To The Right Of Our Title Text glRotatef(-player.spin,0.0f,0.0f,1.0f); // Rotate Counter Clockwise glColor3f(0.0f,1.0f,0.0f); // Set Player Color To Light Green glBegin(GL_LINES); // Start Drawing Our Player Using Lines glVertex2d(-5,-5); // Top Left Of Player glVertex2d( 5, 5); // Bottom Right Of Player glVertex2d( 5,-5); // Top Right Of Player glVertex2d(-5, 5); // Bottom Left Of Player glEnd(); // Done Drawing The Player glRotatef(-player.spin*0.5f,0.0f,0.0f,1.0f); // Rotate Counter Clockwise glColor3f(0.0f,0.75f,0.0f); // Set Player Color To Dark Green glBegin(GL_LINES); // Start Drawing Our Player Using Lines glVertex2d(-7, 0); // Left Center Of Player glVertex2d( 7, 0); // Right Center Of Player glVertex2d( 0,-7); // Top Center Of Player glVertex2d( 0, 7); // Bottom Center Of Player glEnd(); // Done Drawing The Player } filled=true; // Set Filled To True Before Testing glLineWidth(2.0f); // Set Line Width For Cells To 2.0f glDisable(GL_LINE_SMOOTH); // Disable Antialiasing glLoadIdentity(); // Reset The Current Modelview Matrix for (loop1=0; loop1<11; loop1++) // Loop From Left To Right { for (loop2=0; loop2<11; loop2++) // Loop From Top To Bottom { glColor3f(0.0f,0.5f,1.0f); // Set Line Color To Blue if (hline[loop1][loop2]) // Has The Horizontal Line Been Traced { glColor3f(1.0f,1.0f,1.0f); // If So, Set Line Color To White } if (loop1<10) // Dont Draw To Far Right { if (!hline[loop1][loop2]) // If A Horizontal Line Isn't Filled { filled=false; // filled Becomes False } glBegin(GL_LINES); // Start Drawing Horizontal Cell Borders glVertex2d(20+(loop1*60),70+(loop2*40));// Left Side Of Horizontal Line glVertex2d(80+(loop1*60),70+(loop2*40));// Right Side Of Horizontal Line glEnd(); // Done Drawing Horizontal Cell Borders } glColor3f(0.0f,0.5f,1.0f); // Set Line Color To Blue if (vline[loop1][loop2]) // Has The Horizontal Line Been Traced { glColor3f(1.0f,1.0f,1.0f); // If So, Set Line Color To White } if (loop2<10) // Dont Draw To Far Down { if (!vline[loop1][loop2]) // If A Verticle Line Isn't Filled { filled=false; // filled Becomes False } glBegin(GL_LINES); // Start Drawing Verticle Cell Borders glVertex2d(20+(loop1*60),70+(loop2*40));// Left Side Of Horizontal Line glVertex2d(20+(loop1*60),110+(loop2*40));// Right Side Of Horizontal Line glEnd(); // Done Drawing Verticle Cell Borders } glEnable(GL_TEXTURE_2D); // Enable Texture Mapping glColor3f(1.0f,1.0f,1.0f); // Bright White Color glBindTexture(GL_TEXTURE_2D, img->GetTexture()); // Select The Tile Image if ((loop1<10) && (loop2<10)) // If In Bounds, Fill In Traced Boxes { // Are All Sides Of The Box Traced? if (hline[loop1][loop2] && hline[loop1][loop2+1] && vline[loop1][loop2] && vline[loop1+1][loop2]) { glBegin(GL_QUADS); // Draw A Textured Quad glTexCoord2f(float(loop1/10.0f)+0.1f,1.0f-(float(loop2/10.0f))); glVertex2d(20+(loop1*60)+59,(70+loop2*40+1)); // Top Right glTexCoord2f(float(loop1/10.0f),1.0f-(float(loop2/10.0f))); glVertex2d(20+(loop1*60)+1,(70+loop2*40+1)); // Top Left glTexCoord2f(float(loop1/10.0f),1.0f-(float(loop2/10.0f)+0.1f)); glVertex2d(20+(loop1*60)+1,(70+loop2*40)+39); // Bottom Left glTexCoord2f(float(loop1/10.0f)+0.1f,1.0f-(float(loop2/10.0f)+0.1f)); glVertex2d(20+(loop1*60)+59,(70+loop2*40)+39); // Bottom Right glEnd(); // Done Texturing The Box } } glDisable(GL_TEXTURE_2D); // Disable Texture Mapping } } glLineWidth(1.0f); // Set The Line Width To 1.0f if (anti) // Is Anti TRUE? { glEnable(GL_LINE_SMOOTH); // If So, Enable Antialiasing } if (hourglass.fx==1) // If fx=1 Draw The Hourglass { glLoadIdentity(); // Reset The Modelview Matrix glTranslatef(20.0f+(hourglass.x*60),70.0f+(hourglass.y*40),0.0f); // Move To The Fine Hourglass Position glRotatef(hourglass.spin,0.0f,0.0f,1.0f); // Rotate Clockwise glColor3ub(rand()%255,rand()%255,rand()%255); // Set Hourglass Color To Random Color glBegin(GL_LINES); // Start Drawing Our Hourglass Using Lines glVertex2d(-5,-5); // Top Left Of Hourglass glVertex2d( 5, 5); // Bottom Right Of Hourglass glVertex2d( 5,-5); // Top Right Of Hourglass glVertex2d(-5, 5); // Bottom Left Of Hourglass glVertex2d(-5, 5); // Bottom Left Of Hourglass glVertex2d( 5, 5); // Bottom Right Of Hourglass glVertex2d(-5,-5); // Top Left Of Hourglass glVertex2d( 5,-5); // Top Right Of Hourglass glEnd(); // Done Drawing The Hourglass } glLoadIdentity(); // Reset The Modelview Matrix glTranslatef(player.fx+20.0f,player.fy+70.0f,0.0f); // Move To The Fine Player Position glRotatef(player.spin,0.0f,0.0f,1.0f); // Rotate Clockwise glColor3f(0.0f,1.0f,0.0f); // Set Player Color To Light Green glBegin(GL_LINES); // Start Drawing Our Player Using Lines glVertex2d(-5,-5); // Top Left Of Player glVertex2d( 5, 5); // Bottom Right Of Player glVertex2d( 5,-5); // Top Right Of Player glVertex2d(-5, 5); // Bottom Left Of Player glEnd(); // Done Drawing The Player glRotatef(player.spin*0.5f,0.0f,0.0f,1.0f); // Rotate Clockwise glColor3f(0.0f,0.75f,0.0f); // Set Player Color To Dark Green glBegin(GL_LINES); // Start Drawing Our Player Using Lines glVertex2d(-7, 0); // Left Center Of Player glVertex2d( 7, 0); // Right Center Of Player glVertex2d( 0,-7); // Top Center Of Player glVertex2d( 0, 7); // Bottom Center Of Player glEnd(); // Done Drawing The Player for (loop1=0; loop1<(stage*level); loop1++) // Loop To Draw Enemies { glLoadIdentity(); // Reset The Modelview Matrix glTranslatef(enemy[loop1].fx+20.0f,enemy[loop1].fy+70.0f,0.0f); glColor3f(1.0f,0.5f,0.5f); // Make Enemy Body Pink glBegin(GL_LINES); // Start Drawing Enemy glVertex2d( 0,-7); // Top Point Of Body glVertex2d(-7, 0); // Left Point Of Body glVertex2d(-7, 0); // Left Point Of Body glVertex2d( 0, 7); // Bottom Point Of Body glVertex2d( 0, 7); // Bottom Point Of Body glVertex2d( 7, 0); // Right Point Of Body glVertex2d( 7, 0); // Right Point Of Body glVertex2d( 0,-7); // Top Point Of Body glEnd(); // Done Drawing Enemy Body glRotatef(enemy[loop1].spin,0.0f,0.0f,1.0f); // Rotate The Enemy Blade glColor3f(1.0f,0.0f,0.0f); // Make Enemy Blade Red glBegin(GL_LINES); // Start Drawing Enemy Blade glVertex2d(-7,-7); // Top Left Of Enemy glVertex2d( 7, 7); // Bottom Right Of Enemy glVertex2d(-7, 7); // Bottom Left Of Enemy glVertex2d( 7,-7); // Top Right Of Enemy glEnd(); // Done Drawing Enemy Blade } glutSwapBuffers(); }
void SimulatorMonoDisplay (void) { float fltEyeX, fltEyeY, fltEyeZ, fltCenterX, fltCenterY, fltCenterZ; GLsizei p_nViewport[4]; // Draws the main screen glViewport (0, 0, (GLsizei) g_nSimulatorWindowWidth, (GLsizei) g_nSimulatorWindowHeight); glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode (GL_PROJECTION); glLoadIdentity (); gluOrtho2D (0, (GLsizei) g_nSimulatorWindowWidth, 0, (GLsizei) g_nSimulatorWindowHeight); glMatrixMode (GL_MODELVIEW); glLoadIdentity (); glColor3ub (0, 0, 0); glBegin (GL_LINES); glVertex2i ((GLsizei) g_nSimulatorWindowWidth / 2, (GLsizei) g_nSimulatorWindowHeight / 2); glVertex2i ((GLsizei) g_nSimulatorWindowWidth / 2, (GLsizei) g_nSimulatorWindowHeight); glVertex2i (0, (GLsizei) g_nSimulatorWindowHeight / 2); glVertex2i ((GLsizei) g_nSimulatorWindowWidth, (GLsizei) g_nSimulatorWindowHeight / 2); glEnd(); // Draws the left view glViewport (0, (GLsizei) (g_nSimulatorWindowHeight + 1) / 2, (GLsizei) (g_nSimulatorWindowWidth + 1) / 2, (GLsizei) (g_nSimulatorWindowHeight + 1) / 2); glMatrixMode (GL_PROJECTION); glLoadIdentity (); gluPerspective (g_fltSimulatorFovy, (float) g_nSimulatorWindowWidth / (float) g_nSimulatorWindowHeight, g_fltSimulatorNear, g_fltSimulatorFar); glMatrixMode (GL_MODELVIEW); glLoadIdentity (); fltEyeX = g_pRobot->position.x + g_pRobot->leftEye->position.x * COS (g_pRobot->rotation.z * M_PI / 180.0) - g_pRobot->leftEye->position.y * SIN (g_pRobot->rotation.z * M_PI / 180.0); fltEyeY = g_pRobot->position.y + g_pRobot->leftEye->position.x * SIN (g_pRobot->rotation.z * M_PI / 180.0) + g_pRobot->leftEye->position.y * COS (g_pRobot->rotation.z * M_PI / 180.0); fltEyeZ = g_pRobot->position.z + g_pRobot->leftEye->position.z; fltCenterX = fltEyeX + COS (g_pRobot->rotation.z * M_PI / 180.0); fltCenterY = fltEyeY + SIN (g_pRobot->rotation.z * M_PI / 180.0); fltCenterZ = fltEyeZ; gluLookAt (fltEyeX, fltEyeY, fltEyeZ, fltCenterX, fltCenterY, fltCenterZ, .0f, .0f, 1.0f); g_pRobot->Draw (); g_pTerrain->Draw (); //g_pTarget->Draw (); if ((g_pLeftImage) != NULL && g_bForceUpdate) { glGetIntegerv (GL_VIEWPORT, p_nViewport); SimulatorGetImageFromScreen (g_pLeftImage, g_nLeftImageWidth, g_nLeftImageHeight, p_nViewport); } // Draws the right view glViewport ((GLsizei) (g_nSimulatorWindowWidth + 1) / 2, (GLsizei) (g_nSimulatorWindowHeight + 1) / 2, (GLsizei) (g_nSimulatorWindowWidth + 1) / 2, (GLsizei) (g_nSimulatorWindowHeight + 1) / 2); glMatrixMode (GL_PROJECTION); glLoadIdentity (); gluPerspective (g_fltSimulatorFovy, (float) g_nSimulatorWindowWidth / (float) g_nSimulatorWindowHeight, g_fltSimulatorNear, g_fltSimulatorFar); glMatrixMode (GL_MODELVIEW); glLoadIdentity (); fltEyeX = g_pRobot->position.x + g_pRobot->rightEye->position.x * COS (g_pRobot->rotation.z * M_PI / 180.0) - g_pRobot->rightEye->position.y * SIN (g_pRobot->rotation.z * M_PI / 180.0); fltEyeY = g_pRobot->position.y + g_pRobot->rightEye->position.x * SIN (g_pRobot->rotation.z * M_PI / 180.0) + g_pRobot->rightEye->position.y * COS (g_pRobot->rotation.z * M_PI / 180.0); fltEyeZ = g_pRobot->position.z + g_pRobot->rightEye->position.z; fltCenterX = fltEyeX + COS (g_pRobot->rotation.z * M_PI / 180.0); fltCenterY = fltEyeY + SIN (g_pRobot->rotation.z * M_PI / 180.0); fltCenterZ = fltEyeZ; gluLookAt (fltEyeX,fltEyeY, fltEyeZ, fltCenterX, fltCenterY, fltCenterZ, .0f, .0f, 1.0f); g_pRobot->Draw (); g_pTerrain->Draw (); //g_pTarget->Draw (); if ((g_pRightImage != NULL) && g_bForceUpdate) { glGetIntegerv (GL_VIEWPORT, p_nViewport); SimulatorGetImageFromScreen (g_pRightImage, g_nRightImageWidth, g_nRightImageHeight, p_nViewport); } // Draws the external view glViewport (0, 0, (GLsizei) g_nSimulatorWindowWidth, (GLsizei) (g_nSimulatorWindowHeight + 1) / 2); glMatrixMode (GL_PROJECTION); glLoadIdentity (); gluPerspective (FOVY, 2.0f * (float) g_nSimulatorWindowWidth / (float) g_nSimulatorWindowHeight, NEAR, FAR); glMatrixMode (GL_MODELVIEW); glLoadIdentity (); fltCenterX = g_pRobot->position.x; fltCenterY = g_pRobot->position.y; fltCenterZ = g_pRobot->position.z; fltEyeX = fltCenterX + g_pExternalCamera->position.x; fltEyeY = fltCenterY + g_pExternalCamera->position.y; fltEyeZ = fltCenterZ + g_pExternalCamera->position.z; gluLookAt (fltEyeX, fltEyeY, fltEyeZ, fltCenterX, fltCenterY, fltCenterZ, .0f, .0f, 1.0f); g_pRobot->Draw (); g_pTerrain->Draw (); //g_pTarget->Draw (); glutSwapBuffers(); return; }
void Plot::DrawAxis( float offx, float offy, float min, float max, float xdiv, float ydiv, float step_x, float step_y ) { // Calcolo la proporzione del grafico float eps = (float) this->w() / 300.0; // Calcolo la lunghezza degli assi float x_axis = (float) this->max_data * xdiv; // Imposto il colore glColor3ub( 255u, 255u, 255u ); // Imposto la dimensione della linea glLineWidth( (GLfloat) eps ); // Disegno gli assi del piano cartesiano glBegin( GL_LINES ); // Controllo se l'asse delle ascisse è visibile if ( min <= 0 && max >= 0 ) { // Asse delle ascisse glVertex2f( (GLfloat) offx, (GLfloat) offy ); glVertex2f( (GLfloat) offx + (GLfloat) x_axis, (GLfloat) offy ); glVertex2f( (GLfloat) offx + (GLfloat) x_axis, (GLfloat) offy - 4 ); glVertex2f( (GLfloat) offx + (GLfloat) x_axis, (GLfloat) offy + 3 ); } // Asse delle ordinate glVertex2f( (GLfloat) offx, (GLfloat) offy + max * ydiv ); glVertex2f( (GLfloat) offx, (GLfloat) offy + min * ydiv ); glEnd(); // Imposto il carattere del testo gl_font( FL_HELVETICA, (int) ( 8.0 * eps ) ); // Controllo se l'asse delle ascisse è visibile if ( min <= 0 && max >= 0 ) { // Disegno la nomenclatura dell'asse delle ascisse gl_draw( "x", offx + x_axis - (float) gl_width( "x" ) + 8.0 * (GLfloat) eps, offy ); } // Disegno la nomenclatura dell'asse delle ordinate gl_draw( "y", offx + 6.0 * (GLfloat) eps, offy + max * ydiv + (float) gl_width( "y" ) ); // Imposto il colore glColor3ub( 255u, 255u, 255u ); // Imposto la dimensione della linea glLineWidth( (GLfloat) eps ); // Imposto il carattere del testo gl_font( FL_HELVETICA, (int) ( 8.0 * eps ) ); // Buffer del testo char buffer[20]; // Iteratore float i; // Controllo se si vuole disegnare il righello nell'asse delle ascisse if ( this->x_ruler_step ) { // Flag di controllo bool alternate = false; // Disegno le tacche dell'asse delle ascisse for ( i = 0; i <= (float) this->data_set[0].size; i += step_x ) { // Calcolo la posizione verticale float xpos = offx + i * xdiv; // Disegno le tacche dell'asse glBegin( GL_LINES ); glVertex2f( (GLfloat) xpos, (GLfloat) offy ); glVertex2f( (GLfloat) xpos, (GLfloat) offy - 5 * eps ); glEnd(); // Controllo se si stanno usando numeri molto piccoli if ( step_x < 1.0 ) snprintf( buffer, 20, "%.2f", i * this->x_ruler_step ); else snprintf( buffer, 20, "%.1f", i * this->x_ruler_step ); // Disegno il valore della tacca nell'asse if ( (float) this->data_set[0].size / step_x < 5.0 || !alternate ) gl_draw( buffer, (float) xpos - (float) gl_width( buffer ) / 2.0f, offy - 17.0 * eps ); // Visualizzo le etichette a sbalzi alternate = ( alternate ) ? false : true; } } // Disegno le tacche dell'asse delle ordinate for ( i = min; i <= max; i += step_y ) { // Calcolo la posizione verticale float ypos = offy + i * ydiv; // Disegno le tacche dell'asse glBegin( GL_LINES ); glVertex2f( (GLfloat) offx, (GLfloat) ypos ); glVertex2f( (GLfloat) offx + 5 * eps, (GLfloat) ypos ); glEnd(); // Controllo se si stanno usando numeri molto piccoli if ( step_y < 1.0 ) snprintf( buffer, 20, "%.2f", i ); else snprintf( buffer, 20, "%.1f", i ); // Disegno il valore della tacca nell'asse gl_draw( buffer, (float) offx - (float) gl_width( buffer ) - 10, ypos - 3 ); } }
void desenhaTabuleiro(){ int i,j; char comutador=0; glBegin(GL_QUADS); for(i=0;i<LADO_TABULEIRO;++i){ for(j=0;j<LADO_TABULEIRO;j++){ unsigned char green=0, red=0; if(tabuleiro[i][j] & HOVER){ green = 32; } if(tabuleiro[i][j] & ATIVO){ red = 48; } if(comutador){ glColor3ub(63+red,63+green,63); } else { glColor3ub(127+red,127+green,63); } comutador=!comutador; glVertex2i(LADO_CASA/2 + (j+1)*LADO_CASA, LADO_CASA/2 + i*LADO_CASA); glVertex2i(LADO_CASA/2 + j*LADO_CASA, LADO_CASA/2 + i*LADO_CASA); glVertex2i(LADO_CASA/2 + j*LADO_CASA, LADO_CASA/2 + (i+1)*LADO_CASA); glVertex2i(LADO_CASA/2 + (j+1)*LADO_CASA, LADO_CASA/2 + (i+1)*LADO_CASA); } comutador=!comutador; } glEnd(); for(i=0;i<LADO_TABULEIRO;++i){ for(j=0;j<LADO_TABULEIRO;j++){ if(tabuleiro[i][j] & VAZIO){ continue; }else if(tabuleiro[i][j] & PRETO){ if(tabuleiro[i][j] & TRANSICAO){ int cinza = COR_PRETO + (COR_BRANCO-COR_PRETO)*(tabuleiro[i][j] & TRANSICAO)/(TRANSICAO+1); glColor3ub(cinza,cinza,cinza); tabuleiro[i][j] -= TRANSITAR; } else { glColor3ub(COR_PRETO,COR_PRETO,COR_PRETO); } } else if(tabuleiro[i][j] & BRANCO){ if(tabuleiro[i][j] & TRANSICAO){ int cinza = COR_BRANCO - (COR_BRANCO-COR_PRETO)*(tabuleiro[i][j] & TRANSICAO)/(TRANSICAO+1); glColor3ub(cinza,cinza,cinza); tabuleiro[i][j] -= TRANSITAR; } else { glColor3ub(COR_BRANCO,COR_BRANCO,COR_BRANCO); } } int a; float vertex_angle; float x = + (j+1)*LADO_CASA; float y = + (i+1)*LADO_CASA; const float R = LADO_CASA*3/8; const int NUM_VERTEX=20; glBegin(GL_POLYGON); for(a=0;a<NUM_VERTEX;a++){ vertex_angle = 2*a*M_PI/NUM_VERTEX; glVertex2d(x+R*cos(vertex_angle), y+R*sin(vertex_angle)); } glEnd(); } } }
void Plot::DrawData( size_t index, float offx, float offy, float xdiv, float ydiv ) { // Iteratore size_t i; // Calcolo la proporzione del grafico float eps = (float) this->w() / 300.0; // Imposto il colore glColor3ub( this->data_set[index].color.red, this->data_set[index].color.green, this->data_set[index].color.blue ); // Imposto la dimensione della linea glLineWidth( (GLfloat) eps * 1.5 ); // Imposto la sfumatura delle linee glEnable( GL_LINE_SMOOTH ); // Disegno i dati del grafico glBegin( GL_LINE_STRIP ); for ( i = 0; i < this->data_set[index].size; i++ ) { glVertex2f( (GLfloat) offx + (GLfloat) eps * 1.5 + (GLfloat) i * xdiv, (GLfloat) offy + (GLfloat) ( this->data_set[index].data[i] * ydiv ) ); } glEnd(); // Disabilito la sfumatura delle linee glDisable( GL_LINE_SMOOTH ); // Controllo se sono stati abilitati i punti if ( this->data_set[index].points ) { // Imposto la dimensione della linea glLineWidth( (GLfloat) eps ); // Imposto la dimensione dei punti glPointSize( 3.5 * (GLfloat) eps ); // Imposto la sfumatura dei punti glEnable( GL_POINT_SMOOTH ); // Evidenzio i punti conosciuti glBegin( GL_POINTS ); for ( i = 0; i < this->data_set[index].size; i++ ) { glVertex2f( (GLfloat) offx + (GLfloat) eps * 1.5 + (GLfloat) i * xdiv, (GLfloat) offy + (GLfloat) ( this->data_set[index].data[i] * ydiv ) ); } glEnd(); // Disabilito la sfumatura dei punti glDisable( GL_POINT_SMOOTH ); } }
static void gl_shaded_color(unsigned char *col, int shade) { glColor3ub(col[0] - shade > 0 ? col[0] - shade : 0, col[1] - shade > 0 ? col[1] - shade : 0, col[2] - shade > 0 ? col[2] - shade : 0); }
void command_display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if (swapped) { translation[0].y = 80; translation[1].y = 80; translation[2].y = 80; rotation[0].y = 40; rotation[1].y = 40; rotation[2].y = 40; rotation[3].y = 40; } else { translation[0].y = 40; translation[1].y = 40; translation[2].y = 40; rotation[0].y = 80; rotation[1].y = 80; rotation[2].y = 80; rotation[3].y = 80; } glColor3ub(255, 255, 255); setfont("helvetica", 18); drawstr(30, rotation[0].y, "glRotatef("); drawstr(170, rotation[0].y, ","); drawstr(230, rotation[0].y, ","); drawstr(290, rotation[0].y, ","); drawstr(350, rotation[0].y, ");"); drawstr(10, translation[0].y, "glTranslatef("); drawstr(170, translation[0].y, ","); drawstr(230, translation[0].y, ","); drawstr(290, translation[0].y, ");"); drawstr(38, 120, "glScalef("); drawstr(170, 120, ","); drawstr(230, 120, ","); drawstr(290, 120, ");"); drawstr(41, 160, "glBegin( . . . );"); drawstr(41, 200, " . . ."); cell_draw(&translation[0]); cell_draw(&translation[1]); cell_draw(&translation[2]); cell_draw(&rotation[0]); cell_draw(&rotation[1]); cell_draw(&rotation[2]); cell_draw(&rotation[3]); cell_draw(&scale[0]); cell_draw(&scale[1]); cell_draw(&scale[2]); if (!selection) { glColor3ub(255, 255, 0); drawstr(10, 240, "Click on the arguments and move the mouse to modify values."); } glutSwapBuffers(); }
void ui_draw_but_CURVE(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti *rect) { CurveMapping *cumap; CurveMap *cuma; CurveMapPoint *cmp; float fx, fy, fac[2], zoomx, zoomy, offsx, offsy; GLint scissor[4]; rcti scissor_new; int a; if (but->editcumap) { cumap = but->editcumap; } else { cumap = (CurveMapping *)but->poin; } cuma = &cumap->cm[cumap->cur]; /* need scissor test, curve can draw outside of boundary */ glGetIntegerv(GL_VIEWPORT, scissor); scissor_new.xmin = ar->winrct.xmin + rect->xmin; scissor_new.ymin = ar->winrct.ymin + rect->ymin; scissor_new.xmax = ar->winrct.xmin + rect->xmax; scissor_new.ymax = ar->winrct.ymin + rect->ymax; BLI_rcti_isect(&scissor_new, &ar->winrct, &scissor_new); glScissor(scissor_new.xmin, scissor_new.ymin, BLI_rcti_size_x(&scissor_new), BLI_rcti_size_y(&scissor_new)); /* calculate offset and zoom */ zoomx = (BLI_rcti_size_x(rect) - 2.0f * but->aspect) / BLI_rctf_size_x(&cumap->curr); zoomy = (BLI_rcti_size_y(rect) - 2.0f * but->aspect) / BLI_rctf_size_y(&cumap->curr); offsx = cumap->curr.xmin - but->aspect / zoomx; offsy = cumap->curr.ymin - but->aspect / zoomy; /* backdrop */ if (but->a1 == UI_GRAD_H) { /* magic trigger for curve backgrounds */ rcti grid; float col[3] = {0.0f, 0.0f, 0.0f}; /* dummy arg */ grid.xmin = rect->xmin + zoomx * (-offsx); grid.xmax = rect->xmax + zoomx * (-offsx); grid.ymin = rect->ymin + zoomy * (-offsy); grid.ymax = rect->ymax + zoomy * (-offsy); ui_draw_gradient(&grid, col, UI_GRAD_H, 1.0f); /* grid, hsv uses different grid */ glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4ub(0, 0, 0, 48); ui_draw_but_curve_grid(rect, zoomx, zoomy, offsx, offsy, 0.1666666f); glDisable(GL_BLEND); } else { if (cumap->flag & CUMA_DO_CLIP) { gl_shaded_color((unsigned char *)wcol->inner, -20); glRectf(rect->xmin, rect->ymin, rect->xmax, rect->ymax); glColor3ubv((unsigned char *)wcol->inner); glRectf(rect->xmin + zoomx * (cumap->clipr.xmin - offsx), rect->ymin + zoomy * (cumap->clipr.ymin - offsy), rect->xmin + zoomx * (cumap->clipr.xmax - offsx), rect->ymin + zoomy * (cumap->clipr.ymax - offsy)); } else { glColor3ubv((unsigned char *)wcol->inner); glRectf(rect->xmin, rect->ymin, rect->xmax, rect->ymax); } /* grid, every 0.25 step */ gl_shaded_color((unsigned char *)wcol->inner, -16); ui_draw_but_curve_grid(rect, zoomx, zoomy, offsx, offsy, 0.25f); /* grid, every 1.0 step */ gl_shaded_color((unsigned char *)wcol->inner, -24); ui_draw_but_curve_grid(rect, zoomx, zoomy, offsx, offsy, 1.0f); /* axes */ gl_shaded_color((unsigned char *)wcol->inner, -50); glBegin(GL_LINES); glVertex2f(rect->xmin, rect->ymin + zoomy * (-offsy)); glVertex2f(rect->xmax, rect->ymin + zoomy * (-offsy)); glVertex2f(rect->xmin + zoomx * (-offsx), rect->ymin); glVertex2f(rect->xmin + zoomx * (-offsx), rect->ymax); glEnd(); } /* cfra option */ /* XXX 2.48 */ #if 0 if (cumap->flag & CUMA_DRAW_CFRA) { glColor3ub(0x60, 0xc0, 0x40); glBegin(GL_LINES); glVertex2f(rect->xmin + zoomx * (cumap->sample[0] - offsx), rect->ymin); glVertex2f(rect->xmin + zoomx * (cumap->sample[0] - offsx), rect->ymax); glEnd(); } #endif /* sample option */ if (cumap->flag & CUMA_DRAW_SAMPLE) { if (but->a1 == UI_GRAD_H) { float tsample[3]; float hsv[3]; linearrgb_to_srgb_v3_v3(tsample, cumap->sample); rgb_to_hsv_v(tsample, hsv); glColor3ub(240, 240, 240); glBegin(GL_LINES); glVertex2f(rect->xmin + zoomx * (hsv[0] - offsx), rect->ymin); glVertex2f(rect->xmin + zoomx * (hsv[0] - offsx), rect->ymax); glEnd(); } else if (cumap->cur == 3) { float lum = rgb_to_bw(cumap->sample); glColor3ub(240, 240, 240); glBegin(GL_LINES); glVertex2f(rect->xmin + zoomx * (lum - offsx), rect->ymin); glVertex2f(rect->xmin + zoomx * (lum - offsx), rect->ymax); glEnd(); } else { if (cumap->cur == 0) glColor3ub(240, 100, 100); else if (cumap->cur == 1) glColor3ub(100, 240, 100); else glColor3ub(100, 100, 240); glBegin(GL_LINES); glVertex2f(rect->xmin + zoomx * (cumap->sample[cumap->cur] - offsx), rect->ymin); glVertex2f(rect->xmin + zoomx * (cumap->sample[cumap->cur] - offsx), rect->ymax); glEnd(); } } /* the curve */ glColor3ubv((unsigned char *)wcol->item); glEnable(GL_LINE_SMOOTH); glEnable(GL_BLEND); glBegin(GL_LINE_STRIP); if (cuma->table == NULL) curvemapping_changed(cumap, FALSE); cmp = cuma->table; /* first point */ if ((cuma->flag & CUMA_EXTEND_EXTRAPOLATE) == 0) { glVertex2f(rect->xmin, rect->ymin + zoomy * (cmp[0].y - offsy)); } else { fx = rect->xmin + zoomx * (cmp[0].x - offsx + cuma->ext_in[0]); fy = rect->ymin + zoomy * (cmp[0].y - offsy + cuma->ext_in[1]); glVertex2f(fx, fy); } for (a = 0; a <= CM_TABLE; a++) { fx = rect->xmin + zoomx * (cmp[a].x - offsx); fy = rect->ymin + zoomy * (cmp[a].y - offsy); glVertex2f(fx, fy); } /* last point */ if ((cuma->flag & CUMA_EXTEND_EXTRAPOLATE) == 0) { glVertex2f(rect->xmax, rect->ymin + zoomy * (cmp[CM_TABLE].y - offsy)); } else { fx = rect->xmin + zoomx * (cmp[CM_TABLE].x - offsx - cuma->ext_out[0]); fy = rect->ymin + zoomy * (cmp[CM_TABLE].y - offsy - cuma->ext_out[1]); glVertex2f(fx, fy); } glEnd(); glDisable(GL_LINE_SMOOTH); glDisable(GL_BLEND); /* the points, use aspect to make them visible on edges */ cmp = cuma->curve; glPointSize(3.0f); bglBegin(GL_POINTS); for (a = 0; a < cuma->totpoint; a++) { if (cmp[a].flag & CUMA_SELECT) UI_ThemeColor(TH_TEXT_HI); else UI_ThemeColor(TH_TEXT); fac[0] = rect->xmin + zoomx * (cmp[a].x - offsx); fac[1] = rect->ymin + zoomy * (cmp[a].y - offsy); bglVertex2fv(fac); } bglEnd(); glPointSize(1.0f); /* restore scissortest */ glScissor(scissor[0], scissor[1], scissor[2], scissor[3]); /* outline */ glColor3ubv((unsigned char *)wcol->outline); fdrawbox(rect->xmin, rect->ymin, rect->xmax, rect->ymax); }
void drawAtom(float cx, float cy, float cz, GLubyte prop[]) { float r=prop[0]; glColor3ub(prop[1],prop[2],prop[3]); drawSphere(cx, cy, cz, r); }
void ui_draw_but_COLORBAND(uiBut *but, uiWidgetColors *UNUSED(wcol), rcti *rect) { ColorBand *coba; CBData *cbd; float x1, y1, sizex, sizey; float v3[2], v1[2], v2[2], v1a[2], v2a[2]; int a; float pos, colf[4] = {0, 0, 0, 0}; /* initialize in case the colorband isn't valid */ struct ColorManagedDisplay *display = NULL; coba = (ColorBand *)(but->editcoba ? but->editcoba : but->poin); if (coba == NULL) return; if (but->block->color_profile) display = ui_block_display_get(but->block); x1 = rect->xmin; y1 = rect->ymin; sizex = rect->xmax - x1; sizey = rect->ymax - y1; /* first background, to show tranparency */ glColor4ub(UI_TRANSP_DARK, UI_TRANSP_DARK, UI_TRANSP_DARK, 255); glRectf(x1, y1, x1 + sizex, y1 + sizey); glEnable(GL_POLYGON_STIPPLE); glColor4ub(UI_TRANSP_LIGHT, UI_TRANSP_LIGHT, UI_TRANSP_LIGHT, 255); glPolygonStipple(checker_stipple_sml); glRectf(x1, y1, x1 + sizex, y1 + sizey); glDisable(GL_POLYGON_STIPPLE); glShadeModel(GL_FLAT); glEnable(GL_BLEND); cbd = coba->data; v1[0] = v2[0] = x1; v1[1] = y1; v2[1] = y1 + sizey; glBegin(GL_QUAD_STRIP); glColor4fv(&cbd->r); glVertex2fv(v1); glVertex2fv(v2); for (a = 1; a <= sizex; a++) { pos = ((float)a) / (sizex - 1); do_colorband(coba, pos, colf); if (display) IMB_colormanagement_scene_linear_to_display_v3(colf, display); v1[0] = v2[0] = x1 + a; glColor4fv(colf); glVertex2fv(v1); glVertex2fv(v2); } glEnd(); glShadeModel(GL_FLAT); glDisable(GL_BLEND); /* outline */ glColor4f(0.0, 0.0, 0.0, 1.0); fdrawbox(x1, y1, x1 + sizex, y1 + sizey); /* help lines */ v1[0] = v2[0] = v3[0] = x1; v1[1] = y1; v1a[1] = y1 + 0.25f * sizey; v2[1] = y1 + 0.5f * sizey; v2a[1] = y1 + 0.75f * sizey; v3[1] = y1 + sizey; cbd = coba->data; glBegin(GL_LINES); for (a = 0; a < coba->tot; a++, cbd++) { v1[0] = v2[0] = v3[0] = v1a[0] = v2a[0] = x1 + cbd->pos * sizex; if (a == coba->cur) { glColor3ub(0, 0, 0); glVertex2fv(v1); glVertex2fv(v3); glEnd(); setlinestyle(2); glBegin(GL_LINES); glColor3ub(255, 255, 255); glVertex2fv(v1); glVertex2fv(v3); glEnd(); setlinestyle(0); glBegin(GL_LINES); #if 0 glColor3ub(0, 0, 0); glVertex2fv(v1); glVertex2fv(v1a); glColor3ub(255, 255, 255); glVertex2fv(v1a); glVertex2fv(v2); glColor3ub(0, 0, 0); glVertex2fv(v2); glVertex2fv(v2a); glColor3ub(255, 255, 255); glVertex2fv(v2a); glVertex2fv(v3); #endif } else { glColor3ub(0, 0, 0); glVertex2fv(v1); glVertex2fv(v2); glColor3ub(255, 255, 255); glVertex2fv(v2); glVertex2fv(v3); } } glEnd(); }
void adenineThymine() { float hex1[6][2], hex2[6][2]; float rx=512; //radius and colors declarations GLubyte red[] = {15, 231, 76, 60}; //oxygen GLubyte green[] = {20, 39, 174, 96}; //carbon GLubyte blue[] = {20, 52, 152, 219}; //nitrogen GLubyte yellow[] = {10, 241, 196, 15}; //hydrogen getHexagonPoints(hex1, -128, 350, 75); getHexagonPoints(hex2, 128, 350, 75); glPushMatrix(); glTranslatef(rx, 0, 0); glRotatef(theta, 0.0, 1.0, 0.0); //hexagon 1 drawAtom(hex1[0][0], hex1[0][1], 0, green); drawAtom(hex1[1][0], hex1[1][1], 0, blue); drawAtom(hex1[2][0], hex1[2][1], 0, green); drawAtom(hex1[3][0], hex1[3][1], 0, green); drawAtom(hex1[4][0], hex1[4][1], 0, green); drawAtom(hex1[5][0], hex1[5][1], 0, blue); drawBondLine(hex1[0][0],hex1[0][1],0, hex1[1][0],hex1[1][1],0); drawBondLine(hex1[1][0],hex1[1][1],0, hex1[2][0],hex1[2][1],0); drawBondLine(hex1[2][0],hex1[2][1],0, hex1[3][0],hex1[3][1],0); drawBondLine(hex1[3][0],hex1[3][1],0, hex1[4][0],hex1[4][1],0); drawBondLine(hex1[4][0],hex1[4][1],0, hex1[5][0],hex1[5][1],0); drawBondLine(hex1[5][0],hex1[5][1],0, hex1[0][0],hex1[0][1],0); drawAtom(hex1[0][0], hex1[0][1]-50, 0, red); drawBondLine(hex1[0][0],hex1[0][1],0, hex1[0][0],hex1[0][1]-50,0); drawAtom(hex1[1][0]+15, hex1[1][1]-15, -50, yellow); drawBondLine(hex1[1][0],hex1[1][1],0, hex1[1][0]+15,hex1[1][1]-15,-50); drawAtom(hex1[2][0]+40, hex1[2][1]+40, 0, red); drawBondLine(hex1[2][0],hex1[2][1],0, hex1[2][0]+40,hex1[2][1]+40,0); drawAtom(hex1[3][0], hex1[3][1]+50, 0, green); drawBondLine(hex1[3][0],hex1[3][1],0, hex1[3][0],hex1[3][1]+50,0); drawAtom(hex1[3][0], hex1[3][1]+75, 50, yellow); drawBondLine(hex1[3][0],hex1[3][1]+50,0, hex1[3][0],hex1[3][1]+75,50); drawAtom(hex1[3][0]+35, hex1[3][1]+75, -35, yellow); drawBondLine(hex1[3][0],hex1[3][1]+50,0, hex1[3][0]+35,hex1[3][1]+75,-35); drawAtom(hex1[3][0]-35, hex1[3][1]+75, -35, yellow); drawBondLine(hex1[3][0],hex1[3][1]+50,0, hex1[3][0]-35,hex1[3][1]+75,-35); drawAtom(hex1[4][0]-15,hex1[4][1]+15, 50, yellow); drawBondLine(hex1[4][0],hex1[4][1],0, hex1[4][0]-15,hex1[4][1]+15,50); //hexagon 2 drawAtom(hex2[0][0], hex2[0][1], 0, blue); drawAtom(hex2[1][0], hex2[1][1], 0, green); drawAtom(hex2[2][0], hex2[2][1], 0, green); drawAtom(hex2[3][0], hex2[3][1], 0, green); drawAtom(hex2[4][0], hex2[4][1], 0, blue); drawAtom(hex2[5][0], hex2[5][1], 0, green); drawBondLine(hex2[0][0],hex2[0][1],0, hex2[1][0],hex2[1][1],0); drawBondLine(hex2[1][0],hex2[1][1],0, hex2[2][0],hex2[2][1],0); drawBondLine(hex2[2][0],hex2[2][1],0, hex2[3][0],hex2[3][1],0); drawBondLine(hex2[3][0],hex2[3][1],0, hex2[4][0],hex2[4][1],0); drawBondLine(hex2[4][0],hex2[4][1],0, hex2[5][0],hex2[5][1],0); drawBondLine(hex2[5][0],hex2[5][1],0, hex2[0][0],hex2[0][1],0); drawAtom(hex2[1][0]+50, hex2[0][1]+25, 50, blue); drawBondLine(hex2[1][0],hex2[1][1],0, hex2[1][0]+50,hex2[0][1]+25,50); drawAtom(hex2[2][0]+50, hex2[3][1]-25, 50, blue); drawBondLine(hex2[2][0],hex2[2][1],0, hex2[2][0]+50,hex2[3][1]-25,50); drawAtom(hex2[2][0]+100,hex2[2][1]-37.5,75, green); drawBondLine(hex2[1][0]+50, hex2[0][1]+25, 50, hex2[2][0]+100,hex2[2][1]-37.5,75); drawBondLine(hex2[2][0]+50, hex2[3][1]-25, 50, hex2[2][0]+100,hex2[2][1]-37.5,75); drawAtom(hex2[2][0]+142.5,hex2[2][1]-37.5,75, yellow); drawBondLine(hex2[2][0]+100,hex2[2][1]-37.5,75, hex2[2][0]+142.5,hex2[2][1]-37.5,75); drawAtom(hex2[3][0], hex2[3][1]+50, 0, blue); drawBondLine(hex2[3][0],hex2[3][1],0, hex2[3][0],hex2[3][1]+50,0); drawAtom(hex2[3][0], hex2[3][1]+75, 50, yellow); drawBondLine(hex2[3][0], hex2[3][1]+50,0, hex2[3][0],hex2[3][1]+75,50); drawAtom(hex2[3][0], hex2[3][1]+75, -50, yellow); drawBondLine(hex2[3][0],hex2[3][1]+50,0, hex2[3][0],hex2[3][1]+75,-50); drawAtom(hex2[5][0]-30,hex2[5][1]-30, 0, yellow); drawBondLine(hex2[5][0],hex2[5][1],0, hex2[5][0]-30,hex2[5][1]-30,0); //H-bonds glLineWidth(1.5); glBegin(GL_LINES); glVertex3f(hex1[2][0]+40,hex1[2][1]+40,0); glVertex3f(hex2[3][0], hex2[3][1]+75, 50); glVertex3f(hex1[1][0]+15, hex1[1][1]-15, -50); glVertex3f(hex2[4][0],hex2[4][1],0); glEnd(); glTranslatef(-rx, 0, 0); glPopMatrix(); theta+=0.25; drawLegend(); glColor3ub(52, 73, 94); output(300, 190, "Adenine is a nucleobase which plays a major role in", fonts[2]); output(300, 170, "cellular respiration and is rich in adenosine.", fonts[2]); output(300, 130, "Thymine is a pyrimidine nucleobase and it", fonts[2]); output(300, 110, "assists in stabalizing the nucleic acid structures.", fonts[2]); }
void Viewport::drawXYZArrows() { if( !_showArrows ) { return; } float aspectRatioH = _vHeight > _vWidth ? _vHeight / ( float )_vWidth : 1.0f; float aspectRatioW = _vWidth > _vHeight ? _vWidth / ( float )_vHeight : 1.0f; // Matrix for moving arrows to lower left corner of the screen. glm::mat4 arrowTMat = glm::translate( glm::vec3( ARROW_XPOS * aspectRatioW, ARROW_YPOS * aspectRatioH, 0.f ) ); float borderH = 1.0f * aspectRatioH; float borderW = 1.0f * aspectRatioW; glm::mat4 projectionMatrix = glm::ortho( -borderW, borderW, -borderH, borderH, -2500.0f, 2500.0f ); glm::mat4 modelviewMatrix = _camera->getModelViewMatrix(); // Set Translation to 0. We only care about rotation. modelviewMatrix[3][0] = 0.0f; modelviewMatrix[3][1] = 0.0f; modelviewMatrix[3][2] = 0.0f; // Apply Projection and Modelview matrix. glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glMultMatrixf( &projectionMatrix[0][0] ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); // Move arrows to position after rotation. glMultMatrixf( &arrowTMat[0][0] ); glMultMatrixf( &modelviewMatrix[0][0] ); // Draw Axis. glLineWidth( 1.5f * _screenSizeDiffRatio ); glClear( GL_DEPTH_BUFFER_BIT ); glBegin( GL_LINES ); glColor3ub( 255, 0, 0 ); glVertex3d( 0.0, 0.0, 0.0 ); glVertex3d( ARROW_LENGTH, 0.0, 0.0 ); glColor3ub( 0, 255, 0 ); glVertex3d( 0.0, 0.0, 0.0 ); glVertex3d( 0.0, ARROW_LENGTH, 0.0 ); glColor3ub( 0, 0, 255 ); glVertex3d( 0.0, 0.0, 0.0 ); glVertex3d( 0.0, 0.0, ARROW_LENGTH ); glEnd(); glEnable( GL_POINT_SMOOTH ); glPointSize( 3.0 ); glBegin( GL_POINTS ); glColor3ub( 0, 0, 0 ); glVertex3d( 0.0, 0.0, 0.0 ); glEnd(); glDisable( GL_POINT_SMOOTH ); glDisable( GL_LINE_SMOOTH ); glDepthMask( GL_FALSE ); glDisable( GL_DEPTH_TEST ); // Draw label. // Calculate translation for X, Y and Z. glm::mat4 xt = glm::translate( glm::vec3( modelviewMatrix * glm::vec4( ARROW_LENGTH + ARROW_TEXT_OFFSET, 0.f, 0.f, 1.f ) ) ); glm::mat4 yt = glm::translate( glm::vec3( modelviewMatrix * glm::vec4( 0.f, ARROW_LENGTH + ARROW_TEXT_OFFSET, 0.f, 1.f ) ) ); glm::mat4 zt = glm::translate( glm::vec3( modelviewMatrix * glm::vec4( 0.f, 0.f, ARROW_LENGTH + ARROW_TEXT_OFFSET, 1.f ) ) ); glColor3ub( 0, 0, 0 ); // Active Texture Image Unit 0. glActiveTexture( GL_TEXTURE0 ); glLoadIdentity(); glMultMatrixf( &arrowTMat[0][0] ); // X glPushMatrix(); glMultMatrixf( &xt[0][0] ); _textMgr->drawText( _textMgr->loadFont(), 2.0f, "X", 0.f, 0.f, 0.f, 0.f ); glPopMatrix(); // Y glPushMatrix(); glMultMatrixf( &yt[0][0] ); _textMgr->drawText( _textMgr->loadFont(), 2.0f, "Y", 0.f, 0.f, 0.f, 0.f ); glPopMatrix(); // Z glPushMatrix(); glMultMatrixf( &zt[0][0] ); _textMgr->drawText( _textMgr->loadFont(), 2.0f, "Z", 0.f, 0.f, 0.f, 0.f ); glPopMatrix(); }
void GlutDevice::SetPixel(int iX,int iY,int iR,int iG,int iB) { glColor3ub(iR,iG,iB); glVertex2i(iX,iY); }
static void printMode() { int len, thresh, line, mode, xsize, ysize; AR_LABELING_THRESH_MODE threshMode; ARdouble tempF; char text[256], *text_p; glColor3ub(255, 255, 255); line = 1; // Image size and processing mode. arVideoGetSize(&xsize, &ysize); arGetImageProcMode(gARHandle, &mode); if (mode == AR_IMAGE_PROC_FRAME_IMAGE) text_p = "full frame"; else text_p = "even field only"; snprintf(text, sizeof(text), "Processing %dx%d video frames %s", xsize, ysize, text_p); print(text, 2.0f, (line - 1) * 12.0f + 2.0f, 0, 1); line++; // Threshold mode, and threshold, if applicable. arGetLabelingThreshMode(gARHandle, &threshMode); switch (threshMode) { case AR_LABELING_THRESH_MODE_MANUAL: text_p = "MANUAL"; break; case AR_LABELING_THRESH_MODE_AUTO_MEDIAN: text_p = "AUTO_MEDIAN"; break; case AR_LABELING_THRESH_MODE_AUTO_OTSU: text_p = "AUTO_OTSU"; break; case AR_LABELING_THRESH_MODE_AUTO_ADAPTIVE: text_p = "AUTO_ADAPTIVE"; break; case AR_LABELING_THRESH_MODE_AUTO_BRACKETING: text_p = "AUTO_BRACKETING"; break; default: text_p = "UNKNOWN"; break; } snprintf(text, sizeof(text), "Threshold mode: %s", text_p); if (threshMode != AR_LABELING_THRESH_MODE_AUTO_ADAPTIVE) { arGetLabelingThresh(gARHandle, &thresh); len = (int)strlen(text); snprintf(text + len, sizeof(text) - len, ", thresh=%d", thresh); } print(text, 2.0f, (line - 1) * 12.0f + 2.0f, 0, 1); line++; // Border size, image processing mode, pattern detection mode. arGetBorderSize(gARHandle, &tempF); snprintf(text, sizeof(text), "Border: %0.1f%%", tempF * 100.0); arGetPatternDetectionMode(gARHandle, &mode); switch (mode) { case AR_TEMPLATE_MATCHING_COLOR: text_p = "Colour template (pattern)"; break; case AR_TEMPLATE_MATCHING_MONO: text_p = "Mono template (pattern)"; break; case AR_MATRIX_CODE_DETECTION: text_p = "Matrix (barcode)"; break; case AR_TEMPLATE_MATCHING_COLOR_AND_MATRIX: text_p = "Colour template + Matrix (2 pass, pattern + barcode)"; break; case AR_TEMPLATE_MATCHING_MONO_AND_MATRIX: text_p = "Mono template + Matrix (2 pass, pattern + barcode "; break; default: text_p = "UNKNOWN"; break; } len = (int)strlen(text); snprintf(text + len, sizeof(text) - len, ", Pattern detection mode: %s", text_p); print(text, 2.0f, (line - 1) * 12.0f + 2.0f, 0, 1); line++; // Window size. snprintf(text, sizeof(text), "Drawing into %dx%d window", windowWidth, windowHeight); print(text, 2.0f, (line - 1) * 12.0f + 2.0f, 0, 1); line++; }
// Called to draw scene void RenderScene(void) { // Earth and Moon angle of revolution static float fMoonRot = 0.0f; static float fEarthRot = 0.0f; // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Save the matrix state and do the rotations glMatrixMode(GL_MODELVIEW); glPushMatrix(); glRotatef(xRot, 1.0f, 0.0f, 0.0f); //glRotatef(yRot, 0.0f, 1.0f, 0.0f); glRotatef(yRot, 0.0f, 0.0f, 1.0f); //TRAVAR NO EIXO 'Z'. // Translate the whole scene out and into view glTranslatef(0.0f, 0.0f, -300.0f); // Set material color, Red // Sun //glDisable(GL_LIGHTING); glColor3ub(0, 0, 255); glutSolidSphere(15.0f, 30, 17); // glEnable(GL_LIGHTING); // Move the light after we draw the sun! //glLightfv(GL_LIGHT0,GL_POSITION,lightPos); // Rotate coordinate system glRotatef(fEarthRot, 0.0f, 1.0f, 0.0f); // Draw the Earth glDisable(GL_LIGHTING); glColor3ub(255, 255,0); glTranslatef(105.0f,0.0f,0.0f); glutSolidSphere(15.0f, 30, 17); glEnable(GL_LIGHTING); glLightfv(GL_LIGHT0,GL_POSITION,lightPos); // Rotate from Earth based coordinates and draw Moon glColor3ub(200,200,200); glRotatef(fMoonRot,0.0f, 1.0f, 0.0f); glTranslatef(30.0f, 0.0f, 0.0f); //fMoonRot+= 15.0f; //if(fMoonRot > 360.0f) // fMoonRot = 0.0f; glutSolidSphere(6.0f, 30, 17); // Restore the matrix state glPopMatrix(); // Modelview matrix // Step earth orbit 5 degrees fEarthRot += 5.0f; if(fEarthRot > 360.0f) fEarthRot = 0.0f; // Show the image glutSwapBuffers(); }
int main(int argc, char *argv[]) { SDL_Window *window; SDL_GLContext context; // Slightly different SDL initialization if ( SDL_Init(SDL_INIT_VIDEO) != 0 ) { printf("Unable to initialize SDL: %s\n", SDL_GetError()); return 1; } SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); // *new* window = SDL_CreateWindow("sdl_fog_density", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_OPENGL); if ( !window ) { printf("Unable to create window: %s\n", SDL_GetError()); return 1; } context = SDL_GL_CreateContext(window); // Set the OpenGL state after creating the context with SDL_SetVideoMode glClearColor( 0, 0, 0, 0 ); glEnable( GL_TEXTURE_2D ); // Needed when we're using the fixed-function pipeline. glViewport( 0, 0, 640, 480 ); glMatrixMode( GL_PROJECTION ); glPushMatrix(); // just for testing glLoadIdentity(); glOrtho( 0, 640, 480, 0, -1000, 1000 ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); // Load the OpenGL texture GLuint texture; // Texture object handle SDL_Surface *surface; // Gives us the information to make the texture if ( (surface = IMG_Load("screenshot.png")) ) { // Check that the image's width is a power of 2 if ( (surface->w & (surface->w - 1)) != 0 ) { printf("warning: image.bmp's width is not a power of 2\n"); } // Also check if the height is a power of 2 if ( (surface->h & (surface->h - 1)) != 0 ) { printf("warning: image.bmp's height is not a power of 2\n"); } // Have OpenGL generate a texture object handle for us glGenTextures( 1, &texture ); // Bind the texture object glBindTexture( GL_TEXTURE_2D, texture ); // Set the texture's stretching properties glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); //SDL_LockSurface(surface); // Add some greyness memset(surface->pixels, 0x66, surface->w*surface->h); // Edit the texture object's image data using the information SDL_Surface gives us glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, surface->w, surface->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels ); //SDL_UnlockSurface(surface); } else { printf("SDL could not load image.bmp: %s\n", SDL_GetError()); SDL_Quit(); return 1; } // Free the SDL_Surface only if it was successfully created if ( surface ) { SDL_FreeSurface( surface ); } // Clear the screen before drawing glClear( GL_COLOR_BUFFER_BIT ); // Bind the texture to which subsequent calls refer to glBindTexture( GL_TEXTURE_2D, texture ); glEnable(GL_FOG); GLfloat fogColor[] = { 1.0, 0.5, 0.5, 0.05 }; glFogfv(GL_FOG_COLOR, fogColor); glFogf(GL_FOG_DENSITY, 0.2); glFogi(GL_FOG_MODE, GL_EXP2); assert(glIsEnabled(GL_FOG)); glBegin( GL_QUADS ); glTexCoord2i( 0, 0 ); glVertex3f( 10, 10, 10 ); glTexCoord2i( 1, 0 ); glVertex3f( 300, 10, 10 ); glTexCoord2i( 1, 1 ); glVertex3f( 300, 128, 10 ); glTexCoord2i( 0, 1 ); glVertex3f( 10, 128, 10 ); glTexCoord2f( 0, 0.5 ); glVertex3f( 410, 10, 5 ); glTexCoord2f( 1, 0.5 ); glVertex3f( 600, 10, 6 ); glTexCoord2f( 1, 1 ); glVertex3f( 630, 200, 7 ); glTexCoord2f( 0.5, 1 ); glVertex3f( 310, 250, 8 ); glEnd(); glBegin( GL_TRIANGLE_STRIP ); glTexCoord2i( 0, 0 ); glVertex3f( 100, 300, 1 ); glTexCoord2i( 1, 0 ); glVertex3f( 300, 300, 1 ); glTexCoord2i( 1, 1 ); glVertex3f( 300, 400, 1 ); glTexCoord2i( 0, 1 ); glVertex3f( 500, 410, 1 ); glEnd(); glDisable(GL_TEXTURE_2D); glColor3ub(90, 255, 255); glBegin( GL_QUADS ); glVertex3f( 10, 410, 5 ); glVertex3f( 300, 410, 50 ); glVertex3f( 300, 480, 100 ); glVertex3f( 10, 470, 5 ); glEnd(); glBegin( GL_QUADS ); glColor3f(1.0, 0, 1.0); glVertex3f( 410, 410, 10 ); glColor3f(0, 1.0, 0); glVertex3f( 600, 410, 10 ); glColor3f(0, 0, 1.0); glVertex3f( 600, 480, 10 ); glColor3f(1.0, 1.0, 1.0); glVertex3f( 410, 470, 10 ); glEnd(); SDL_GL_SwapWindow(window); #if !defined(__EMSCRIPTEN__) // Wait for 3 seconds to give us a chance to see the image SDL_Delay(30000); #endif // Now we can delete the OpenGL texture and close down SDL glDeleteTextures( 1, &texture ); SDL_Quit(); return 0; }
void draw(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // glEnable(GL_DEPTH_TEST); //setOrthographicCubeProjection(1.f); glPushMatrix(); glLoadIdentity(); glRotatef(rotateX,1,0,0); glRotatef(-rotateY,0,1,0); glScalef(scale,scale,scale); glTranslatef(-0.5,-0.5,-0.5); console.push_back("Hello collisions"); glColor3ub(155,155,155); if (showWire) { //const size_t size = tris.size(); glBegin(GL_LINES); for (unsigned i=0;i<objs.size();i++) { for (unsigned j=0;j<objs[i].faces_.size();j++) { const Real3& a = objs[i].tvx_[objs[i].faces_[j][0]]; const Real3& b = objs[i].tvx_[objs[i].faces_[j][1]]; const Real3& c = objs[i].tvx_[objs[i].faces_[j][2]]; glVertex3fv(&a[0]); glVertex3fv(&b[0]); glVertex3fv(&b[0]); glVertex3fv(&c[0]); glVertex3fv(&c[0]); glVertex3fv(&a[0]); } if (showNormals) { glColor3ub(0,255,0); for (unsigned j=0;j<objs[i].tnormals_.size();j++) { const Real3& n = objs[i].tnormals_[j]; const Real3& v = objs[i].tvx_[j]; glVertex3fv(&v[0]); glVertex3fv(&(v+0.01*n)[0]); } } } glEnd(); } glColor3ub(255,0,0); // glBegin(GL_LINES); // if (true) { // glVertex3f(seg[0].x,seg[0].y,seg[0].z); // glVertex3f(seg[1].x,seg[1].y,seg[1].z); // // } // glEnd(); // // public: // Vector<const Polygon *> polys_; // Vector<int> users_; // Vec3f segmentPt0_; // Vec3f segmentPt1_; // }; glColor3ub(255,0,0); if (showGeom) { glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); // glEnable(GL_DEPTH_TEST); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); for(unsigned i=0;i<objs.size();i++) { glVertexPointer(3, GL_FLOAT, 0, &objs[i].tvx_[0]); glNormalPointer(GL_FLOAT, 0, &objs[i].tnormals_[0]); glColorPointer(3,GL_UNSIGNED_BYTE, 0, &objs[i].colors_[0]); glDrawElements( GL_TRIANGLES, objs[i].faces_.size()*3, GL_UNSIGNED_INT, &objs[i].faces_[0]); } glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); glDisable(GL_LIGHTING); // glDisable(GL_DEPTH_TEST); } glDisable(GL_DEPTH_TEST); glBegin(GL_LINES); for(unsigned i=0;i<objs.size();i++) { glColor3ub(0,255,0); for (unsigned j=0;j<12;j++) { BoxEdge e = coltrees[i]->getRootNode()->aabb.getEdge(j); Vec3f s = e.p0; Vec3f p = e.p1; glVertex3f(s.x,s.y,s.z); glVertex3f(p.x,p.y,p.z); } for (unsigned j=0;j<colres[i].polys_.size();j++) { const Real3& a = objs[i].tvx_[colres[i].polys_[j]->getIndex(0)]; const Real3& b = objs[i].tvx_[colres[i].polys_[j]->getIndex(1)]; const Real3& c = objs[i].tvx_[colres[i].polys_[j]->getIndex(2)]; glVertex3fv(&a[0]); glVertex3fv(&b[0]); glVertex3fv(&b[0]); glVertex3fv(&c[0]); glVertex3fv(&c[0]); glVertex3fv(&a[0]); } Vec3f s = colres[i].segmentPt0_; Vec3f p = colres[i].segmentPt1_; glVertex3f(s.x,s.y,s.z); glVertex3f(p.x,p.y,p.z); } glEnd(); glEnable(GL_DEPTH_TEST); drawCube(1.); drawAxis(0.01); // glDisable(GL_DEPTH_TEST); glPopMatrix(); testTextOverlay(); glutSwapBuffers(); }
void GameMenu::DrawObjects (void) { //fishing rod glColor3ub(125, 54, 3); glBegin(GL_QUADS); glVertex2d(785.0, 480.0); glVertex2d(770.0, 485.0); glVertex2d(625.0, 310.0); glVertex2d(632.0, 293.0); glVertex2d(632.0, 293.0); glVertex2d(625.0, 310.0); glVertex2d(480.0, 178.0); glVertex2d(486.0, 168.0); glVertex2d(486.0, 168.0); glVertex2d(480.0, 178.0); glVertex2d(340.0, 104.0); glVertex2d(338.0, 86.0); glVertex2d(338.0, 86.0); glVertex2d(340.0, 104.0); glVertex2d(206.0, 67.0); glVertex2d(183.0, 52.0); glEnd(); //string glColor3ub(50, 50, 50); glBegin(GL_LINE_STRIP); glVertex2d(185.0, 57.0); glVertex2d(144.0, 119.0); glVertex2d(114.0, 197.0); glVertex2d(95.0, 279.0); glEnd(); //hook glColor3ub(169, 169, 0); glBegin(GL_QUADS); glVertex2d(90.0, 279.0); glVertex2d(100.0, 279.0); glVertex2d(102.0, 327.0); glVertex2d(89.0, 337.0); glVertex2d(89.0, 337.0); glVertex2d(102.0, 327.0); glVertex2d(116.0, 346.0); glVertex2d(116.0, 363.0); glVertex2d(116.0, 363.0); glVertex2d(116.0, 346.0); glVertex2d(121.0, 341.0); glVertex2d(132.0, 342.0); glVertex2d(132.0, 342.0); glVertex2d(121.0, 341.0); glVertex2d(123.0, 328.0); glVertex2d(133.0, 328.0); glEnd(); }