当前位置:首页 > 代码 > 正文

计算机图形学程序代码(计算机绘图程序)

admin 发布:2022-12-19 04:53 85


本篇文章给大家谈谈计算机图形学程序代码,以及计算机绘图程序对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

求C源码:计算机图形学程序——扫描线算法

这是我以前上学的时候写的,你改改,凑活用巴。

=============================

#include graphics.h

#include stdio.h

#include dos.h

#include math.h

#include bios.h

#include string.h

void parspl ( int p[10000][2] , long n , int precision , int color )

{

int x = 0 , y = 0 , i = 0 , j = 0 , m = 0 ;

double t2 = 0 , t3 = 0 , t = 0 , a , b , c , d , e = p[1][0] + 5 , f = p[1][1] + 5 ;

setcolor ( color ) ;

m=n+1;

p[0][0] = p[n][0] ;

p[0][1] = p[n][1] ;

p[m][0] = p[1][0] ;

p[m][1] = p[1][1] ;

p[m+1][0] = p[2][0] ;

p[m+1][1] = p[2][1] ;

moveto ( p[1][0] , p[1][1] ) ;

for ( i = 0 ; i n ; i ++ )

{

t = 0.5 / precision ;

for ( j = 1 ; j precision ; j ++ )

{

t2 = t * t ;

t3 = t2 * t ;

a = 4 * t2 - t - 4 * t3 ;

b = 1 - 10 * t2 + 12 * t3 ;

c = t + 8 * t2 - 12 * t3 ;

d = 4 * t3 - 2 * t2 ;

x = a * p[i][0] + b * p[i+1][0] + c * p[i+2][0] + d * p[i+3][0] ;

y = a * p[i][1] + b * p[i+1][1] + c * p[i+2][1] + d * p[i+3][1] ;

lineto ( x , y ) ;

line ( e , f , x + 5 , y + 5 ) ;

moveto ( x , y ) ;

t += 0.5 / precision ;

e = x + 5 ;

f = y + 5 ;

}

lineto ( p[i+2][0] , p[i+2][1] ) ;

moveto ( e , f ) ;

lineto ( p[i+2][0] + 5 , p[i+2][1] + 5 ) ;

moveto ( p[i+2][0] , p[i+2][1] ) ;

}

}

int main()

