如何让我的棋盘更大..我试图在这里制作一个程序1显示棋盘上2显示阴阳符号..如果它是在单独的程序它运行大但这里太小 [英] How to make my chess board bigger .. am trying here to make a program on 1 shows chess board on 2 shows yin-yang symbol .. if it were in separate program it runs big but here it is too small

查看:89
本文介绍了如何让我的棋盘更大..我试图在这里制作一个程序1显示棋盘上2显示阴阳符号..如果它是在单独的程序它运行大但这里太小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include <windows.h>
#include <gl/gl.h>
#include <gl/glut.h>
#include <math.h>
using namespace std;


// initializations
void Ok();
void Set_Transformations();
void Initialize(int argc, char *argv[]);
void OnKeyPress(unsigned char key, int x, int y);
void Draw(int number);
void Draw_Big_Circle(double radius, double x, double y);
void Draw_Black_Circle(double radius2,double x2, double y2);
void Draw_White_Circle(double radius3,double x3, double y3);
const float DEG2RAD = 3.141592653/180;

int main(int argc, char *argv[]) {
	Initialize(argc, argv);
	return 0;
}

void Initialize(int argc, char *argv[]) {
	glutInit(&argc, argv);     
	glutInitDisplayMode(GLUT_RGBA); 
	glutInitWindowPosition(100, 100);
	glutInitWindowSize(500, 500); 
	glutCreateWindow("Part One -Press(1)for ChessBoard--(2)for Yin-Yang symbol");
	Set_Transformations();
	glutDisplayFunc(Ok);
	glutKeyboardFunc(OnKeyPress);
	glutMainLoop();
}

void Set_Transformations() {
	glClearColor(1.0, 1.0, 1.0, 0.0);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(-100, 100, -100, 100);
	glMatrixMode(GL_MODELVIEW);
}

void Draw(int number){
	glClear(GL_COLOR_BUFFER_BIT);

	switch(number){

		case 1:  
			glBegin(GL_LINE_LOOP); //border
			glColor3f(0.0,0.0,0.0);
			glVertex2f(0, 80);
			glVertex2f(80, 80);
			glVertex2f(80, 0);
			glVertex2f(0, 0);
			glEnd();
			
			glBegin(GL_QUADS); //here the chess 
			
			glColor3f(0.6,0.6,0.6);
			for(int x=0; x<8; x++)
			for(int y=0; y<8; y++)
				if((x+y)%20)
				{	glVertex2f(x, y);
					glVertex2f(x+1, y);
					glVertex2f(x+1, y+1);
					glVertex2f(x, y+1);
			}
					glEnd();
					break;

		case 2:	
			Draw_Big_Circle(50,5,25);
			Draw_Black_Circle(25,5,50);
			Draw_White_Circle(25,5,0);
			Draw_Black_Circle(5,5,0);
			Draw_White_Circle(5,5,50);
			glEnd();
			break;
	}
	glFlush();
}

void Draw_Big_Circle(double radius, double x, double y){ 
	//Polygon
	glColor3f(0.0f, 0.0f, 0.0f);
	glBegin(GL_TRIANGLE_FAN);
		for (int angle = 0; angle <= 180; angle++){
			float degInRad = angle*DEG2RAD; 
			glVertex2f((float)(x + sin(degInRad) * radius), 
			(float)(y + cos(degInRad) * radius));
		}
	glEnd();

	//Border 
	glLineWidth(1.0f);
	glColor3d(0.0, 0.0, 0.0);
	glBegin(GL_POINTS); 
		for (float angle = 0; angle <= 360; angle += 0.05){
			float degInRad = angle*DEG2RAD;
			glVertex2f((float)(x + sin(degInRad) * radius), 
			(float)(y + cos(degInRad) * radius));
		}
	glEnd();
}

void Draw_Black_Circle(double radius2,double x2, double y2){

	//Polygon
	glColor3f(0.0f, 0.0f, 0.0f);
	glBegin(GL_TRIANGLE_FAN);
		for (int angle = 0; angle <= 360; angle++){
			float degInRad = angle*DEG2RAD; 
			glVertex2f((float)(x2 + sin(degInRad) * radius2), 
			(float)(y2 + cos(degInRad) * radius2));
		}
		
	glEnd();
}

void Draw_White_Circle(double radius3,double x3, double y3){

	//Polygon
	glColor3f(1.0f, 1.0f, 1.0f);
	glBegin(GL_TRIANGLE_FAN);
		for (int angle = 0; angle <= 360; angle++){
			float degInRad = angle*DEG2RAD; 
			glVertex2f((float)(x3 + sin(degInRad) * radius3), 
			(float)(y3 + cos(degInRad) * radius3));
		}
		
	glEnd();
}
void Ok(){
	glClear(GL_COLOR_BUFFER_BIT);
	glFlush();
}
void OnKeyPress(unsigned char key, int x, int y)
{
	if(key == 27)
	{
		exit(0);
	}

	switch(key)
	{
		case '1':
			Draw(1);
			break;
		case '2':
			Draw(2);
			break;
	}
}

推荐答案

这篇关于如何让我的棋盘更大..我试图在这里制作一个程序1显示棋盘上2显示阴阳符号..如果它是在单独的程序它运行大但这里太小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