?
Solved

Texture Mapping source code...

Posted on 1998-07-01
5
Medium Priority
?
270 Views
Last Modified: 2013-12-03
I want to get source code of texture mapping in Win32.

<requirement>
source code have to be programed in C.
mapping speed have to be fast(optimized code).
program have to run in Win32 API.
example must be included..

thanks.
0
Comment
Question by:jhjeon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 7

Expert Comment

by:BlackMan
ID: 1409251
I don't know if this is what you want:

/*==========================================================================
 *
 *  Copyright (C) 1995, 1996 Microsoft Corporation. All Rights Reserved.
 *
 *  File: tex1.c
 *
 ***************************************************************************/
 
/*
 * A texture mapping example using a cylindrical mapping.
 */
 
#include "rmdemo.h"
 
BOOL
BuildScene(LPDIRECT3DRMDEVICE dev, LPDIRECT3DRMVIEWPORT view,
   LPDIRECT3DRMFRAME scene, LPDIRECT3DRMFRAME camera)
{
    LPDIRECT3DRMMESH mesh = NULL;
    LPDIRECT3DRMMESHBUILDER builder = NULL;
    LPDIRECT3DRMFRAME frame = NULL;
    LPDIRECT3DRMTEXTURE tex = NULL;
    LPDIRECT3DRMMATERIAL mat = NULL;
    LPDIRECT3DRMWRAP wrap = NULL;
    LPDIRECT3DRMLIGHT l1 = NULL;
    LPDIRECT3DRMLIGHT l2 = NULL;
    D3DRMBOX box;
    D3DVALUE miny, maxy;
    D3DVALUE height;
    HRESULT rval;
 
    dev;
    view;
    camera;
 
    if (FAILED(lpD3DRM->lpVtbl->CreateLightRGB(lpD3DRM, D3DRMLIGHT_AMBIENT, D3DVAL(0.2),
                                  D3DVAL(0.2), D3DVAL(0.2), &l1)))
  goto generic_error;
    if (FAILED(scene->lpVtbl->AddLight(scene, l1)))
goto generic_error;
    if (FAILED(lpD3DRM->lpVtbl->CreateFrame(lpD3DRM, scene, &frame)))
goto generic_error;
    if (FAILED(frame->lpVtbl->SetOrientation(frame, scene, -D3DVAL(1), -D3DVAL(1),
                                  D3DVAL(1), D3DVAL(0), D3DVAL(1), D3DVAL(0))))
  goto generic_error;
    if (FAILED(lpD3DRM->lpVtbl->CreateLightRGB(lpD3DRM, D3DRMLIGHT_DIRECTIONAL, D3DVAL(1),
                                  D3DVAL(1), D3DVAL(1), &l2)))
  goto generic_error;
    if (FAILED(frame->lpVtbl->AddLight(frame, l2)))
goto generic_error;
    RELEASE(frame);
 
    if (FAILED(lpD3DRM->lpVtbl->CreateFrame(lpD3DRM, scene, &frame)))
goto generic_error;
    if (FAILED(frame->lpVtbl->SetPosition(frame, scene, D3DVAL(0), D3DVAL(0), D3DVAL(15))))
goto generic_error;
    if (FAILED(frame->lpVtbl->SetRotation(frame, scene, D3DVAL(1.1), D3DVAL(0.3),  
                               D3DVAL(0.0), D3DVAL(0.04))))
       goto generic_error;
 
    if (FAILED(lpD3DRM->lpVtbl->CreateMeshBuilder(lpD3DRM, &builder)))
goto generic_error;
    rval = builder->lpVtbl->Load(builder, "sphere4.x", NULL,
    D3DRMLOAD_FROMFILE, NULL, NULL);
    if (rval != D3DRM_OK) {
        Msg("Failed to load sphere4.x.\n%s", D3DRMErrorToString(rval));
goto ret_with_error;
    }
 
    rval = lpD3DRM->lpVtbl->LoadTexture(lpD3DRM, "tex7.ppm", &tex);
    if (rval != D3DRM_OK) {
        Msg("Failed to load tex7.ppm.\n%s", D3DRMErrorToString(rval));
goto ret_with_error;
    }
    if (FAILED(lpD3DRM->lpVtbl->CreateMaterial(lpD3DRM, D3DVAL(10.0), &mat)))
goto generic_error;
 
    if (FAILED(builder->lpVtbl->SetTexture(builder, tex)))
goto generic_error;
    if (FAILED(builder->lpVtbl->SetMaterial(builder, mat)))
goto generic_error;
    if (FAILED(builder->lpVtbl->SetColorRGB(builder, D3DVAL(1.0), D3DVAL(1.0), D3DVAL(1.0))))
goto generic_error;
 
    if (FAILED(builder->lpVtbl->CreateMesh(builder, &mesh)))
goto generic_error;
    RELEASE(builder);
 
    if (FAILED(mesh->lpVtbl->GetBox(mesh, &box)))
goto generic_error;
    maxy = box.max.y;
    miny = box.min.y;
    height = maxy - miny;
 
    if (FAILED(lpD3DRM->lpVtbl->CreateWrap(lpD3DRM, D3DRMWRAP_CYLINDER, NULL, D3DVAL(0.0),
                              D3DVAL(0.0), D3DVAL(0.0), D3DVAL(0.0),
                              D3DVAL(1.0), D3DVAL(0.0), D3DVAL(0.0),
                              D3DVAL(0.0), D3DVAL(1.0), D3DVAL(0.0),
                              D3DDivide(miny, height), D3DVAL(1.0),
                              D3DDivide(-D3DVAL(1.0), height), &wrap)))
      goto generic_error;
 
    if (FAILED(wrap->lpVtbl->Apply(wrap, (LPDIRECT3DRMOBJECT)mesh)))
goto generic_error;
    if (FAILED(frame->lpVtbl->AddVisual(frame, (LPDIRECT3DRMVISUAL) mesh)))
goto generic_error;
 
    RELEASE(frame);
    RELEASE(wrap);
    RELEASE(mesh);
    RELEASE(tex);
    RELEASE(mat);
    RELEASE(l1);
    RELEASE(l2);
    return TRUE;
generic_error:
    Msg("A failure occurred while building the scene.\n");
ret_with_error:
    RELEASE(mesh);
    RELEASE(builder);
    RELEASE(frame);
    RELEASE(tex);
    RELEASE(mat);
    RELEASE(wrap);
    RELEASE(l1);
    RELEASE(l2);
    return FALSE;
}
 