{

long n = 5 ;

char pwd[4] ;

int p[100][2] ;

int a1 , a2 , b1 , b2 , c1 , c2 , d1 , d2 , e1 , e2 ;

int gdriver = VGA , gmode = VGAHI ;

initgraph( gdriver , gmode , "c:\\tc" ) ;

setbkcolor ( 0 ) ;

a1 = p[1][0] = 320 ;

a2 = p[1][1] = 240 ;

b1 = p[2][0] = 320 ;

b2 = p[2][1] = 120 ;

c1 = p[3][0] = 452 ;

c2 = p[3][1] = 128 ;

d1 = p[4][0] = 382 ;

d2 = p[4][1] = 388 ;

e1 = p[5][0] = 364 ;

e2 = p[5][1] = 280 ;

loop:

if ( a1 = p[1][0] p[1][0] = 520 )

{

a1 = p[1][0] ;

p[1][0] += 1 ;

}

else

{

if ( p[1][0] = 120 )

{

a1 = p[1][0] ;

p[1][0] -= 1 ;

}

else

a1 = p[1][0] = 120 ;

}

if ( a2 = p[1][1] p[1][1] = 60 )

{

a2 = p[1][1] ;

p[1][1] -= 2 ;

}

else

{

if ( p[1][1] = 420 )

{

a2 = p[1][1] ;

p[1][1] += 2 ;

}

else

a2 = p[1][1] = 420 ;

}

if ( b1 = p[2][0] p[2][0] = 120 )

{

b1 = p[2][0] ;

p[2][0] -= 2 ;

}

else

{

if ( p[2][0] = 520 )

{

b1 = p[2][0] ;

p[2][0] += 2 ;

}

else

b1 = p[2][0] = 520 ;

}

if ( b2 = p[2][1] p[2][1] = 420 )

{

b2 = p[2][1] ;

p[2][1] += 1 ;

}

else

{

if ( p[2][1] = 60 )

{

b2 = p[2][1] ;

p[2][1] -= 1 ;

}

else

b2 = p[2][1] = 60 ;

}

if ( c1 = p[3][0] p[3][0] = 520 )

{

c1 = p[3][0] ;

p[3][0] += 1 ;

}

else

{

if ( p[3][0] = 120 )

{

c1 = p[3][0] ;

p[3][0] -= 1 ;

}

else

c1 = p[3][0] = 120 ;

}

if ( c2 = p[3][1] p[3][1] = 420 )

{

c2 = p[3][1] ;

p[3][1] += 1 ;

}

else

{

if ( p[3][1] = 60 )

{

c2 = p[3][1] ;

p[3][1] -= 1 ;

}

else

c2 = p[3][1] = 60 ;

}

if ( d1 = p[4][0] p[4][0] = 120 )

{

d1 = p[4][0] ;

p[4][0] -= 1 ;

}

else

{

if ( p[4][0] = 520 )

{

d1 = p[4][0] ;

p[4][0] += 1 ;

}

else

d1 = p[4][0] = 520 ;

}

if ( d2 = p[4][1] p[4][1] = 60 )

{

d2 = p[4][1] ;

p[4][1] -= 1 ;

}

else

{

if ( p[4][1] = 420 )

{

d2 = p[4][1] ;

p[4][1] += 1 ;

}

else

d2 = p[4][1] = 420 ;

}

if ( e1 = p[5][0] p[5][0] = 520 )

{

e1 = p[5][0] ;

p[5][0] += 1 ;

}

else

{

if ( p[5][0] = 120 )

{

e1 = p[5][0] ;

p[5][0] -= 1 ;

}

else

e1 = p[5][0] = 120 ;

}

if ( e2 = p[5][1] p[5][1] = 420 )

{

e2 = p[5][1] ;

p[5][1] += 2 ;

}

else

{

if ( p[5][1] = 60 )

{

e2 = p[5][1] ;

p[5][1] -= 2 ;

}

else

e2 = p[5][1] = 60 ;

}

parspl ( p , n , 100 , 4 ) ;

parspl ( p , n , 100 , 4 ) ;

if ( bioskey ( 1 ) 0 )

{

printf ("Please Input Password:") ;

gets (pwd) ;

if ( !strcmp(pwd,"cmy") )

{

clearviewport () ;

closegraph () ;

return 1 ;

}

}

cleardevice () ;

goto loop ;

}

高分求一个计算机图形学的源程序

建立一个空的Win32应用程序,添加一个cpp文件,然后把代码拷进去就行了

#pragma comment(lib,"opengl32.lib")

#pragma comment(lib,"glu32.lib")

#pragma comment(lib,"glaux.lib")

#include windows.h

#include gl/gl.h

#include gl/glu.h

#include gl/glaux.h

HDC hDC=NULL;

HGLRC hRC=NULL;

HWND hWnd=NULL;

HINSTANCE hInstance;

BOOL keys[256];

BOOL active=TRUE;

BOOL fullscreen=TRUE;

GLfloat rtri;

GLfloat rquad;

LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);

GLvoid ResizeGLScene(GLsizei width,GLsizei height)

{

if(height==0)

height=1;

glViewport(0,0,width,height);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

}

int InitGL(GLvoid)

{

glShadeModel(GL_SMOOTH);

glClearColor(0.0f,0.0f,0.0f,0.5f);

glClearDepth(1.0f);

glEnable(GL_DEPTH_TEST);

glDepthFunc(GL_LEQUAL);

glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);

return TRUE;

}

int DrawGLScene(GLvoid)

