Användarprofil

Uppgifter
Användarnamn
Email
Besök -
Hemsida Ingen
Plats (stad)
Senaste besök 01:00 - 1:a Januari 1970
Poster i forumet
Varningar
Grupp
Medlem sedan 01:00 - 1:a Januari 1970
Artiklar och filer
Den här användaren har inga artiklar eller filer

Avatar


Presentation av

Den här användaren har inte skapat någon personlig presentation.

Senaste inläggen i forumet

DirectX hjälp
Jag försöker lära mig lite DirectX. Jag håller på med en tutorial från: http://www.two-kings.de/tutorials/dxgraphics/

Jag har modifierat om koden så att man inte behöver göra alla de där valen, utan bara behöver trycka på: Start eller cancel.

Nu till problemet... Jag har börjat att försöka göra trianglar och sånt... Koden blir kompilerad och allt verkar stå rätt till, men triangeln och kvadraten syns inte! Jag tror felet ligger i main.cpp:


//includes
#include "main.h"

//globals

CApplication g_App;

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
    MSG Message;

    LPDIRECT3DVERTEXBUFFER9 pTriangleVB = NULL;
    LPDIRECT3DVERTEXBUFFER9 pQuadVB = NULL;
    VOID* pData;

    D3DVERTEX aTriangle[] = {{-2.0f, 1.0f,10.0f,0xffff0000},
                            {-3.0f,-1.0f,10.0f,0xff00ff00},
                            {-1.0f,-1.0f,10.0f,0xff0000ff}};

    D3DVERTEX aQuad[] = {{1.0f,-1.0f,10.0f,0xffffff00},
                        {3.0f,-1.0f,10.0f,0xffffff00},
                        {1.0f, 1.0f,10.0f,0xffffff00},
                        {3.0f, 1.0f,10.0f,0xffffff00}};


    while(g_App.GetWindowStatus())
    {
        if(GetMessage(&Message, NULL, 0, 0))
        {
            if(!IsDialogMessage(g_App.GetWindowHandle(), &Message))
            {
                TranslateMessage(&Message);
                DispatchMessage(&Message);
            }
        }
    }

    if(!g_App.GetD3DStatus()) return Message.wParam;

    g_App.GetDevice()->CreateVertexBuffer(sizeof(aTriangle),
D3DUSAGE_WRITEONLY,
D3DFVF_CUSTOMVERTEX,
D3DPOOL_MANAGED,
&pTriangleVB,
NULL);

    g_App.GetDevice()->CreateVertexBuffer(sizeof(aQuad),
D3DUSAGE_WRITEONLY,
D3DFVF_CUSTOMVERTEX,
D3DPOOL_MANAGED,
&pQuadVB,
NULL);

    pTriangleVB->Lock(0,sizeof(pData),(void**)&pData,0);
    memcpy(pData,aTriangle,sizeof(aTriangle));
    pTriangleVB->Unlock();

    pQuadVB->Lock(0,sizeof(pData),(void**)&pData,0);
    memcpy(pData,aQuad,sizeof(aQuad));
    pQuadVB->Unlock();

    while(g_App.GetD3DStatus())
    {
        if(PeekMessage(&Message, NULL, 0, 0, PM_REMOVE))
        {
            TranslateMessage(&Message);
            DispatchMessage(&Message);
        }

        if(g_App.CheckDevice())
        {
            g_App.GetDevice()->Clear(0,
                                     NULL,
                                     D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
                                     D3DCOLOR_XRGB(0,0,0),
                                     1.0f,
                                     0);

            g_App.GetDevice()->BeginScene();

            g_App.GetDevice()->SetStreamSource(0, pTriangleVB, 0, sizeof(D3DVERTEX));
            g_App.GetDevice()->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);

            g_App.GetDevice()->SetStreamSource(0, pQuadVB, 0, sizeof(D3DVERTEX));
            g_App.GetDevice()->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2);

            g_App.GetDevice()->EndScene();

            g_App.GetDevice()->Present(NULL,NULL,NULL,NULL);
        }
    }

    return 0;
}



Uppskattar om någon kunnig kanske vet vad felet är... Det är inte säkert att felet ligger här, det är bara vad jag tror...

Postad 09:54 - 26:e Maj 2006
Linker fel?
Funkade inget vidare :/

Postad 19:54 - 15:e Maj 2006
Ubuntu
Det fungerade inte heller, den stannade när den laddade...

Kan det bero på att jag läser skivan med min DVD brännare? Brända skivor verkar inte fungera på vanliga CD läsaren så jag använder brännaren...

