void motion(int x, int y) { static GLint savepoint[2]; /* 以前のラバーバンドの端点 */ /* 論理演算機能 ON */ glEnable(GL_COLOR_LOGIC_OP); glLogicOp(GL_INVERT); glBegin(GL_LINES); if (rubberband) { /* 以前のラバーバンドを消す */ glVertex2iv(point[pointnum - 1]); glVertex2iv(savepoint); } /* 新しいラバーバンドを描く */ glVertex2iv(point[pointnum - 1]); glVertex2i(x, y); glEnd(); glFlush(); /* 論理演算機能 OFF */ glLogicOp(GL_COPY); glDisable(GL_COLOR_LOGIC_OP); /* 今描いたラバーバンドの端点を保存 */ savepoint[0] = x; savepoint[1] = y; /* 今描いたラバーバンドは次のタイミングで消す */ rubberband = 1; }
void motion(int x, int y) { static GLint savepoint[2]; glEnable(GL_COLOR_LOGIC_OP); glLogicOp(GL_INVERT); glBegin(GL_LINES); if(rubberband){ glVertex2iv(point[pointnum - 1]); glVertex2iv(savepoint); } glVertex2iv(point[pointnum - 1]); glVertex2i(x, y); glEnd(); glFlush(); glLogicOp(GL_COPY); glDisable(GL_COLOR_LOGIC_OP); savepoint[0] = x; savepoint[1] = y; rubberband = 1; }
static void draw_dividers(FileLayout *layout, View2D *v2d) { const int step = (layout->tile_w + 2 * layout->tile_border_x); int v1[2], v2[2]; int sx; unsigned char col_hi[3], col_lo[3]; UI_GetThemeColorShade3ubv(TH_BACK, 30, col_hi); UI_GetThemeColorShade3ubv(TH_BACK, -30, col_lo); v1[1] = v2d->cur.ymax - layout->tile_border_y; v2[1] = v2d->cur.ymin; glBegin(GL_LINES); /* vertical column dividers */ sx = (int)v2d->tot.xmin; while (sx < v2d->cur.xmax) { sx += step; glColor3ubv(col_lo); v1[0] = v2[0] = sx; glVertex2iv(v1); glVertex2iv(v2); glColor3ubv(col_hi); v1[0] = v2[0] = sx + 1; glVertex2iv(v1); glVertex2iv(v2); } glEnd(); }
void display(){ glClear(GL_COLOR_BUFFER_BIT); if (n == 1 && (type == GL_LINE_STRIP || type == GL_LINE_LOOP)){ glColor3f(1, 1, 0); glBegin(GL_POINTS); glVertex2iv(vert[0]); glEnd(); } glBegin(type); glColor3f(1, 1, 0); for (int i = 0; i < n; i++) glVertex2iv(vert[i]); glEnd(); glBegin(GL_POINTS); for (int i = 0; i < k; i++){ if (outside_test(i) == false ){ glColor3f(0, 1, 0); } else glColor3f(1, 0, 0); glVertex2iv(test_points[i]); } glEnd(); glutSwapBuffers(); }
void mouse(int button, int state, int x, int y) { switch (button) { case GLUT_LEFT_BUTTON: /* ボタンを操作した位置を記録する */ point[pointnum][0] = x; point[pointnum][1] = y; if (state == GLUT_UP) { /* ボタンを押した位置から離した位置まで線を引く */ glColor3d(0.0, 0.0, 0.0); glBegin(GL_LINES); glVertex2iv(point[pointnum - 1]); /* 一つ前は押した位置 */ glVertex2iv(point[pointnum]); /* 今の位置は離した位置 */ glEnd(); glFlush(); /* 始点ではラバーバンドを描いていないので消さない */ rubberband = 0; } else { } if (pointnum < MAXPOINTS) ++pointnum; break; case GLUT_MIDDLE_BUTTON: break; case GLUT_RIGHT_BUTTON: break; default: break; } }
void pointcg() { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0, 0.0, 0.0); glBegin(GL_LINES); glVertex2i(50, 100); glVertex2i(50, 50); glEnd(); glColor3f(1.0, 1.0, 0); glBegin(GL_POINTS); glVertex2i(50, 100); glVertex2i(50, 50); glEnd(); glColor3f(0.0, 1.0, 1.0); GLint point1[] = {50,100}; GLint point2[] = {100, 100}; glBegin(GL_LINES); glVertex2iv(point1); glVertex2iv(point2); glEnd(); glFlush(); }
/* draw stroke defined in buffer (simple ogl lines/points for now, as dotted lines) */ static void gp_draw_stroke_buffer (tGPspoint *points, int totpoints, short thickness, short dflag, short sflag) { tGPspoint *pt; int i; /* error checking */ if ((points == NULL) || (totpoints <= 0)) return; /* check if buffer can be drawn */ if (dflag & (GP_DRAWDATA_ONLY3D|GP_DRAWDATA_ONLYV2D)) return; /* if drawing a single point, draw it larger */ if (totpoints == 1) { /* draw point */ glBegin(GL_POINTS); glVertex2iv(&points->x); glEnd(); } else if (sflag & GP_STROKE_ERASER) { /* don't draw stroke at all! */ } else { float oldpressure = points[0].pressure; /* draw stroke curve */ if (G.debug & G_DEBUG) setlinestyle(2); glLineWidth(oldpressure * thickness); glBegin(GL_LINE_STRIP); for (i=0, pt=points; i < totpoints && pt; i++, pt++) { /* if there was a significant pressure change, stop the curve, change the thickness of the stroke, * and continue drawing again (since line-width cannot change in middle of GL_LINE_STRIP) */ if (fabsf(pt->pressure - oldpressure) > 0.2f) { glEnd(); glLineWidth(pt->pressure * thickness); glBegin(GL_LINE_STRIP); /* need to roll-back one point to ensure that there are no gaps in the stroke */ if (i != 0) glVertex2iv(&(pt - 1)->x); /* now the point we want... */ glVertex2iv(&pt->x); oldpressure = pt->pressure; } else glVertex2iv(&pt->x); } glEnd(); /* reset for predictable OpenGL context */ glLineWidth(1.0f); if (G.debug & G_DEBUG) setlinestyle(0); } }
void ScreenBuffer::drawPixel(int x, int y, double intensity) { int leftx = x * pixelWidth; int rightx = leftx + pixelWidth; int bottomy = y * pixelHeight; int topy = bottomy + pixelHeight; int p1 [] = {leftx , bottomy}; int p2 [] = {leftx , topy}; int p3 [] = {rightx , topy}; int p4 [] = {rightx , bottomy}; // cout << "dimensions of pixel square are: " // << p1[0] << ", " << p1[1] // << " -- " // << p3[0] << ", " << p3[1] << "\n"; glColor3d(intensity, intensity, intensity); glBegin (GL_POLYGON); glVertex2iv ( p1 ); glVertex2iv ( p4 ); glVertex2iv ( p3 ); glVertex2iv ( p2 ); glEnd(); checkGlErrors(); }
static void viconutil_draw_tri(GLint(*pts)[2]) { glBegin(GL_TRIANGLES); glVertex2iv(pts[0]); glVertex2iv(pts[1]); glVertex2iv(pts[2]); glEnd(); }
void Mesh::render(const vec3b& color, bool texturing, bool selected) const { bool use_texture = texturing && !tex_coord.empty(); glEnable(GL_NORMALIZE); glEnable(GL_LIGHTING); if (use_texture) { glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, texture_id); } auto& mesh = *this; auto triangles = mesh.triangles; triangles << top_cover.triangles; triangles << bottom_cover.triangles; glBegin(GL_TRIANGLES); for (auto& tri : triangles) { if (selected) glColor3ub(255, 0, 0); else if (use_texture) glColor3ub(255, 255, 255); else glColor3ubv(color.coords); glNormal3dv(tri.normal.coords); if (use_texture) glTexCoord2dv(tex(tri[0]).coords); glVertex3iv(mesh[tri[0]].coords); glNormal3dv(tri.normal.coords); if (use_texture) glTexCoord2dv(tex(tri[1]).coords); glVertex3iv(mesh[tri[1]].coords); glNormal3dv(tri.normal.coords); if (use_texture) glTexCoord2dv(tex(tri[2]).coords); glVertex3iv(mesh[tri[2]].coords); } glEnd(); if (use_texture) { glDisable(GL_TEXTURE_2D); } glDisable(GL_LIGHTING); glDisable(GL_NORMALIZE); #ifndef NDEBUG if (selected && use_texture) { glLineWidth(5); glColor3d(1, 0, 0); glBegin(GL_LINE_STRIP); for(auto &e: anchor_points) glVertex2iv(e[0].coords); glEnd(); glBegin(GL_LINE_STRIP); for (auto &e: anchor_points) glVertex2iv(e[1].coords); glEnd(); glLineWidth(1); } #endif glColor3d(1, 1, 1); }
static void sdrawtripoints(int x1, int y1, int x2, int y2) { int v[2]; v[0] = x1; v[1] = y1; glVertex2iv(v); v[0] = x1; v[1] = y2; glVertex2iv(v); v[0] = x2; v[1] = y1; glVertex2iv(v); }
void sdrawline(int x1, int y1, int x2, int y2) { int v[2]; glBegin(GL_LINE_STRIP); v[0] = x1; v[1] = y1; glVertex2iv(v); v[0] = x2; v[1] = y2; glVertex2iv(v); glEnd(); }
void display(void) { glClear(GL_COLOR_BUFFER_BIT); glBegin( GL_POINTS ); glVertex2iv( p ); // 配列で与えられた整数点を表示 glEnd( ); glFlush( ); }
// I thought about making a lookup table for this, but it would involve an STL map of STL vectors // and some weird function casts, so I'm doing it the naive way instead. void GeomRenderer::sendVertex(GLuint vertexIndex) { assert(vertexData.size >= 2 && vertexData.size <= 4); switch(vertexData.type) { case GL_SHORT: if (vertexData.size == 2) glVertex2sv((const GLshort*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride)); if (vertexData.size == 3) glVertex3sv((const GLshort*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride)); if (vertexData.size == 4) glVertex4sv((const GLshort*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride)); break; case GL_INT: if (vertexData.size == 2) glVertex2iv((const GLint*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride)); if (vertexData.size == 3) glVertex3iv((const GLint*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride)); if (vertexData.size == 4) glVertex4iv((const GLint*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride)); break; case GL_FLOAT: if (vertexData.size == 2) glVertex2fv((const GLfloat*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride)); if (vertexData.size == 3) glVertex3fv((const GLfloat*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride)); if (vertexData.size == 4) glVertex4fv((const GLfloat*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride)); break; case GL_DOUBLE: if (vertexData.size == 2) glVertex2dv((const GLdouble*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride)); if (vertexData.size == 3) glVertex3dv((const GLdouble*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride)); if (vertexData.size == 4) glVertex4dv((const GLdouble*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride)); break; } }
static int test09(int size, int num) { GLint vx[8][2]; GLint x0, y0, x1, y1, x2, y2, x3, y3; GLint i; GLint boxW, boxH; boxW = (24 - (COLS + 1) * GAP) / COLS; boxH = (24 - (ROWS + 1) * GAP) / ROWS; y0 = -boxH / 4; y1 = y0 + boxH / 2 / 3; y2 = y1 + boxH / 2 / 3; y3 = boxH / 4; x0 = -boxW / 4; x1 = x0 + boxW / 2 / 3; x2 = x1 + boxW / 2 / 3; x3 = boxW / 4; vx[0][0] = x0; vx[0][1] = y1; vx[1][0] = x0; vx[1][1] = y2; vx[2][0] = x1; vx[2][1] = y3; vx[3][0] = x2; vx[3][1] = y3; vx[4][0] = x3; vx[4][1] = y2; vx[5][0] = x3; vx[5][1] = y1; vx[6][0] = x2; vx[6][1] = y0; vx[7][0] = x1; vx[7][1] = y0; glBegin(GL_TRIANGLE_FAN); #if 0 if (errChk) printError("glBegin(GL_TRIANGLE_FAN)"); #endif if (verbose) crDebug("glBegin( GL_TRIANGLE_FAN )"); glVertex2i(0, 0); for (i = 0; i < 8; i++) { glVertex2iv(vx[i]); } glEnd(); glBegin(GL_TRIANGLE_FAN); glVertex2i(0, 0); glVertex2i(-100, 100); glEnd(); return size * num / 5; }
void Graph::drawGraph(){ //Add Axis Labeling glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glTranslated(-.5, -.5, 0); GLdouble sX = 1 / ((GLdouble)mX + 1); GLdouble sY = 1 / ((GLdouble)mY + 1); glScaled(sX, sY, 1); glColor3f(0, 0, 0); glBegin(GL_LINES); glVertex2i(lX, 0); glVertex2i(mX, 0); glVertex2i(0, lY); glVertex2i(0, mY); glEnd(); glBegin(GL_LINE_STRIP); glVertex2i(0, 0); for (std::list<Point>::iterator cPoint = points.begin(); cPoint != points.end(); ++cPoint){ glVertex2iv(cPoint->getPoint()); } glEnd(); glPopMatrix(); }
void mouse(int button, int state, int x, int y) { switch(button){ case GLUT_LEFT_BUTTON: point[pointnum][0] = x; point[pointnum][1] = y; if(state == GLUT_UP){ glColor3d(0.0, 0.0, 0.0); glBegin(GL_LINES); glVertex2iv(point[pointnum - 1]); glVertex2iv(point[pointnum]); glEnd(); glFlush(); rubberband = 0; }else{ } if(pointnum < MAXPOINTS - 1) ++pointnum; break; case GLUT_MIDDLE_BUTTON: printf("middle"); break; case GLUT_RIGHT_BUTTON: printf("right"); break; default: break; } printf("button is "); switch(state){ case GLUT_UP: printf("up"); break; case GLUT_DOWN: printf("down"); break; default: break; } printf(" at (%d,%d)\n", x, y); }
static void viconutil_draw_lineloop(GLint(*pts)[2], int numPoints) { int i; glBegin(GL_LINE_LOOP); for (i = 0; i < numPoints; i++) { glVertex2iv(pts[i]); } glEnd(); }
static void vicon_small_tri_right_draw(int x, int y, int w, int UNUSED(h), float alpha) { GLint pts[3][2]; int cx = x + w / 2 - 4; int cy = y + w / 2; int d = w / 5, d2 = w / 7; viconutil_set_point(pts[0], cx - d2, cy + d); viconutil_set_point(pts[1], cx - d2, cy - d); viconutil_set_point(pts[2], cx + d2, cy); glColor4f(0.2f, 0.2f, 0.2f, alpha); glBegin(GL_TRIANGLES); glVertex2iv(pts[0]); glVertex2iv(pts[1]); glVertex2iv(pts[2]); glEnd(); }
void sdrawXORline4(int nr, int x0, int y0, int x1, int y1) { static int old[4][2][2]; static char flags[4] = {0, 0, 0, 0}; /* with builtin memory, max 4 lines */ set_inverted_drawing(1); glBegin(GL_LINES); if (nr == -1) { /* flush */ for (nr = 0; nr < 4; nr++) { if (flags[nr]) { glVertex2iv(old[nr][0]); glVertex2iv(old[nr][1]); flags[nr] = 0; } } } else { if (nr >= 0 && nr < 4) { if (flags[nr]) { glVertex2iv(old[nr][0]); glVertex2iv(old[nr][1]); } old[nr][0][0] = x0; old[nr][0][1] = y0; old[nr][1][0] = x1; old[nr][1][1] = y1; flags[nr] = 1; } glVertex2i(x0, y0); glVertex2i(x1, y1); } glEnd(); set_inverted_drawing(0); }
void display(void) { glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_LINES); for(int i = 0; i < 10; i++) { verts[i][0] = i; verts[i][1] = 5; glVertex2iv((GLint *) verts[i]); } glEnd(); glFlush(); }
static void vicon_disclosure_tri_down_draw(int x, int y, int w, int UNUSED(h), float alpha) { GLint pts[3][2]; int cx = x + w / 2; int cy = y + w / 2; int d = w / 3, d2 = w / 5; viconutil_set_point(pts[0], cx + d, cy + d2); viconutil_set_point(pts[1], cx - d, cy + d2); viconutil_set_point(pts[2], cx, cy - d2); glBegin(GL_TRIANGLES); glColor4f(0.8f, 0.8f, 0.8f, alpha); glVertex2iv(pts[0]); glVertex2iv(pts[1]); glColor4f(0.3f, 0.3f, 0.3f, alpha); glVertex2iv(pts[2]); glEnd(); glColor4f(0.0f, 0.0f, 0.0f, 1); viconutil_draw_lineloop_smooth(pts, 3); }
void display(void) { int i; glClear(GL_COLOR_BUFFER_BIT); /* 記録したデータで線を描く */ if (pointnum > 1) { glColor3d(0.0, 0.0, 0.0); glBegin(GL_LINES); for (i = 0; i < pointnum; ++i) { glVertex2iv(point[i]); } glEnd(); } glFlush(); }
/** * Callback that draws a line between the mouse and a position given as the initial argument. */ void ED_region_draw_mouse_line_cb(const bContext *C, ARegion *ar, void *arg_info) { wmWindow *win = CTX_wm_window(C); const float *mval_src = (float *)arg_info; const int mval_dst[2] = {win->eventstate->x - ar->winrct.xmin, win->eventstate->y - ar->winrct.ymin}; UI_ThemeColor(TH_VIEW_OVERLAY); setlinestyle(3); glBegin(GL_LINE_STRIP); glVertex2iv(mval_dst); glVertex2fv(mval_src); glEnd(); setlinestyle(0); }
void draw(int s){ int i; int zero = 0; for(int i = s; i < pointnum; i++){ if(point[i][0] == 0 && point[i][1] == 0){ zero = i; break; } } if(zero == 0){ glColor3d(0.0, 0.0, 0.0); glBegin(GL_LINE_STRIP); for(i = s; i < pointnum; i++){ glVertex2iv(point[i]); } glEnd(); } else{ glColor3d(0.0, 0.0, 0.0); glBegin(GL_LINE_STRIP); for(i = s; i < zero; ++i){ glVertex2iv(point[i]); } glEnd(); } if(zero+1 > pointnum-1){ return; } else{ if(zero == 0){ } else{ draw(zero+1); } } }
GLvoid CALLBACK draw(void) { int i; if(num>=2){ glClearColor(1.0,1.0,1.0,0.0); glClear(GL_COLOR_BUFFER_BIT); glColor3d(0.0,0.0,0.0); glBegin(GL_LINE_STRIP); for(i=0;i<num;i++) { glVertex2iv(point[i]); } glEnd(); glFlush(); } }
void myBigDipper() { GLint vertices[7][2] = {{20, 10}, {74, 74}, {129, 83}, {194, 101}, {239, 67}, {320, 128}, {289, 190}}; glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_POINTS); glVertex2iv(vertices[0]); glVertex2iv(vertices[1]); glVertex2iv(vertices[2]); glVertex2iv(vertices[3]); glVertex2iv(vertices[4]); glVertex2iv(vertices[5]); glVertex2iv(vertices[6]); glEnd(); glFlush(); }
/* Draw the window - this is where all the GL actions are */ void display(void) { int i; /* clear the screen to white */ glClearColor(1.0, 1.0, 1.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); /* draw a black line */ glColor3f(0.0, 0.0, 0.0); glBegin(GL_LINES); for (i = 0; i < NENDS; ++i) { glVertex2iv((GLint *) ends[i]); } glEnd(); glFlush(); }
static void TriangleFan(void) { GLint vx[8][2]; GLint x0,y0,x1,y1,x2,y2,x3,y3; GLint i; y0=-boxH/4; y1=y0+boxH/2/3; y2=y1+boxH/2/3; y3=boxH/4; x0=-boxW/4; x1=x0+boxW/2/3; x2=x1+boxW/2/3; x3=boxW/4; vx[0][0]=x0;vx[0][1]=y1; vx[1][0]=x0;vx[1][1]=y2; vx[2][0]=x1;vx[2][1]=y3; vx[3][0]=x2;vx[3][1]=y3; vx[4][0]=x3;vx[4][1]=y2; vx[5][0]=x3;vx[5][1]=y1; vx[6][0]=x2;vx[6][1]=y0; vx[7][0]=x1;vx[7][1]=y0; glBegin(GL_TRIANGLE_FAN); AUX_SETCOLOR(windType,AUX_WHITE); glVertex2i(0,0); for(i=0;i<8;i++) { AUX_SETCOLOR(windType,AUX_WHITE-i); glVertex2iv(vx[i]); } glEnd(); glBegin(GL_TRIANGLE_FAN); glVertex2i(0,0); glVertex2i(-100,100); glEnd(); }
static void PolygonFunc(void) { GLint vx[8][2]; GLint x0, y0, x1, y1, x2, y2, x3, y3; GLint i; y0 = -boxH/4; y1 = y0 + boxH/2/3; y2 = y1 + boxH/2/3; y3 = boxH/4; x0 = -boxW/4; x1 = x0 + boxW/2/3; x2 = x1 + boxW/2/3; x3 = boxW/4; vx[0][0] = x0; vx[0][1] = y1; vx[1][0] = x0; vx[1][1] = y2; vx[2][0] = x1; vx[2][1] = y3; vx[3][0] = x2; vx[3][1] = y3; vx[4][0] = x3; vx[4][1] = y2; vx[5][0] = x3; vx[5][1] = y1; vx[6][0] = x2; vx[6][1] = y0; vx[7][0] = x1; vx[7][1] = y0; glBegin(GL_POLYGON); for (i = 0; i < 8; i++) { SetColor(COLOR_WHITE-i); glVertex2iv(vx[i]); } glEnd(); glBegin(GL_POLYGON); glVertex2i(0, 0); glVertex2i(100, 100); glEnd(); }