{

glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

glLoadIdentity();

glTranslatef(-1.5f,0.0f,-6.0f);

glRotatef(rtri,0.0f,1.0f,0.0f);

glBegin(GL_TRIANGLES);

glColor3f(1.0f,0.0f,0.0f);

glVertex3f(0.0f,1.0f,0.0f);

glColor3f(0.0f,1.0f,0.0f);

glVertex3f(-1.0f,-1.0f,1.0f);

glColor3f(0.0f,0.0f,1.0f);

glVertex3f(1.0f,-1.0f,1.0f);

glColor3f(1.0f,0.0f,0.0f);

glVertex3f(0.0f,1.0f,0.0f);

glColor3f(0.0f,0.0f,1.0f);

glVertex3f(1.0f,-1.0f,1.0f);

glColor3f(0.0f,1.0f,0.0f);

glVertex3f(1.0f,-1.0f,-1.0f);

glColor3f(1.0f,0.0f,0.0f);

glVertex3f(0.0f,1.0f,0.0f);

glColor3f(0.0f,1.0f,0.0f);

glVertex3f(1.0f,-1.0f,-1.0f);

glColor3f(0.0f,0.0f,1.0f);

glVertex3f(-1.0f,-1.0f,-1.0f);

glColor3f(1.0f,0.0f,0.0f);

glVertex3f(0.0f,1.0f,0.0f);

glColor3f(0.0f,0.0f,1.0f);

glVertex3f(-1.0f,-1.0f,-1.0f);

glColor3f(0.0f,1.0f,0.0f);

glVertex3f(-1.0f,-1.0f,1.0f);

glEnd();

glLoadIdentity();

glTranslatef(1.5f,0.0f,-7.0f);

glRotatef(rquad,1.0f,1.0f,1.0f);

glBegin(GL_QUADS);

glColor3f(0.0f,1.0f,0.0f);

glVertex3f(1.0f,1.0f,-1.0f);

glVertex3f(-1.0f,1.0f,-1.0f);

glVertex3f(-1.0f,1.0f,1.0f);

glVertex3f(1.0f,1.0f,1.0f);

glColor3f(1.0f,0.5f,0.0f);

glVertex3f(1.0f,-1.0f,1.0f);

glVertex3f(-1.0f,-1.0f,1.0f);

glVertex3f(-1.0f,-1.0f,-1.0f);

glVertex3f(1.0f,-1.0f,-1.0f);

glColor3f(1.0f,0.0f,0.0f);

glVertex3f(1.0f,1.0f,1.0f);

glVertex3f(-1.0f,1.0f,1.0f);

glVertex3f(-1.0f,-1.0f,1.0f);

glVertex3f(1.0f,-1.0f,1.0f);

glColor3f(1.0f,1.0f,0.0f);

//glVertex3f(1.0f,-1.0f,-1.0f);

//glVertex3f(-1.0f,-1.0f,-1.0f);

//glVertex3f(-1.0f,1.0f,-1.0f);

//glVertex3f(1.0f,1.0f,-1.0f);

glVertex3f(-1.0f,1.0f,-1.0f);

glVertex3f(1.0f,1.0f,-1.0f);

glVertex3f(1.0f,-1.0f,-1.0f);

glVertex3f(-1.0f,-1.0f,-1.0f);

glColor3f(0.0f,0.0f,1.0f);

glVertex3f(-1.0f,1.0f,1.0f);

glVertex3f(-1.0f,1.0f,-1.0f);

glVertex3f(-1.0f,-1.0f,-1.0f);

glVertex3f(-1.0f,-1.0f,1.0f);

glColor3f(1.0f,0.0f,1.0f);

glVertex3f(1.0f,1.0f,-1.0f);

glVertex3f(1.0f,1.0f,1.0f);

glVertex3f(1.0f,-1.0f,1.0f);

glVertex3f(1.0f,-1.0f,-1.0f);

glEnd();

rtri+=0.2f;

rquad-=0.15f;

return TRUE;

}

GLvoid KillGLWindow(GLvoid)

{

if(fullscreen)

{

ChangeDisplaySettings(NULL,0);

ShowCursor(TRUE);

}

if(hRC)

{

if(!wglMakeCurrent(NULL,NULL))

MessageBox(NULL,"释放DC或RC失败","关闭错误",MB_OK|MB_ICONINFORMATION);

if(!wglDeleteContext(hRC))

MessageBox(NULL,"释放RC失败","关闭错误",MB_OK|MB_ICONINFORMATION);

hRC=NULL;

}

if(hDC !ReleaseDC(hWnd,hDC))

{

MessageBox(NULL,"释放DC失败","关闭错误",MB_OK|MB_ICONINFORMATION);

hDC=NULL;

}

if(hWnd !DestroyWindow(hWnd))

{

MessageBox(NULL,"释放窗口句柄失败","关闭错误",MB_OK|MB_ICONINFORMATION);

hWnd=NULL;

}

if(!UnregisterClass("OpenG",hInstance))

{

MessageBox(NULL,"不能注销窗口类","关闭错误",MB_OK|MB_ICONINFORMATION);

hInstance=NULL;

}

}