Postad 15:50 - 15:e Maj 2006
Linker fel?
------ Build started: Project: Lost Island(Project Name), Configuration: Debug Win32 ------
Compiling...
main.cpp
Linking...
main.obj : error LNK2019: unresolved external symbol "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) referenced in function "int __cdecl InitWindow(char *,int,int,int)" (?InitWindow@@YAHPADHHH@Z)
D:\Documents and Settings\André Nyström\My Documents\Lost Island(Project Name)\VC++\Lost Island(Project Name)\Debug\Lost Island(Project Name).exe : fatal error LNK1120: 1 unresolved externals
Build log was saved at "file://d:\Documents and Settings\André Nyström\My Documents\Lost Island(Project Name)\VC++\Lost Island(Project Name)\Debug\BuildLog.htm"
Lost Island(Project Name) - 2 error(s), 0 warning(s)

======= Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped =======



Det händer när jag tar bort (WNDPROC), dvs inte så mycket...

Postad 15:47 - 15:e Maj 2006
Linker fel?

#ifndef __INITWINANDGL_H__
#define __INITWINANDGL_H__

// includes
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include "Vars.h"

// defines
#define WNDCLSNAME "LI"

// function define
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

// funtions
GLvoid ReSizeGLScene(GLsizei Width, GLsizei Height)
{
    if(Height==0)
    {
        Height = 1;
    }

    glViewport(0,0,Width,Height);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    gluPerspective(45.0f, (GLfloat)Width/(GLfloat)Height,0.1f, 1000.0f);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}

int InitGL(GLvoid)
{
    glShadeModel(GL_SMOOTH);

    glClearColor(0.0f,0.0f,0.0f,0.0f);

    glClearDepth(1.0f);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);

    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

    return TRUE;
}

GLvoid KillGL(GLvoid)
{
    ChangeDisplaySettings(NULL, 0);
    ShowCursor(true);

    if(hRC)
    {
        if(!wglMakeCurrent(NULL, NULL))
        {
            MessageBox(NULL, "Couldn't release the RC and DC!", "SHUTDOWN ERROR!", MB_OK|MB_ICONINFORMATION);
        }

        if(!wglDeleteContext(hRC))
        {
            MessageBox(NULL, "Couldn't release the rendering context!", "SHUTDOWN ERROR!", MB_OK|MB_ICONINFORMATION);
        }
        hRC=NULL;
    }

    if(hDC && !ReleaseDC(hWnd, hDC))
    {
        MessageBox(NULL, "Couldn't release the Device Context!", "SHUTDOWN ERROR!", MB_OK|MB_ICONINFORMATION);
        hDC = NULL;
    }

    if(hWnd && !DestroyWindow(hWnd))
    {
        MessageBox(NULL, "Couldn't destroy the hWnd!", "SHUTDOWN ERROR!", MB_OK|MB_ICONINFORMATION);
        hWnd=NULL;
    }

    if(!UnregisterClass(WNDCLSNAME, hInstance))
    {
        MessageBox(NULL, "Couldn't unregister class!", "SHUTDOWN ERROR!", MB_OK | MB_ICONINFORMATION);
        hInstance=NULL;
    }
}

