Beispiel #1
0
int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    MSG			msg;
    WNDCLASSEX	wcex;
    HACCEL		hAccelTable;

    hInstance = hInst;

    wcex.cbSize = sizeof(WNDCLASSEX);

    wcex.style			= CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc	= (WNDPROC)WndProc;
    wcex.cbClsExtra		= 0;
    wcex.cbWndExtra		= 0;
    wcex.hInstance		= hInstance;
    wcex.hIcon			= LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
    wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground	= (HBRUSH)(COLOR_WINDOW+1);
    wcex.lpszMenuName	= (LPCSTR)IDR_MENU1;
    wcex.lpszClassName	= TITLE;
    wcex.hIconSm		= LoadIcon(wcex.hInstance, (LPCTSTR)IDI_ICON1);

    RegisterClassEx(&wcex);

    HWnd = CreateWindow(TITLE, TITLE, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                        50, 50, 400, 300, NULL, NULL, hInstance, NULL);
    if (HWnd == NULL)
        return FALSE;

    // Display the window
    ShowWindow(HWnd, nCmdShow);
    UpdateWindow(HWnd);

    ilInit();
    ilEnable(IL_ORIGIN_SET);
    ilEnable(IL_TYPE_SET);
    ilEnable(IL_FORMAT_SET);

    ilOriginFunc(IL_ORIGIN_LOWER_LEFT);
    ilTypeFunc(IL_UNSIGNED_BYTE);
    ilFormatFunc(IL_BGR);

    // Is there a file to load from the command-line?
    if (__argc > 1) {
        LoadImages(__argv[1]);
    }

    hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDR_MENU1);

    while (GetMessage(&msg, NULL, 0, 0)) {
        if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

    return msg.wParam;
}
Beispiel #2
0
void IMG_InitDevil()
{
	//initialize devIL
	ilInit();
	ilOriginFunc( IL_ORIGIN_UPPER_LEFT );
	ilEnable( IL_ORIGIN_SET );
	ilEnable( IL_TYPE_SET );
	ilTypeFunc( IL_UNSIGNED_BYTE );
}
Beispiel #3
0
GLubyte* OpenImageDevIL(const std::string& filename, unsigned int& w, unsigned int& h, unsigned int& d)
{
	static bool first = true;
	if(first) {
		first = false;

		// Init DevIL
		ilInit();

		// Set origin of image to upper left corner
		ilOriginFunc(IL_ORIGIN_UPPER_LEFT);
		ilEnable(IL_ORIGIN_SET);

		ilEnable(IL_TYPE_SET);
		ilTypeFunc(IL_UNSIGNED_BYTE);
	}

    // Generating a new texture
    ILuint ilTexture;
    ilGenImages(1, &ilTexture);
    ilBindImage(ilTexture);

    // Loading image
	if (!ilLoadImage(filename.c_str()))
		return false;

	w = ilGetInteger(IL_IMAGE_WIDTH);
	h = ilGetInteger(IL_IMAGE_HEIGHT);
	d = ilGetInteger(IL_IMAGE_BPP);
	
	if(d==4)
		ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);

    // Get the size of image
    const unsigned char* Pixels = ilGetData();

	GLubyte* img = new GLubyte[(size_t)(w) * (size_t)(h) * (size_t)(d)];
	memcpy(img, Pixels, (size_t)(w) * (size_t)(h) * (size_t)(d));
	
    // Remove the texture
    ilBindImage(0);
    ilDeleteImages(1, &ilTexture);
	
	return img;
	//return NULL;
}
Beispiel #4
0
void ILAPIENTRY ilSetInteger(ILenum Mode, ILint Param)
{
    switch (Mode)
    {
    // Integer values
    case IL_FORMAT_MODE:
        ilFormatFunc(Param);
        return;
    case IL_KEEP_DXTC_DATA:
        if (Param == IL_FALSE || Param == IL_TRUE) {
            ilStates[ilCurrentPos].ilKeepDxtcData = Param;
            return;
        }
        break;
    case IL_MAX_QUANT_INDICES:
        if (Param >= 2 && Param <= 256) {
            ilStates[ilCurrentPos].ilQuantMaxIndexs = Param;
            return;
        }
        break;
    case IL_NEU_QUANT_SAMPLE:
        if (Param >= 1 && Param <= 30) {
            ilStates[ilCurrentPos].ilNeuSample = Param;
            return;
        }
        break;
    case IL_ORIGIN_MODE:
        ilOriginFunc(Param);
        return;
    case IL_QUANTIZATION_MODE:
        if (Param == IL_WU_QUANT || Param == IL_NEU_QUANT) {
            ilStates[ilCurrentPos].ilQuantMode = Param;
            return;
        }
        break;
    case IL_TYPE_MODE:
        ilTypeFunc(Param);
        return;

    // Image specific values
    case IL_IMAGE_DURATION:
        if (iCurImage == NULL) {
            ilSetError(IL_ILLEGAL_OPERATION);
            break;
        }
        iCurImage->Duration = Param;
        return;
    case IL_IMAGE_OFFX:
        if (iCurImage == NULL) {
            ilSetError(IL_ILLEGAL_OPERATION);
            break;
        }
        iCurImage->OffX = Param;
        return;
    case IL_IMAGE_OFFY:
        if (iCurImage == NULL) {
            ilSetError(IL_ILLEGAL_OPERATION);
            break;
        }
        iCurImage->OffY = Param;
        return;
    case IL_IMAGE_CUBEFLAGS:
        if (iCurImage == NULL) {
            ilSetError(IL_ILLEGAL_OPERATION);
            break;
        }
        iCurImage->CubeFlags = Param;
        break;

    // Format specific values
    case IL_BMP_RLE:
        if (Param == IL_FALSE || Param == IL_TRUE) {
            ilStates[ilCurrentPos].ilBmpRle = Param;
            return;
        }
        break;
    case IL_DXTC_FORMAT:
        if (Param >= IL_DXT1 || Param <= IL_DXT5 || Param == IL_DXT1A) {
            ilStates[ilCurrentPos].ilDxtcFormat = Param;
            return;
        }
        break;
    case IL_JPG_SAVE_FORMAT:
        if (Param == IL_JFIF || Param == IL_EXIF) {
            ilStates[ilCurrentPos].ilJpgFormat = Param;
            return;
        }
        break;
    case IL_JPG_QUALITY:
        if (Param >= 0 && Param <= 99) {
            ilStates[ilCurrentPos].ilJpgQuality = Param;
            return;
        }
        break;
    case IL_PNG_INTERLACE:
        if (Param == IL_FALSE || Param == IL_TRUE) {
            ilStates[ilCurrentPos].ilPngInterlace = Param;
            return;
        }
        break;
    case IL_PCD_PICNUM:
        if (Param >= 0 || Param <= 2) {
            ilStates[ilCurrentPos].ilPcdPicNum = Param;
            return;
        }
        break;
    case IL_PNG_ALPHA_INDEX:
        if (Param >= -1 || Param <= 255) {
            ilStates[ilCurrentPos].ilPngAlphaIndex=Param;
            return;
        }
        break;
    case IL_SGI_RLE:
        if (Param == IL_FALSE || Param == IL_TRUE) {
            ilStates[ilCurrentPos].ilSgiRle = Param;
            return;
        }
        break;
    case IL_TGA_CREATE_STAMP:
        if (Param == IL_FALSE || Param == IL_TRUE) {
            ilStates[ilCurrentPos].ilTgaCreateStamp = Param;
            return;
        }
        break;
    case IL_TGA_RLE:
        if (Param == IL_FALSE || Param == IL_TRUE) {
            ilStates[ilCurrentPos].ilTgaRle = Param;
            return;
        }
        break;
    case IL_VTF_COMP:
        if (Param == IL_DXT1 || Param == IL_DXT5 || Param == IL_DXT3 || Param == IL_DXT1A || Param == IL_DXT_NO_COMP) {
            ilStates[ilCurrentPos].ilVtfCompression = Param;
            return;
        }
        break;

    default:
        ilSetError(IL_INVALID_ENUM);
        return;
    }

    ilSetError(IL_INVALID_PARAM);  // Parameter not in valid bounds.
    return;
}