BOOL CreateGLWindow(char* title,int width,int height,int bits,BOOL fullscreenflag)

{

GLuint PixelFormat;

WNDCLASS wc;

DWORD dwExStyle;

DWORD dwStyle;

RECT WindowRect;

WindowRect.left=(long)0;

WindowRect.right=(long)width;

WindowRect.top=(long)0;

WindowRect.bottom=(long)height;

fullscreen=fullscreenflag;

hInstance=GetModuleHandle(NULL);

wc.style=CS_HREDRAW|CS_VREDRAW|CS_OWNDC;

wc.lpfnWndProc=(WNDPROC)WndProc;

wc.cbClsExtra=0;

wc.cbWndExtra=0;

wc.hInstance=hInstance;

wc.hIcon=LoadIcon(NULL,IDI_WINLOGO);

wc.hCursor=LoadCursor(NULL,IDC_ARROW);

wc.hbrBackground=NULL;

wc.lpszMenuName=NULL;

wc.lpszClassName="OpenG";

if(!RegisterClass(wc))

{

MessageBox(NULL,"注册窗口失败","错误",MB_OK|MB_ICONINFORMATION);

return FALSE;

}

if(fullscreen)

{

DEVMODE dmScreenSettings;

memset(dmScreenSettings,0,sizeof(dmScreenSettings));

dmScreenSettings.dmSize=sizeof(dmScreenSettings);

dmScreenSettings.dmPelsWidth=width;

dmScreenSettings.dmPelsHeight=height;

dmScreenSettings.dmBitsPerPel=bits;

dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;

if(ChangeDisplaySettings(dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL)

{

if(MessageBox(NULL,"全屏模式设置失败!\n使用窗口模式?","OpenGL 3D游戏编程",MB_YESNO|MB_ICONEXCLAMATION)==IDYES)

{

fullscreen=FALSE;

}

else

{

MessageBox(NULL,"程序将被关闭","错误",MB_OK|MB_ICONINFORMATION);

return FALSE;

}

}

}

if(fullscreen)

{

dwExStyle=WS_EX_APPWINDOW;

dwStyle=WS_POPUP;

ShowCursor(FALSE);

}

else

{

dwExStyle=WS_EX_APPWINDOW|WS_EX_WINDOWEDGE;

dwStyle=WS_OVERLAPPEDWINDOW;

}

AdjustWindowRectEx(WindowRect,dwStyle,FALSE,dwExStyle);

if(!(hWnd=CreateWindowEx(dwExStyle,"OpenG",title,

dwStyle|WS_CLIPSIBLINGS|WS_CLIPCHILDREN,0,0,

WindowRect.right-WindowRect.left,WindowRect.bottom-WindowRect.top,

NULL,NULL,hInstance,NULL)))

{

KillGLWindow();

MessageBox(NULL,"窗口创建失败","错误",MB_OK|MB_ICONINFORMATION);

return FALSE;

}

static PIXELFORMATDESCRIPTOR pfd=

{

sizeof(PIXELFORMATDESCRIPTOR),1,

PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER,

PFD_TYPE_RGBA,bits,

0,0,0,0,0,0,

0,

0,

0,

0,0,0,0,

16,

0,

0,

PFD_MAIN_PLANE,

0,

0,0,0

};

if(!(hDC=GetDC(hWnd)))

{

KillGLWindow();

MessageBox(NULL,"不能创建一个窗口设备描述表","错误",MB_OK|MB_ICONINFORMATION);

return FALSE;

}

if(!(PixelFormat=ChoosePixelFormat(hDC,pfd)))

{

KillGLWindow();

MessageBox(NULL,"不能创建一个匹配的像素格式","错误",MB_OK|MB_ICONINFORMATION);

return FALSE;

}

if(!SetPixelFormat(hDC,PixelFormat,pfd))

{

KillGLWindow();

MessageBox(NULL,"不能设置像素格式","错误",MB_OK|MB_ICONINFORMATION);

return FALSE;

}

if(!(hRC=wglCreateContext(hDC)))

{

KillGLWindow();

MessageBox(NULL,"不能创建OpenGL渲染描述表","错误",MB_OK|MB_ICONINFORMATION);

return FALSE;

}

if(!wglMakeCurrent(hDC,hRC))

{

KillGLWindow();

MessageBox(NULL,"不能激活当前的OpenGL渲染描述表","错误",MB_OK|MB_ICONINFORMATION);

return FALSE;

}

ShowWindow(hWnd,SW_SHOW);

SetForegroundWindow(hWnd);

SetFocus(hWnd);

ResizeGLScene(width,height);

if(!InitGL())

{

KillGLWindow();

MessageBox(NULL,"初始化失败","错误",MB_OK|MB_ICONINFORMATION);

return FALSE;

}

return TRUE;

}

LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)