BOOL InitWindow(char *Title, int Width, int Height, int Bits)
{
    GLuint        PixelFormat;

    WNDCLASS    WC;

    RECT    WindowRect;
    WindowRect.left=(long)0;
    WindowRect.right=(long)Width;
    WindowRect.top=(long)0;
    WindowRect.bottom=(long)Height;



    hInstance            = GetModuleHandle(NULL);
    WC.style            = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
    WC.lpfnWndProc        = (WNDPROC)WndProc;
    WC.cbClsExtra        = 0;
    WC.cbWndExtra        = 0;
    WC.hInstance        = hInstance;
    WC.hIcon            = LoadIcon(NULL, IDI_WINLOGO);
    WC.hCursor            = LoadCursor(NULL, IDC_ARROW);
    WC.hbrBackground    = NULL;
    WC.lpszMenuName        = NULL;
    WC.lpszClassName    = WNDCLSNAME;

    if(!RegisterClass(&WC))
    {
        MessageBox(NULL, "Couldn't register WC class!", "", MB_OK | MB_ICONINFORMATION);
        return FALSE;
    }

    DEVMODE dmScreenSettings;
    memset(&dmScreenSettings, 0, sizeof(dmScreenSettings));
    dmScreenSettings.dmSize = sizeof(dmScreenSettings);
    dmScreenSettings.dmPelsWidth = Width;
    dmScreenSettings.dmPelsHeight = Height;
    dmScreenSettings.dmBitsPerPel = Bits;
    dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;

    if(ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN)!= DISP_CHANGE_SUCCESSFUL)
    {
        MessageBox(NULL, "Fullscreen is not supported by your video card", "ERROR!", MB_OK|MB_ICONINFORMATION);
        return FALSE;
    }

    AdjustWindowRectEx(&WindowRect, WS_POPUP, FALSE, WS_EX_APPWINDOW);

    if(!(hWnd=CreateWindowEx(WS_EX_APPWINDOW,
                             WNDCLSNAME,
                             Title,
                             WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_POPUP,
                             0,
                             0,
                             WindowRect.right-WindowRect.left,
                             WindowRect.bottom-WindowRect.top,
                             NULL,
                             NULL,
                             hInstance,
                             NULL)))
    {
        KillGL();
        MessageBox(NULL, "Couldn't Create Window!", "ERROR!", MB_OK | MB_ICONINFORMATION);
        return FALSE;
    }

    static PIXELFORMATDESCRIPTOR pfd=
    {
        sizeof(PIXELFORMATDESCRIPTOR),
        1,
        PFD_DRAW_TO_WINDOW |
        PFD_SUPPORT_OPENGL |
        PFD_DOUBLEBUFFER,
        PFD_TYPE_RGBA,
        Bits,
        0,0,0,0,0,0,
        0,
        0,
        0,
        0,0,0,0,
        16,
        0,
        0,
        PFD_MAIN_PLANE,
        0,
        0,0,0
    };

    if(!(hDC=GetDC(hWnd)))
    {
        KillGL();
        MessageBox(NULL, "Couldn't Create The DC", "ERROR!", MB_OK | MB_ICONINFORMATION);
        return FALSE;
    }

    if(!(PixelFormat=ChoosePixelFormat(hDC, &pfd)))
    {
        KillGL();
        MessageBox(NULL, "Couldn't Choose PixelFormat", "ERROR!", MB_OK | MB_ICONINFORMATION);
        return FALSE;
    }

    if(!(SetPixelFormat(hDC, PixelFormat, &pfd)))
    {
        KillGL();
        MessageBox(NULL, "Couldn't Set PixelFormat", "ERROR!", MB_OK | MB_ICONINFORMATION);
        return FALSE;
    }

    if(!wglCreateContext(hDC))
    {
        KillGL();
        MessageBox(NULL, "Couldn't Create The A GL RC", "ERROR!", MB_OK | MB_ICONINFORMATION);
        return FALSE;
    }

    if(!wglMakeCurrent(hDC, hRC))
    {
        KillGL();
        MessageBox(NULL, "Couldn't Activate GL RC", "ERROR!", MB_OK | MB_ICONINFORMATION);
        return FALSE;
    }

    ShowWindow(hWnd, SW_SHOW);
    SetForegroundWindow(hWnd);
    SetFocus(hWnd);
    ReSizeGLScene(Width, Height);

    if(!InitGL())
    {
        KillGL();
        MessageBox(NULL, "Couldn't Init GL!", "ERROR!", MB_OK | MB_ICONINFORMATION);
        return FALSE;
    }

    return TRUE;
}

#endif


main.cpp kanske man ska visa också:


// includes
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include "InitWinAndGL.h"
#include "DrawScene.h"
#include "Vars.h"

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
    MSG Msg;
    BOOL Done=FALSE;

    if(!InitWindow("LI" ,800, 600, 16))return 0;

    while(!Done)
    {
        if(PeekMessage(&Msg, NULL, 0,0, PM_REMOVE))
        {
            if(Msg.message==WM_QUIT)
            {
                Done=TRUE;
            }
            else
            {
                TranslateMessage(&Msg);
                DispatchMessage(&Msg);
            }
        }
        else
        {
            if(Active)
            {
                DrawScene();
                SwapBuffers(hDC);
            }
        }
    }
    KillGL();
    return (Msg.wParam);
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, LPARAM lParam, WPARAM wParam)
{
    switch(uMsg)
    {
    case WM_ACTIVATE:
        {
            if(!HIWORD(wParam))
            {
                Active = TRUE;
            }
            else
            {
                Active = FALSE;
            }
            return 0;

        }

    case WM_SYSCOMMAND:
        {
            switch(wParam)
            {
            case SC_SCREENSAVE:
            case SC_MONITORPOWER:
                return 0;
            }
            break;
        }

    case WM_CLOSE:
        {
            PostQuitMessage(0);
            return 0;
        }

    case WM_KEYDOWN:
        {
            Keys[wParam] = TRUE;
            return 0;
        }

    case WM_KEYUP:
        {
            Keys[wParam] = FALSE;
            return 0;
        }

    case WM_SIZE:
        {
            ReSizeGLScene(LOWORD(lParam), HIWORD(lParam));
            return 0;
        }
    }
    return DefWindowProc(hWnd, uMsg, wParam, lParam);
}


Postad 14:55 - 15:e Maj 2006

Skicka meddelande
Läs s blog