コード例 #1
0
ファイル: main.cpp プロジェクト: armerpaul/CUDA_RayTracer
Sphere* CreateSpheres() {
	Sphere* spheres = new Sphere[NUM_SPHERES]();
   int i=0, j=0, k=0, num=0;

   while (num < NUM_SPHERES) {
      for (i=0; i < 6 && num < NUM_SPHERES; i++) {
         for (j=0; j < 5 && num < NUM_SPHERES; j++) {
            spheres[num].radius = 30. - rand() % 10;
            spheres[num].center = CreatePoint(j * 80. - 80. + rand() % 15,
                                              i * 80. - 200. + rand() % 15,
                                              -700. - k * 100 + rand() % 15);
            spheres[num].ambient = CreateColor(std::min((i + j) * .15, 1.),
                                               std::min((j + k) * .15, 1.),
                                               std::max(1. - (k + i) * .15, 0.));
            spheres[num].diffuse = CreateColor(std::min((i + j) * .15, 1.),
                                               std::min((j + k) * .15, 1.),
                                               std::max(1. - (k + i) * .15, 0.));
            spheres[num].specular = CreateColor(1., 1., 1.);
            num++;
         }
      }
      k++;
   }

	return spheres;
}
コード例 #2
0
ファイル: driver.c プロジェクト: khongton/Raycaster
int main() {
   /* Debugging Code */ 
   //double minX = 0.05859357, maxX = 0.44921857;
   //double minY = 2.03125, maxY = 2.421875;
   //int width = 20, height = 20;

   double minX = -10, maxX = 10, minY = -7.5, maxY = 7.5;
   int width = 512, height = 384;
   Canvas canvas;
   InitCanvas(&canvas, minX, maxX, minY, maxY, width, height);

   Point eye = CreatePoint(0.0, 0.0, -14.0);
   Point blueSphere = CreatePoint(1.0, 1.0, 0.0);
   Point redSphere = CreatePoint(0.5, 1.5, -3.0);
   Point lightPoint = CreatePoint(-100.0, 100.0, -100.0);

   Color blue = CreateColor(0.0, 0.0, 1.0);
   Color red = CreateColor(1.0, 0.0, 0.0);
   Color ambient = CreateColor(1.0, 1.0, 1.0);
   Color lightColor = CreateColor(1.5, 1.5, 1.5);
   
   Finish largeFinish = CreateFinish(0.2, 0.4, 0.5, 0.05);
   Finish smallFinish = CreateFinish(0.4, 0.4, 0.5, 0.05);

   Light light = CreateLight(lightPoint, lightColor);
   Sphere spheres[2];
   spheres[0] = CreateSphere(blueSphere, 2.0, blue, largeFinish);
   spheres[1] = CreateSphere(redSphere, 0.5, red, smallFinish);
   
   castAllRays(&canvas, eye, spheres, ambient, light, 2);
   return 0;
}
コード例 #3
0
ファイル: test.cpp プロジェクト: eledot/libnge2
int main(int argc, char* argv[])
{
	//初始化NGE分为VIDEO,AUDIO,这里是只初始化VIDEO,如果初始化所有用INIT_VIDEO|INIT_AUDIO,或者INIT_ALL
	NGE_Init(INIT_VIDEO);
	//初始化按键处理btn_down是按下响应,后面是弹起时的响应,0是让nge处理home消息(直接退出),填1就是让PSP系统处理
	//home消息,通常填1正常退出(1.50版的自制程序需要填0)
	InitInput(btn_down,NULL,1);
	//最后一个参数是psp swizzle优化,通常填1
	p_bg = image_load("images/demo0.jpg",DISPLAY_PIXEL_FORMAT_8888,1);
	if(p_bg == NULL) {
		printf("can not open file\n");
	}
	p_logo = image_load("images/nge2logo.png",DISPLAY_PIXEL_FORMAT_4444,1);
	if(p_logo == NULL) {
		printf("can not open file\n");
	}
	//创建一个半透明的图片遮罩color
	logomask1 = CreateColor(255,255,255,128,p_logo->dtype);
	//随便创建一个图片遮罩color
	logomask2 = CreateColor(100,100,100,255,p_logo->dtype);

	while ( !game_quit )
	{
		ShowFps();
		InputProc();
		DrawScene();
	}
	image_free(p_bg);
	image_free(p_logo);
	NGE_Quit();
	return 0;
}
コード例 #4
0
ファイル: main.cpp プロジェクト: armerpaul/CUDA_RayTracer
PointLight* LightInit() {
   PointLight* temp = new PointLight();

   temp->ambient = CreateColor(0.2, 0.2, 0.2);
   temp->diffuse = CreateColor(0.6, 0.6, 0.6);
   temp->specular = CreateColor(0.9, 0.9, 0.9);

   //temp->position = CreatePoint(0, 200, 0);
   temp->position = CreatePoint(-1 * WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2, -1 * WINDOW_WIDTH / 2);

   return temp;
}
コード例 #5
0
ファイル: test.cpp プロジェクト: eledot/libnge2
int init() {
	//初始化NGE分为VIDEO,AUDIO,这里是只初始化VIDEO,如果初始化所有用INIT_VIDEO|INIT_AUDIO,或者INIT_ALL
	NGE_Init(INIT_VIDEO);
	//初始化按键处理btn_down是按下响应,后面是弹起时的响应,0是让nge处理home消息(直接退出),填1就是让PSP系统处理
	//home消息,通常填1正常退出(1.50版的自制程序需要填0)
#ifdef NGE_INPUT_BUTTON_SUPPORT
	InitInput(btn_down,NULL,1);
#endif
	//最后一个参数是psp swizzle优化,通常填1
	p_bg = image_load(RES_PATH("images/demo0.jpg"),DISPLAY_PIXEL_FORMAT_8888,1);
	if(p_bg == NULL) {
		nge_print("can not open file\n");
	}
	p_logo = image_load(RES_PATH("images/nge2logo.png"),DISPLAY_PIXEL_FORMAT_4444,1);
	if(p_logo == NULL) {
		nge_print("can not open file\n");
	}
	//创建一个半透明的图片遮罩color
	logomask1 = CreateColor(255,255,255,128,p_logo->dtype);
	//随便创建一个图片遮罩color
	logomask2 = CreateColor(100,100,100,255,p_logo->dtype);
	return 0;
}
コード例 #6
0
void MenuButton::Draw() {
	int heightOffset = 4; // without offset, font is a little to high

	// draw the background rectangle
	spriteBatch->DrawFilledRect(
		&CreateRect(x, y, width, height),
		bg
	);

	// draw the text
	spriteBatch->DrawString(
		font,
		text,
		StringDrawMode::Solid,
		fg,
		CreateColor(0, 0, 0, 255),
		width,
		&CreatePoint(x + width / 2 - spriteFont->GetMessageSize(0, text).x / 2, y + heightOffset + height / 2 - spriteFont->GetMessageSize(0, text).y / 2)
	);
}
コード例 #7
0
ファイル: main.cpp プロジェクト: armerpaul/CUDA_RayTracer
color_t RayTrace(Ray* r, Sphere* s, Plane* f, PointLight* l) {
   	color_t black = CreateColor(0, 0, 0);
   	double t, smallest;
   	Point p;
   	int i = 0, closestSphere = -1;

   	while (i < NUM_SPHERES) {
		t = SphereRayIntersection(s + i, r);

		if (t > 0 && (t < smallest || closestSphere < 0)) {
			smallest = t;
			closestSphere = i;
		}
      	i++;
   }

   if (closestSphere > -1) {
   		//fprintf(stderr, "r = %lf, g = %lf, b = %lf\n", s[closestSphere].color.r, s[closestSphere].color.g, s[closestSphere].color.b);
      	p = CreatePoint(r->direction.x * smallest, r->direction.y * smallest, r->direction.z * smallest);
      	return SphereShading(closestSphere, r, p, s, l);
   }
   
   return black;
}
コード例 #8
0
ファイル: nge_jpg.c プロジェクト: kimonline/libnge2
image_p image_load_jpg_buf(const char* mbuf,int bsize, int displaymode)
{
	image_p pimage = NULL;
	struct jpeg_decompress_struct	cinfo;
	struct jpeg_error_mgr jerr;
	uint8 *rawdata,*scanline, *p,*data = NULL;
	int	rawsize,texw,texh,width,height,bpb=2,size;
	int r,g,b,x;
	uint32* p32;
	uint16* p16;
	uint16 color16;
	uint32 color32;

	if(mbuf == NULL||bsize==0)
		return 0;
	memset(&cinfo,0,sizeof(struct jpeg_decompress_struct));
	memset(&jerr,0,sizeof(struct jpeg_error_mgr));

	rawsize = bsize;
	rawdata = (uint8*)mbuf;

	if (rawdata[6] != 'J' || rawdata[7] != 'F' || rawdata[8] != 'I' || rawdata[9] != 'F')
	{
		return 0;
	}

	cinfo.err = jpeg_std_error(&jerr);
	jpeg_create_decompress(&cinfo);

	jpeg_mem_src(&cinfo, rawdata, rawsize);

	jpeg_read_header(&cinfo, 1);

	jpeg_start_decompress(&cinfo);

	if(cinfo.output_components != 3 && cinfo.output_components != 4)
	{
		jpeg_destroy_decompress(&cinfo);
		return 0;
	}
	texw = roundpower2(cinfo.output_width);
	texh = roundpower2(cinfo.output_height);
	width = cinfo.output_width;
	height = cinfo.output_height;

	if(displaymode == DISPLAY_PIXEL_FORMAT_8888){
		bpb = 4;
	}
	size = texw * texh * bpb;
	data = (uint8*)malloc(size);
	memset(data,0,size);
	scanline = (uint8*)malloc(cinfo.output_width * 3);
	if(!scanline){
		jpeg_destroy_decompress(&cinfo);
		SAFE_FREE (data);
		return 0;
	}
	p32 = (uint32*)data;
	p16 = (uint16*) p32;

	while(cinfo.output_scanline < cinfo.output_height){
		jpeg_read_scanlines(&cinfo, &scanline, 1);
		p = (uint8*)scanline;
		for(x=0; x<(int)cinfo.output_width; x++){

			r = p[0];
			g = p[1];
			b = p[2];
			switch (displaymode){
				case DISPLAY_PIXEL_FORMAT_565:
					color16 = MAKE_RGBA_565(r,g,b,0xff);
					*(p16+x) = color16;
					break;
				case DISPLAY_PIXEL_FORMAT_5551:
					color16 = MAKE_RGBA_5551(r,g,b,0xff);
					*(p16+x) = color16;
					break;
				case DISPLAY_PIXEL_FORMAT_4444:
					color16 = MAKE_RGBA_4444(r,g,b,0xff);
					*(p16+x) = color16;
					break;
				case DISPLAY_PIXEL_FORMAT_8888:
					color32 = MAKE_RGBA_8888(r,g,b,0xff);
					*(p32+x) = color32;
					break;
			}
			p+=3;
		}
		p32 += texw;
		p16 += texw;
	}
	SAFE_FREE(scanline);
	jpeg_finish_decompress(&cinfo);
	jpeg_destroy_decompress(&cinfo);
	pimage = (image_p)malloc(sizeof(image_t));
	memset(pimage,0,sizeof(image_t));
	pimage->data = (uint8 *)data;
	pimage->w    = width;
	pimage->h    = height;
	pimage->texw = texw;
	pimage->texh = texh;
	pimage->bpb  = bpb;
	pimage->dtype = displaymode;
	pimage->rcentrex = pimage->w*1.0f/2;
	pimage->rcentrey = pimage->h*1.0f/2;
	pimage->mode = GET_PSM_COLOR_MODE(displaymode);
	pimage->mask = CreateColor(255,255,255,255,displaymode);
	pimage->texid = image_tid++;
	return pimage;
}
コード例 #9
0
ファイル: main.c プロジェクト: alexarse/FrameBuffer
int main()
{
	eosFrameBuffer fb;
	if(eosFrameBuffer_Open(&fb)) {
		return 0;
	}

	CFrameBuffer bf = CreateFrameBuffer(1366, 768);

	struct timeval start, end;
 
    	long mtime, seconds, useconds;    
 
    	gettimeofday(&start, NULL);
 
	
	// Draw background rectangle.
	CRect bg_rect = CreateRect(100, 100, 200, 200);
	CColor bg_color = CreateColor(240, 0, 0);
	DrawRectangle(&bf, &bg_rect, &bg_color);

	// Draw rectangle contour.
	//CColor contour_color = CreateColor(0, 0, 0);
	//DrawRectangleContour(&bf, &bg_rect, &contour_color);

	// Draw diagonal line.
	//CPoint p0 = CPoint_Create(0, 499);
	//CPoint p1 = CPoint_Create(499, 0);
	//CColor p_color = CreateColor(255, 255, 0);
	//DrawLine(&bf, &p0, &p1, &p_color);

	// Draw char.
	CFont font = CreateFont("resources/test.myfont");
	//CPoint char_pos = CPoint_Create(300, 100);
	//CColor char_color = CreateColor(255, 255, 255);
	//DrawChar(&bf, &font, 'P', &char_pos, &char_color);

	// Draw text.
	CPoint str_pos = CPoint_Create(100, 200);
	CColor str_color = CreateColor(180, 180, 180);
	DrawString(&bf, &font, "Monster Truck", &str_pos, &str_color);

	// Draw text.
	CPoint str2_pos = CPoint_Create(100, 220);
	CColor str2_color = CreateColor(10, 180, 180);
	DrawString(&bf, &font, "Monster Truck", &str2_pos, &str2_color);

	// Get text width.
	//CString mst_str = CString_Create("Monster Truck");
	//printf("Monster Truck width : %d\n", GetStringXSize(&font, &mst_str));

	// Draw image resize.
	CImage image = CreateImageFromBitmap("resources/umbrella2.bmp");
	CPoint img_pos = CPoint_Create(300, 51);
	CSize img_size = CreateSize(500, 500);
	DrawImageResize(&bf, &image, &img_pos, &img_size);	

	eosFrameBuffer_Draw(&fb);
	eosFrameBuffer_DrawBackBuffer(&fb, &bf);
    	
	gettimeofday(&end, NULL);
    	seconds  = end.tv_sec  - start.tv_sec;
    	useconds = end.tv_usec - start.tv_usec;
    	mtime = seconds + useconds;
   	printf("Elapsed time: %d ms\n", mtime / 1000);

	gettimeofday(&start, NULL);
	
	DrawRectangle(&bf, &bg_rect, &bg_color);
	DrawString(&bf, &font, "Monster Truck", &str_pos, &str_color);
	DrawString(&bf, &font, "Monster Truck", &str2_pos, &str2_color);
	DrawImageResize(&bf, &image, &img_pos, &img_size);
	eosFrameBuffer_DrawBackBuffer(&fb, &bf);

	gettimeofday(&end, NULL);
	seconds  = end.tv_sec  - start.tv_sec;
        useconds = end.tv_usec - start.tv_usec;
        mtime = seconds + useconds;
        printf("Elapsed time: %d ms\n", mtime / 1000);

	eosFrameBuffer_Close(&fb);
	//printf("FIX:\n");
	//printf("FB len         : %d\n", m_FixInfo.smem_len);
	//printf("FB type        : %d\n", m_FixInfo.type);
	//printf("FB type aux    : %d\n", m_FixInfo.type_aux);
	//printf("FB visual      : %d\n", m_FixInfo.visual);
	//printf("FB xpanstep    : %d\n", m_FixInfo.xpanstep);
	//printf("FB ypanstep    : %d\n", m_FixInfo.ypanstep);
	//printf("FB ywrapstep   : %d\n", m_FixInfo.ywrapstep);
	//printf("FB line_length : %d\n", m_FixInfo.line_length);

	//printf("VAR:\n");
	//printf("Res            : %d %d\n", m_VarInfo.xres, m_VarInfo.yres);
	//printf("Res virtual    : %d %d\n", m_VarInfo.xres_virtual, m_VarInfo.yres_virtual);
	//printf("Offset         : %d %d\n", m_VarInfo.xoffset, m_VarInfo.yoffset);
	//printf("bits_per_pixel : %d\n", m_VarInfo.bits_per_pixel);
	//printf("grayscale      : %d\n", m_VarInfo.grayscale);
	return 0;
}
コード例 #10
0
ファイル: line-edit.cpp プロジェクト: quequotion/higan-qq
void pLineEdit::setForegroundColor(Color color) {
  GdkColor gdkColor = CreateColor(color.red, color.green, color.blue);
  gtk_widget_modify_text(gtkWidget, GTK_STATE_NORMAL, &gdkColor);
}
コード例 #11
0
ファイル: nge_bmp.c プロジェクト: doorxp/libnge2
image_p image_load_bmp_buf(const char* mbuf,int bsize, int displaymode)
{
	image_p pimage = NULL;
	uint8_t *pdata,*data,*line;
	int dsize,w,h,texw,texh,bpb,size,x,y,done = 0;
	uint32_t* p32;
	uint16_t* p16;
	uint16_t color16;
	uint32_t color32;
	PBITMAPFILEHEADER pbfh = (PBITMAPFILEHEADER)mbuf;
	PBITMAPINFOHEADER pbih;

	if(pbfh->bfType !=0x4d42){
		nge_print("not bmp file\n");
		return 0;
	}
	pbih = (PBITMAPINFOHEADER)(mbuf+sizeof(BITMAPFILEHEADER));
	dsize = sizeof(BITMAPFILEHEADER)+pbih->biSize;
	pdata =  (uint8_t*)mbuf+dsize;
	w = pbih->biWidth;
	h = pbih->biHeight;
	texw = roundpower2(w);
	texh = roundpower2(h);
	bpb  = 4;
	if(displaymode != DISPLAY_PIXEL_FORMAT_8888){
		bpb = 2;
	}
	//int biSizeImage = ((((pbih->biWidth * pbih->biBitCount) + 31) & ~31) / 8) * pbih->biHeight;
	size = texw * texh * bpb;
	data = (uint8_t*)malloc(size);
	memset(data,0,size);
	p32 = (uint32_t*)data;
	p16 = (uint16_t*) p32;
	line = NULL;
	if(pbih->biBitCount == 24){
		for (y = h;y>0;y--){
			line = pdata+(y-1)*w*3;
			for (x=0;x<w;x++){
				switch(displaymode)
				{
				case DISPLAY_PIXEL_FORMAT_8888:
					color32 = MAKE_RGBA_8888(line[2],line[1],line[0],0xff);
					*(p32+x) = color32;
					break;
				case DISPLAY_PIXEL_FORMAT_565:
					color16 = MAKE_RGBA_565(line[2],line[1],line[0],0xff);
					*(p16+x) = color16;
					break;
				case DISPLAY_PIXEL_FORMAT_5551:
					color16 = MAKE_RGBA_5551(line[2],line[1],line[0],0xff);
					*(p16+x) = color16;
					break;
				case DISPLAY_PIXEL_FORMAT_4444:
					color16 = MAKE_RGBA_4444(line[2],line[1],line[0],0xff);
					*(p16+x) = color16;
					break;
				}
				line+=3;
			}
			p32 += texw;
			p16 += texw;
		}
		done = 1;
	}
	else if(pbih->biBitCount == 32){
		for (y = h;y>0;y--){
			line = pdata+(y-1)*w*4;
			for (x=0;x<w;x++){
				switch(displaymode)
				{
				case DISPLAY_PIXEL_FORMAT_8888:
					color32 = MAKE_RGBA_8888(line[2],line[1],line[0],0xff);
					*(p32+x) = color32;
					break;
				case DISPLAY_PIXEL_FORMAT_565:
					color16 = MAKE_RGBA_565(line[2],line[1],line[0],0xff);
					*(p16+x) = color16;
					break;
				case DISPLAY_PIXEL_FORMAT_5551:
					color16 = MAKE_RGBA_5551(line[2],line[1],line[0],0xff);
					*(p16+x) = color16;
					break;
				case DISPLAY_PIXEL_FORMAT_4444:
					color16 = MAKE_RGBA_4444(line[2],line[1],line[0],0xff);
					*(p16+x) = color16;
					break;
				}
				line+=4;
			}
			p32 += texw;
			p16 += texw;
		}
		done = 1;
	}

	if (done){
		pimage = (image_p)malloc(sizeof(image_t));
		memset(pimage,0,sizeof(image_t));
		pimage->data = (uint8_t *)data;
		pimage->w    = w;
		pimage->h    = h;
		pimage->texw = texw;
		pimage->texh = texh;
		pimage->bpb  = bpb;
		pimage->dtype = displaymode;
		pimage->rcentrex = pimage->w*1.0f/2;
		pimage->rcentrey = pimage->h*1.0f/2;
		pimage->mode = GET_PSM_COLOR_MODE(displaymode);
		pimage->mask = CreateColor(255,255,255,255,displaymode);
		pimage->texid = image_tid++;
	}
	return pimage;
}
コード例 #12
0
// AUTHOR: Jacob Deichert
// GROUP: Database/GUI Login
// DATE: 
#include "MenuButton.h"

SDL_Color MenuButton::BUTTON_BG_DEFAULT_COLOR = CreateColor(24, 24, 24, 255);
SDL_Color MenuButton::BUTTON_BG_DEFAULT_HOVER_COLOR = CreateColor(34, 34, 34, 255);
SDL_Color MenuButton::BUTTON_FG_DEFAULT_COLOR = CreateColor(3, 138, 206, 255);

MenuButton::MenuButton(int _x, int _y, int _width, int _height, int _id, std::string _name, std::string _text, int _font) {
	x = _x;
	y = _y;
	width = _width;
	height = _height;
	text = _text;
	font = _font;

	id = _id;
	name = _name;

	onLeftClickCallbackOwner = NULL;
	OnLeftClickEvent = NULL;

	onMouseEnterCallbackOwner = NULL;
	OnMouseEnterEvent = NULL;

	onMouseExitCallbackOwner = NULL;
	OnMouseExitEvent = NULL;

	currentlyContainsMouse = false;
	previouslyContainsMouse = false;