{

switch(uMsg)

{

case WM_ACTIVATE:

{

if(!HIWORD(wParam))

active=TRUE;

else

active=FALSE;

return 0;

}

case WM_SYSCOMMAND:

{

switch(wParam)

{

case SC_SCREENSAVE:

case SC_MONITORPOWER:

return 0;

}

break;

}

case WM_CLOSE:

{

PostQuitMessage(0);

return 0;

}

case WM_KEYDOWN:

{

keys[wParam]=TRUE;

return 0;

}

case WM_KEYUP:

{

keys[wParam]=FALSE;

return 0;

}

case WM_SIZE:

{

ResizeGLScene(LOWORD(lParam),HIWORD(lParam));

return 0;

}

}

return DefWindowProc(hWnd,uMsg,wParam,lParam);

}

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)

{

MSG msg;

BOOL done=FALSE;

if(MessageBox(NULL,"你想在全屏模式下运行吗?","设置全屏模式",MB_YESNO|MB_ICONQUESTION)==IDNO)

{

fullscreen=FALSE;

}

if(!CreateGLWindow("Win32 SDK风格 OpenGL程序框架",640,480,16,fullscreen))

return 0;

while(!done)

{

if(PeekMessage(msg,NULL,0,0,PM_REMOVE))

{

if(msg.message==WM_QUIT)

done=TRUE;

else

{

TranslateMessage(msg);

DispatchMessage(msg);

}

}

else

{

if(active)

{

if(keys[VK_ESCAPE])

done=TRUE;

else

{

DrawGLScene();

SwapBuffers(hDC);

}

}

if(keys[VK_F1])

{

keys[VK_F1]=FALSE;

KillGLWindow();

fullscreen=!fullscreen;

if(!CreateGLWindow("Win32 SDK风格 OpenGL程序框架",640,480,16,fullscreen))

return 0;

}

}

}

KillGLWindow();

return msg.wParam;

}

计算机图形学问题,在C++环境下编写程序,希望给出完整代码

这个要你自己给出起点和终点:

#include stdio.h

#include stdlib.h

#include math.h

#include graphics.h

void swap_start_end(int x1,int y1,int x2,int y2);

void s_line(int x1,int y1,int x2,int y2);

main()

{

int x1,y1,x2,y2;

printf("Please input the start dot:\n");

scanf("%d%d",x1,y1);

printf("Please input the end dot:\n");

scanf("%d%d",x2,y2);

swap(x1,y1,x2,y2);

s_line(x1,y1,x2,y2);

}

void swap_start_end(int x1,int y1,int x2,int y2)

{

int mid;

mid=x1;

x1=y1;

y1=mid;

mid=x2;

x2=y2;

y2=mid;

}

void s_line(int x1,int y1,int x2,int y2)