void
OverrideDefaults(Defaults* defaults)
{
    defaults->bConstRenderQuality = TRUE;
    lstrcpy(defaults->Name, "Texture Mapping Direct3DRM Example");
}

 

0
 

Author Comment

by:jhjeon
ID: 1409252
BlackMan, thanks for your comment
but I don't want Direct3d, OpenGL, Guild etc..
I do not need source code with 3D library ..

I want raw algorithm of texture mapping .
 
0
 
LVL 2

Expert Comment

by:kinkajou
ID: 1409253
True texture mapping onto a polygonal object? As opposed to just bitmapping.
0
 
LVL 4

Accepted Solution

by:
nils pipenbrinck earned 900 total points
ID: 1409254
These two URL's are what you need.

They explain in detail how to write a fast affinite texture mapper (for triangles and n-gons). complete with example sourcecode (for 32-bit dos, but the texturemapper itself works fine under win32).

ftp://us.hornet.org/pub/demos/code/3d/trifill/texmap/fatmap.txt

ftp://us.hornet.org/pub/demos/code/3d/trifill/texmap/fatmap2.zip

Have fun,

  Nils Pipenbrinck
0
 

Author Comment

by:jhjeon
ID: 1409255
nils pipenbrinck, Thanks for your answer!

have a good day !!

0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question