Ignore:
Timestamp:
Apr 4, 2012, 8:40:04 PM (10 years ago)
Author:
sam
Message:

build: major refactoring of the Win32 and Xbox project files; we now
link properly on the Xbox.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/tutorial/tut01.cpp

    r1179 r1189  
    22// Lol Engine - Triangle tutorial
    33//
    4 // Copyright: (c) 2011 Sam Hocevar <sam@hocevar.net>
     4// Copyright: (c) 2012 Sam Hocevar <sam@hocevar.net>
    55//   This program is free software; you can redistribute it and/or
    66//   modify it under the terms of the Do What The Fuck You Want To
     
    5050        {
    5151            m_shader = Shader::Create(
     52#if !defined __CELLOS_LV2__ && !defined _XBOX
    5253                "#version 120\n"
    5354                "attribute vec2 coord2d;"
     
    6162                "    gl_FragColor[1] = 0.0;"
    6263                "    gl_FragColor[2] = 1.0;"
    63                 "}");
     64                "}"
     65#else
     66                "void main(float2 coord2d : POSITION,"
     67                "          out float4 out_Position : POSITION) {"
     68                "    out_Position = float4(coord2d, 0.0, 1.0);"
     69                "}",
     70
     71                "void main(out float4 out_FragColor : COLOR) {"
     72                "    out_FragColor[0] = 0.0;"
     73                "    out_FragColor[0] = 0.0;"
     74                "    out_FragColor[0] = 1.0;"
     75                "}"
     76#endif
     77            );
    6478            m_attrib = m_shader->GetAttribLocation("coord2d");
    6579            m_ready = true;
    6680
    67 #if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__
     81#if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ && !defined _XBOX
    6882            /* Method 1: store vertex buffer on the GPU memory */
    6983            glGenBuffers(1, &m_vbo);
     
    7185            glBufferData(GL_ARRAY_BUFFER, sizeof(m_vertices), m_vertices,
    7286                         GL_STATIC_DRAW);
    73 #elif !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__
     87#elif !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ && !defined _XBOX
    7488            /* Method 2: upload vertex information at each frame */
     89#elif defined _XBOX
     90            extern D3DDevice *g_d3ddevice;
     91            D3DVERTEXELEMENT9 const elements[3] =
     92            {
     93                { 0, 0, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
     94                D3DDECL_END()
     95            };
     96            g_d3ddevice->CreateVertexDeclaration(elements, &m_vdecl);
     97            g_d3ddevice->CreateVertexBuffer(sizeof(m_vertices), D3DUSAGE_WRITEONLY, NULL, D3DPOOL_MANAGED, &m_vbo, NULL);
     98
     99            vec2 *vertices;
     100            m_vbo->Lock(0, 0, (void **)&vertices, 0);
     101            memcpy(vertices, m_vertices, sizeof(m_vertices));
     102            m_vbo->Unlock();
    75103#else
    76104#endif
     
    80108
    81109        m_shader->Bind();
    82 #if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__
     110#if defined _XBOX
     111        extern D3DDevice *g_d3ddevice;
     112        g_d3ddevice->SetVertexDeclaration(m_vdecl);
     113        g_d3ddevice->SetStreamSource(0, m_vbo, 0, sizeof(*m_vertices));
     114#elif !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__
    83115        glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
    84116        glEnableVertexAttribArray(m_attrib);
     
    93125#endif
    94126
     127#if defined _XBOX
     128        g_d3ddevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);
     129#else
    95130        glDrawArrays(GL_TRIANGLES, 0, 3);
     131#endif
    96132
    97 #if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__
     133#if defined _XBOX
     134        /* FIXME: do we need to unset anything here? */
     135#elif !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__
    98136        glDisableVertexAttribArray(m_attrib);
    99137        glBindBuffer(GL_ARRAY_BUFFER, 0);
     
    109147    vec2 m_vertices[3];
    110148    Shader *m_shader;
    111 #if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__
     149#if defined _XBOX
     150    D3DVertexDeclaration *m_vdecl;
     151    D3DVertexBuffer *m_vbo;
     152#elif !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__
    112153    GLuint m_vbo;
    113154#endif
     
    120161    Application app("Tutorial 1: Triangle", ivec2(640, 480), 60.0f);
    121162
    122 #if defined _MSC_VER
     163#if defined _MSC_VER && !defined _XBOX
    123164    _chdir("..");
    124 #elif defined _WIN32
     165#elif defined _WIN32 && !defined _XBOX
    125166    _chdir("../..");
    126167#endif
     
    130171
    131172    app.Run();
    132 
    133173    return EXIT_SUCCESS;
    134174}
Note: See TracChangeset for help on using the changeset viewer.