{

int driver=DETECT,mode;

int curx,cury,dx,dy,tx,ty,mid,d,flag,i;

initgraph(driver,mode,"");

curx=x1;

cury=y1;

dx=abs(x2-x1);

dy=abs(y2-y1);

if(x2-x1=0)

tx=1;

else

tx=-1;

if(y2-y1=0)

ty=1;

else

ty=-1;

if(dxdy)

flag=0;

else

{

flag=1;

mid=dx;dx=dy;dy=mid;

mid=tx;tx=ty;ty=mid;

mid=x1;x1=y1;y1=mid;

mid=x2;x2=y2;y2=mid;

}

if(flag)

putpixel(cury,curx,2);

else

putpixel(curx,cury,2);

d=2*dy-dx;

for(i=0;idx;i++)

{

if(d=0)

{

d=d+2*(dy-dx);

cury+=ty;

}

else

d=d+2*dy;

curx+=tx;

if(flag)

putpixel(cury,curx,2);

else

putpixel(curx,cury,2);

}

getch();

closegraph();

}

计算机图形学程序

#include GL/glut.h

#include stdio.h

#include stdlib.h

void LineGL(int x0,int y0,int x1,int y1)

{

glBegin (GL_LINES);

glColor3f (1.0f, 0.0f, 0.0f); glVertex2f (x0,y0);

glColor3f (0.0f, 1.0f, 0.0f); glVertex2f (x1,y1);

glEnd ();

}

struct outcode

{

unsigned all;

unsigned left,right,top,bottom;

};

struct Rectangle

{

float xmin,xmax,ymin,ymax;

};

Rectangle rect;

int x0,y0,x1,y1;

GLboolean bClip = false;

void compoutcode(float x,float y,Rectangle rect,outcode *outcode)

{

outcode-all=0;

outcode-top=outcode-bottom=0;

if(y(float)rect.ymax)

{

outcode-top=1;

outcode-all+=1;

}

else if(y(float)rect.ymin)

{

outcode-bottom=1;

outcode-all+=1;

}

outcode-right=outcode-left=0;

if(x(float)rect.xmax)

{

outcode-right=1;

outcode-all+=1;

}

else if(x(float)rect.xmin)

{

outcode-left=1;

outcode-all+=1;

}

}

int cohensutherlandlineclip(Rectangle rect, int x0,int y0,int x1,int y1)

{

int accept,done;

outcode outcode0,outcode1;

outcode * outcodeout;

float x,y;

accept=0;

done=0;

compoutcode(x0,y0,rect,outcode0);

compoutcode(x1,y1,rect,outcode1);

do{

if(outcode0.all==0outcode1.all==0)

{

accept=1;

done=1;

}

else if(outcode0.alloutcode1.all!=0)

done=1;

else

{

if(outcode0.all!=0)

outcodeout=outcode0;

else

outcodeout=outcode1;

if(outcodeout-left)

{

y=y0+(y1-y0)*(rect.xmin-x0)/(x1-x0);

x=(float)rect.xmin;

}

else if(outcodeout-top)

{

x=x0+(x1-x0)*(rect.ymax-y0)/(y1-y0);

y=(float)rect.ymax;

}

else if(outcodeout-right)

{

y=y0+(y1-y0)*(rect.xmax-x0)/(x1-x0);

x=(float)rect.xmax;

}

else if(outcodeout-bottom)

{

x=x0+(x1-x0)*(rect.ymin-y0)/(y1-y0);

y=(float)rect.ymin;

}

if(outcodeout-all==outcode0.all)

{

x0=x;y0=y;compoutcode(x0,y0,rect,outcode0);

}

else

{

x1=x;y1=y;

compoutcode(x1,y1,rect,outcode1);

}

}

}while(!done);

if(accept)

LineGL(x0,y0,x1,y1);

return accept;

}

void myDisplay()

{

glClear(GL_COLOR_BUFFER_BIT);

glColor3f (1.0f, 0.0f, 0.0f);

glRectf(rect.xmin,rect.ymin,rect.xmax,rect.ymax);

if (!bClip)

LineGL(x0,y0,x1,y1);

else

cohensutherlandlineclip(rect, x0,y0,x1,y1);

glFlush();

}

void Init()

