Example #1
0
void renderStudentScene(S_Renderer *pRenderer, S_Model *pModel)
{
	/* test existence frame bufferu a modelu */
	IZG_ASSERT(pModel && pRenderer);

	/* nastavit projekcni matici */
	trProjectionPerspective(pRenderer->camera_dist, pRenderer->frame_w, pRenderer->frame_h);

	/* vycistit model matici */
	trLoadIdentity();

	/* nejprve nastavime posuv cele sceny od/ke kamere */
	trTranslate(0.0, 0.0, pRenderer->scene_move_z);

	/* nejprve nastavime posuv cele sceny v rovine XY */
	trTranslate(pRenderer->scene_move_x, pRenderer->scene_move_y, 0.0);

	/* natoceni cele sceny - jen ve dvou smerech - mys je jen 2D... :( */
	trRotateX(pRenderer->scene_rot_x);
	trRotateY(pRenderer->scene_rot_y);

	/* nastavime material */
	/*
	renMatAmbient(pRenderer, &MAT_RED_AMBIENT);
	renMatDiffuse(pRenderer, &MAT_RED_DIFFUSE);
	renMatSpecular(pRenderer, &MAT_RED_SPECULAR);
	//*/
	renMatAmbient(pRenderer, &MAT_WHITE_AMBIENT);
	renMatDiffuse(pRenderer, &MAT_WHITE_DIFFUSE);
	renMatSpecular(pRenderer, &MAT_WHITE_SPECULAR);

	/* a vykreslime nas model (ve vychozim stavu kreslime pouze snimek 0) */
	renderModel(pRenderer, pModel, myStudFrame);
}
Example #2
0
File: main.c Project: pavelfryz/fit
 void renderScene()
{
    /* test existence frame bufferu a modelu */
    IZG_ASSERT(polymodel && renderer);

    /* nastavit projekcni matici */
    trProjectionPerspective(renderer->camera_dist, renderer->frame_w, renderer->frame_h);

    /* vycistit model matici */
    trLoadIdentity();

    /* nejprve nastavime posuv cele sceny od/ke kamere */
    trTranslate(0.0, 0.0, renderer->scene_move_z);

    /* natoceni cele sceny - jen ve dvou smerech - mys je jen 2D... :( */
    trRotateX(renderer->scene_rot_x);
    trRotateY(renderer->scene_rot_y);

    /* nastavime material */
    renMatAmbient(renderer, &MAT_RED_AMBIENT);
    renMatDiffuse(renderer, &MAT_RED_DIFFUSE);
    renMatSpecular(renderer, &MAT_RED_SPECULAR);

    /* a vykreslime nas model */
    renderModel();
}
Example #3
0
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{

	//HDC hdc;
	//PAINTSTRUCT ps;
	static RECT rect;
	//HBRUSH NewBrush;

	switch (message)
	{
	case WM_CREATE:
		//PlaySound(TEXT("hellowin.wav"), NULL, SND_FILENAME | SND_ASYNC);
		//do something
		//各种initialize
		trClearColor(0.0, 0.0, 0.0, 1.0);
		return 0;
	case WM_SIZE:
		GetWindowRect(hwnd,&rect);
		//设置相机
		trViewport(0, 0, (TRint)(rect.right - rect.left), (TRint)(rect.bottom - rect.top));//重置当前视口
		trMatrixMode(TR_PROJECTION);//选择投影矩阵
		trLoadIdentity();//重置选择好的投影矩阵


	case WM_PAINT:
		/*hdc = BeginPaint(hwnd, &ps);
		GetClientRect(hwnd, &rect);
		DrawText(hdc, TEXT("Hello, Windows 98!"), -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
		EndPaint(hwnd, &ps);*/
		//开始绘图
		trClear(TR_COLOR_BUFFER_BIT | TR_DEPTH_BUFFER_BIT);
		trBegin(TR_POINTS);
		trVertex4d(0.5,0.5,0.0,1.0);
		trEnd();
		WinFlush(hwnd, frontBuffer, rect.right - rect.left, rect.bottom - rect.top);
		return 0;
	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;
	}
	return DefWindowProc(hwnd, message, wParam, lParam);
}
Example #4
0
void renderStudentScene(S_Renderer *pRenderer, S_Model *pModel)
{
    S_StudentRenderer * renderer = (S_StudentRenderer *) pRenderer;
    S_Frag * frag;
    S_RGBA resultColor;
    int x = 0;
    int y = 0;
    int i = 0;
    double transparency = 0.0;

    /* test existence frame bufferu a modelu */
    IZG_ASSERT(pModel && pRenderer);

    /* nastavit projekcni matici */
    trProjectionPerspective(pRenderer->camera_dist, pRenderer->frame_w, pRenderer->frame_h);

    /* vycistit model matici */
    trLoadIdentity();

    /* nejprve nastavime posuv cele sceny od/ke kamere */
    trTranslate(0.0, 0.0, pRenderer->scene_move_z);

    /* nejprve nastavime posuv cele sceny v rovine XY */
    trTranslate(pRenderer->scene_move_x, pRenderer->scene_move_y, 0.0);

    /* natoceni cele sceny - jen ve dvou smerech - mys je jen 2D... :( */
    trRotateX(pRenderer->scene_rot_x);
    trRotateY(pRenderer->scene_rot_y);

    ///////////////////////////////// cerveny kralik ///////////////////////////////////
    /* nastavime material */
    renMatAmbient(pRenderer, &MAT_RED_AMBIENT);
    renMatDiffuse(pRenderer, &MAT_RED_DIFFUSE);
    renMatSpecular(pRenderer, &MAT_RED_SPECULAR);

    /* nejprve nastavime posuv cele sceny v rovine XY */
    trTranslate(pRenderer->scene_move_x - 1.2, pRenderer->scene_move_y, 0.0);

    /* a vykreslime nas model */
    renderModel(pRenderer, pModel);

    ///////////////////////////////// zeleny kralik ///////////////////////////////////
    /* nastavime material */
    renMatAmbient(pRenderer, &MAT_STUD_AMBIENT);
    renMatDiffuse(pRenderer, &MAT_STUD_DIFFUSE);
    renMatSpecular(pRenderer, &MAT_STUD_SPECULAR);
	
    /* nejprve nastavime posuv cele sceny v rovine XY */
    trTranslate(pRenderer->scene_move_x + 2.4, pRenderer->scene_move_y, 0.0);

    /* a vykreslime nas model */
    renderModel(pRenderer, pModel);
    ///////////////////////////////////////////////////////////////////////////////////

    // vypocet barvy a jeji vykresleni
    for(x = 0; x < pRenderer->frame_h; x++)
    {
        for(y = 0; y < pRenderer->frame_w; y++)
        {
            // inicializace
            transparency = 1.0;
            resultColor.red = 0;
            resultColor.green = 0;
            resultColor.blue = 0;
            resultColor.alpha = 0;

            i = renderer->hBuffer[y * pRenderer->frame_w + x];
            if(i < 0) resultColor = COLOR_BLACK;

            // vypocet smichane barvy
            while(i >= 0)
            {
                frag = fragvecGetPtr(renderer->nBuffer, i);
                resultColor.blue += transparency * frag->color.blue;
                resultColor.red += transparency * frag->color.red;
                resultColor.green += transparency * frag->color.green;
                transparency *= (1.0 - (frag->color.alpha / 255.0));
                i = frag->next;
            }

            // vykresleni vypocteneho pixelu
            PIXEL(pRenderer, x, y) = resultColor;
        }
    }
}