{

glClearColor(0.0, 0.0, 0.0, 0.0);

glShadeModel(GL_FLAT);

rect.xmin=100; //窗口的大小

rect.xmax=300;

rect.ymin=100;

rect.ymax=300;

x0 = 450,y0 = 0, x1 = 0, y1 = 450;//裁剪前的直线端点

printf("Press key 'c' to Clip!\nPress key 'r' to Restore!\n");

}

void Reshape(int w, int h)

{

glViewport(0, 0, (GLsizei) w, (GLsizei) h);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

gluOrtho2D(0.0, (GLdouble) w, 0.0, (GLdouble) h);

}

void keyboard(unsigned char key, int x, int y)

{

switch (key)

{

case 'c':

bClip = true;

glutPostRedisplay();//重画

break;

case 'r':

bClip = false;

Init();

glutPostRedisplay();//

break;

case 'x':

exit(0);

break;

default:

break;

}

}

int main(int argc, char *argv[])

{

glutInit(argc, argv);

glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);

glutInitWindowPosition(100, 100);

glutInitWindowSize(640, 480);

glutCreateWindow("Hello World!");

Init();

glutDisplayFunc(myDisplay);

glutReshapeFunc(Reshape);

glutKeyboardFunc(keyboard);

glutMainLoop();

return 0;

}

正好也在做试验, 这个是裁剪算法,我在VC下运行无错误。

还有torbc?是turbo c吧?因为编译环境有些区别,而网上找的又都是VC的,所以都会遇到错误。

建议去装个VC的 ,毕竟VC比turbo c主流

计算机图形学 画任意弧度圆弧和椭圆弧的算法代码c++

给出起点和终点:

#include stdio.h

#include stdlib.h

#include math.h

#include graphics.h

void swap_start_end(int x1,int y1,int x2,int y2);

void s_line(int x1,int y1,int x2,int y2);

main()

void swap_start_end(int x1,int y1,int x2,int y2)

{

int mid;

mid=x1;

x1=y1;

y1=mid;

mid=x2;

x2=y2;

y2=mid;

if(x2-x1=0)

dutx=1;

cury+=ty;

putpixel(i,j,2);

outtextxy(320,245,"0"); /*原点坐标*/

outtextxy(320-5*20,245,"-5");circle(320-5*20,240,2); /*横坐标值*/

outtextxy(320 5*20,245,"5");circle(320 5*20,240,2);

outtextxy(320-10*20,245,"-10");circle(320-10*20,240,2);

outtextxy(320 10*20,245,"10");circle(320 10*20,240,2);

outtextxy(320-15*20,245,"-15");circle(320-15*20,240,2);

outtextxy(320 15*20,245,"15");circle(320 15*20,240,2);

outtextxy(320,240-5*20,"-5");circle(320,240-5*20,2); /*纵坐标值*/

outtextxy(320,240 5*20,"5");circle(320,240 5*20,2);

outtextxy(320,240-10*20,"-10");circle(320,240-10*20,2);

outtextxy(320,240 10*20,"10");circle(320,240 10*20,2);

outtextxy(20,10,"The center of the circle is (0,0) "); /*坐标轴左上角显示提示信息*/

setcolor(RED); /*标记坐标轴*/

line(20,240,620,240); outtextxy(320 15*20,230,"X");

line(320,20,320,460); outtextxy(330,20,"Y");

扩展资料:

C++语言的程序因为要体现高性能,所以都是编译型的。但其开发环境,为了方便测试,将调试环境做成解释型的。即开发过程中,以解释型的逐条语句执行方式来进行调试,以编译型的脱离开发环境而启动运行的方式来生成程序最终的执行代码。

生成程序是指将源码(C++语句)转换成一个可以运行的应用程序的过程。如果程序的编写是正确的,那么通常只需按一个功能键,即可搞定这个过程。该过程实际上分成两个步骤。

第一步是对程序进行编译,这需要用到编译器(compiler)。编译器将C++语句转换成机器码(也称为目标码);如果这个步骤成功,下一步就是对程序进行链接,这需要用到链接器(linker)。链接器将编译获得机器码与C++库中的代码进行合并。

参考资料来源:百度百科-C++

计算机图形学程序代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于计算机绘图程序、计算机图形学程序代码的信息别忘了在本站进行查找喔。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/2687.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载