コード例 #1
0
ファイル: Test.cpp プロジェクト: erio-nk/MyCxxProgram2011
void Main()
{
	wnd.Create("てすと", 0, 0, 500, 500, 
		WindowOption::StandardStyle|
		WindowOption::ClientSize|
		WindowOption::BGWhite|
		WindowOption::Centering);
	wnd.Show();

	// Initialize
	backBuf.Create(500, 500);

	rect[0] = Vector2(-50.0, -50.0);
	rect[1] = Vector2(-50.0, 50.0);
	rect[2] = Vector2(50.0, 50.0);
	rect[3] = Vector2(50.0, -50.0);


	//Vector3 v(20, 30, 1);
	//Matrix3 m;
	//Matrix3Translation4V2(m, 100, 200);
	//v = v * m;

	// Application Loop
	MainLoop(Run);

	// Finalize
	backBuf.Release();
}
コード例 #2
0
	// 初期化。
	bool Create(HWND hWnd)
	{
		if (failed(_window.Create(hWnd)))
		{
			return false;
		}
		SIZE sz;
		_window.GetClientSize(sz);

		{
			using namespace std::placeholders;
			_window.AddMessageHandler(WM_SIZE, std::bind(&Impl::OnWindowSizeMessage, this, _1, _2, _3, _4));
			_window.AddMessageHandler(WM_KEYUP, std::bind(&Impl::OnWindowKeyUpMessage, this, _1, _2, _3, _4));
		}
		
		if (failed(_device.Create(hWnd)))
		{
			return false;
		}
		
		if (failed(_renderer.Create(_device)))
		{
			return false;
		}
			
		if (failed(CreateModel()))
		{
			return false;
		}

		ResetProjectionTransform(sz);

		return true;
	}
コード例 #3
0
ファイル: Program.cpp プロジェクト: ytyaru/Draw201608070937
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPreInst, LPSTR lpszCmdLine, int nCmdShow)
{
	setlocale(LC_ALL, ".ACP");

	Window *pWindow = Window::CreateInstance();

	InitializeWndProc initializeWndProc;
	pWindow->Add((IPartWndProc*)&initializeWndProc);
	
	KeyboardWndProc keyboardWndProc;
	pWindow->Add((IPartWndProc*)&keyboardWndProc);
	
	//GdiWndProc gdiWndProc;
	//pWindow->Add((IPartWndProc*)&gdiWndProc);

	//GdiPlusWndProc gdiPlusWndProc;
	//pWindow->Add((IPartWndProc*)&gdiPlusWndProc);
	
	DrawWndProc drawWndProc;
	pWindow->Add((IPartWndProc*)&drawWndProc);

	pWindow->Create(hInstance);

	MSG msg;
	while (GetMessage(&msg, NULL, 0, 0)) {
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	Window::RemoveInstance(pWindow);

	return (msg.wParam);
}
コード例 #4
0
ファイル: test.cpp プロジェクト: erio-nk/MyCxxProgram2011
void Main()
{
	Window wnd;

	wnd.Create("‚Ä‚·‚Æ", 0, 0, 100, 100, 
		WindowOption::StandardStyle|
		WindowOption::ClientSize|
		WindowOption::Centering);
	wnd.Show();

	MessageLoop();
	//MainLoop(Run);
}
コード例 #5
0
ファイル: sfWindow.cpp プロジェクト: freemaul/SFML
static VALUE Window_initialize(int argc, VALUE *argv, VALUE vSelf) {
	// Get C++ object pointer from vSelf
	Window *pSelf;
	Data_Get_Struct(vSelf, Window, pSelf);
	if(argc >= 2 && argc <= 3 &&
			IS(argv[0], g_cVideoMode) &&
			ISSTR(argv[1]) &&
			(argc < 3 || true) &&
			(argc < 4 || ISNUM(argv[3]))) {
		pSelf->Create(*(VideoMode *)DATA_PTR(argv[0]), STR2CSTR(argv[1]),
			argc < 3 ? (Style::Resize|Style::Close) : NUM2INT(argv[2]),
			argc < 4 ? 0 : NUM2INT(argv[3]));
	} else
		rb_raise(rb_eTypeError, "wrong argument type(s)");
	return vSelf;
}
コード例 #6
0
ファイル: signer.cpp プロジェクト: fast01/ULib
   void run(int argc, char* argv[], char* env[])
      {
      U_TRACE(5, "Application::run(%d,%p,%p)", argc, argv, env)

      UApplication::run(argc, argv, env);

      // manage options

      UString cfg_str;

      if (UApplication::isOptions()) cfg_str = opt['c'];

      // manage arg operation

      // manage file configuration

      if (cfg_str.empty()) cfg_str = U_STRING_FROM_CONSTANT("signer.cfg");

      cfg.UFile::setPath(cfg_str);

      // --------------------------------------------------------------------------------------------------------------
      // configuration parameters
      // --------------------------------------------------------------------------------------------------------------
      // --------------------------------------------------------------------------------------------------------------

      // form_template = cfg[U_STRING_FROM_CONSTANT("TEMPLATE")];

      hinstance = GetModuleHandle(0);

      Window MainWindow;
      //PropSheet MainWindow;

      // Initialize common controls
      InitCommonControls();

      // Init window class lib
      Window::SetAppInstance(hinstance);

      // Create pages

      // Add pages to sheet

      // Create the PropSheet main window
      MainWindow.Create();

      // Clean exit.. save user options.
      }
コード例 #7
0
ファイル: Source.cpp プロジェクト: kairouen/rendering1hour
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, INT)
{
	MSG msg;
	HANDLE	hMutex; //ミューテックスのハンドル
	HANDLE hThreadExport, hThreadWindow, hThreadDraw;
	Window win;
	win.Create("preview",0,0,SCREEN_WIDTH+30,SCREEN_HEIGHT+80);

	image = new edupt::Color[SCREEN_WIDTH * SCREEN_HEIGHT];

	Init(win.GethWnd());

	hMutex = CreateMutex(NULL, FALSE, NULL);
	hThreadExport = (HANDLE)_beginthread(ExportScene,0,NULL);	//レンダリング経過出力スレッド
	hThreadWindow = (HANDLE)_beginthread(WindowProc,0,NULL);	//プロシージャ
	hThreadDraw = (HANDLE)_beginthread(DrawScene,0,NULL);	//プレビュー描画スレッド

	Run();
	CloseHandle(hThreadExport);
	CloseHandle(hThreadWindow);
	CloseHandle(hThreadDraw);
	CloseHandle(hMutex);

	while(true)
	{
		if(PeekMessage(&msg,NULL, 0, 0,PM_REMOVE))
		{
			if(msg.message == WM_QUIT)
			{
				break;
			}
			else
			{
				DispatchMessage(&msg);
			}
		}
		else
		{
			Sleep(1);
		}
	}

	delete(image);

	return 0;
}
コード例 #8
0
ファイル: MouseInc.cpp プロジェクト: 52M/MouseInc
int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
                     _In_opt_ HINSTANCE hPrevInstance,
                     _In_ LPTSTR    lpCmdLine,
                     _In_ int       nCmdShow)
{
    ::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);

    ImmDisableIME(-1);

    // 检查单例,并通知旧程序
    HANDLE mutex = ::CreateMutex(NULL, TRUE, repeat_run);
    if (::GetLastError() == ERROR_ALREADY_EXISTS)
    {
        UINT WM_REPEAT_RUN = ::RegisterWindowMessage(repeat_run);
        ::PostMessage(HWND_BROADCAST, WM_REPEAT_RUN, 0, 0);
        ::CloseHandle(mutex);
        return 0;
    }

    InitializeVirtualDesktopManagerInternal();

    // 加载lua引擎
    lua_engine = new LuaEngine();

    // 加载配置
    Config::Init();

    // 启动程序
    Window wnd;
    if (!wnd.Create(NULL, CRect(0, 0, 400, 400), app_name, WS_CAPTION))
    {
        return 0;
    }
    // wnd.ShowWindow(nCmdShow);

    // 消息循环
    WTL::CMessageLoop msgLoop;
    int ret = msgLoop.Run();

    delete lua_engine;
    return ret;
}
コード例 #9
0
ファイル: main.cpp プロジェクト: matt-han/ba_gui1
//------------------------------------------------------------------------------
//	starts the GUI
//	Parameters:
//	 IN:
//		- HINSTANCE hInstance -> handle to the instance
//		- int nCmdShow -> format for how to show the window
//	Return: _iError code signaling if operation succeded or _iError
//------------------------------------------------------------------------------
int createGUI(HINSTANCE hInstance, int nCmdShow)
{
	Window win;

	win.sethInstance(hInstance);

	if (!win.Create(WINDOW_TITLE , WS_OVERLAPPEDWINDOW))
    {
        return ERROR_CREATE_GUI;
    }

    ShowWindow(win.window(), nCmdShow);

    // Run the message loop.

    MSG msg = { };
    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

	return ERROR_SUCCESS;
}
コード例 #10
0
ファイル: PaintWindow.hpp プロジェクト: kwtskran/XCSoar
 void Create(ContainerWindow &parent, PixelRect rc,
             const WindowStyle style=WindowStyle()) {
   Create(parent, _T("PaintWindow"), rc, style);
 }
コード例 #11
0
ファイル: PaintWindow.hpp プロジェクト: kwtskran/XCSoar
 void Create(ContainerWindow &parent, const TCHAR *cls, PixelRect rc,
             const WindowStyle style=WindowStyle()) {
   Create(&parent, cls, rc, style);
 }
コード例 #12
0
ファイル: main.cpp プロジェクト: JoshuaBrookover/Jatta
int main()
{
    try
    {
        ImageLoaders::PNG loader;
        if (!loader.CanLoad("resources/logo.png"))
        {
            throw FatalException("Cannot load PNG images.");
        }
        Image* image = loader.Load("resources/logo.png");

        WindowStyle style;
        style.title = U8("logo.png (") + image->GetWidth() + U8(", ") + image->GetHeight() + U8(")");
        style.width = image->GetWidth();
        style.height = image->GetHeight();
        style.backgroundColor = Colors::black;
        style.resizable = false;

        Window window;
        window.Create(style);

        OpenGL::Context context;
        context.Create(&window);

        GL::BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        GL::Enable(GL_BLEND);
        GL::Enable(GL_ALPHA_TEST);
        GL::Enable(GL_TEXTURE_2D);

        UInt program = LoadShader(U8("resources/shader.vert"), U8("resources/shader.frag"));

        UInt box = MakeBox();

        UInt texture;
        GL::GenTextures(1, &texture);
        GL::BindTexture(GL_TEXTURE_2D, texture);
        GL::TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
        GL::TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
        GL::TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        GL::TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        GL::TexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
        GL::PixelStorei(GL_UNPACK_ALIGNMENT, 1);
        GL::TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image->GetWidth(), image->GetHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, image->GetData());
        GL::BindTexture(GL_TEXTURE_2D, 0);

        Timer timer;
        Float32 hue = 0.0f;
        while (window.IsOpen())
        {
            Timer::Sleep(1);
            hue = Math::Mod(hue + timer.GetDeltaTime() * 45, 360.0f);
            context.ClearColor(Color::MakeHSL(hue, 40, 255));

            context.Viewport(0, 0, window.GetWidth(), window.GetHeight());
            context.Clear(GL::COLOR_BUFFER_BIT | GL::DEPTH_BUFFER_BIT);
            GL::UseProgram(program);
            GL::UniformMatrix4fv(GL::GetUniformLocation(program, "orthoMatrix"), 1, false, Matrix::MakeOrtho(0, 1, 1, 0).GetData());
            GL::UniformMatrix4fv(GL::GetUniformLocation(program, "modelMatrix"), 1, false, Matrix::Identity().GetData());
            GL::Uniform1i(GL::GetUniformLocation(program, "texture"), 0);
            GL::ActiveTexture(GL_TEXTURE0);
            GL::BindTexture(GL_TEXTURE_2D, texture);
            GL::BindVertexArray(box);
            GL::DrawArrays(GL_QUADS, 0, 4);
            GL::BindVertexArray(0);
            GL::UseProgram(0);
            context.SwapBuffers();

            Window::Update();
        }
    }
    catch (Exception& e)
    {
        std::cout << e.what() << std::endl;
        std::cout << std::hex << "Error code: 0x" << e.unique << std::dec << " (decimal " << e.unique << ")" << std::endl;
    }
}
コード例 #13
0
ファイル: Context.cpp プロジェクト: anareboucas/nanook
VOID Context::Create( UINT ColorBits, UINT AlphaBits, UINT DepthBits, UINT MultiSample )
{
	Window W;
	W.Create( Window::m_pDefaultWindowClass, TEXT(""), 0, 0, Ptr<Window>::Null, 0, Point(0,0), Point(1,1) );

	m_hDeviceContext = GetDC(W.Handle());

	PIXELFORMATDESCRIPTOR PixelFormat;
	ZeroMemory( &PixelFormat, sizeof(PixelFormat) );
	
	PixelFormat.nSize = sizeof(PIXELFORMATDESCRIPTOR);
  PixelFormat.nVersion   = 1;
  PixelFormat.dwFlags    = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_SUPPORT_COMPOSITION | PFD_SWAP_COPY;
  PixelFormat.iPixelType = PFD_TYPE_RGBA;
  PixelFormat.cColorBits = ColorBits + AlphaBits;
	PixelFormat.cDepthBits = DepthBits;

	INT PixelFormatIndex = ChoosePixelFormat( m_hDeviceContext, &PixelFormat );
	SetPixelFormat(m_hDeviceContext, PixelFormatIndex, &PixelFormat);

	m_hGLContext = wglCreateContext(m_hDeviceContext); 

	Activate();

	PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
	
  if (wglChoosePixelFormatARB == 0)
    MultiSample = 0;

	while (MultiSample > 0)
	{
		INT PixelFormatAttributes[] = 
		{
			WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
			WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
			WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,
			WGL_COLOR_BITS_ARB, ColorBits,
			WGL_ALPHA_BITS_ARB, AlphaBits,
			WGL_DEPTH_BITS_ARB, DepthBits,
			WGL_STENCIL_BITS_ARB, 0,
			WGL_DOUBLE_BUFFER_ARB, GL_TRUE,
			WGL_SAMPLE_BUFFERS_ARB, GL_TRUE,
			WGL_SAMPLES_ARB, MultiSample,
			0,
		};

		UINT N = 0;
		PixelFormatIndex = 0;
		wglChoosePixelFormatARB( m_hDeviceContext, PixelFormatAttributes, NULL, 1, &PixelFormatIndex, &N);
    if (N > 0)
      break;

    MultiSample >>= 1;
	}

	ReleaseDC( W.Handle(), m_hDeviceContext );
	wglDeleteContext( m_hGLContext );
	W.Destroy();

	m_hDeviceContext = GetDC(m_pWindow->Handle());

	ZeroMemory( &PixelFormat, sizeof(PixelFormat) );

	PixelFormat.nSize = sizeof(PIXELFORMATDESCRIPTOR);
  PixelFormat.nVersion   = 1;
  PixelFormat.dwFlags    = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_SUPPORT_COMPOSITION | PFD_SWAP_COPY;
  PixelFormat.iPixelType = PFD_TYPE_RGBA;
  PixelFormat.cColorBits = ColorBits + AlphaBits;
	PixelFormat.cDepthBits = DepthBits;

	if (MultiSample == 0)
		PixelFormatIndex = ChoosePixelFormat( m_hDeviceContext, &PixelFormat );
	SetPixelFormat(m_hDeviceContext, PixelFormatIndex, &PixelFormat);

	m_hGLContext = wglCreateContext(m_hDeviceContext); 

	Activate();

	TraceD(TEXT("OpenGL Renderer: %s"), glGetString(GL_RENDERER) );
	TraceD(TEXT("OpenGL Vendor: %s"), glGetString(GL_VENDOR) );
	TraceD(TEXT("OpenGL Version: %s"), glGetString(GL_VERSION) );
  TraceD(TEXT("MultiSampling: %d"), MultiSample );

	InitExtensions();

  m_pWindow = 0;
}
コード例 #14
0
ファイル: main.cpp プロジェクト: kirkbackus/meal-track
//Entry point of the program
int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nCmdShow)
{
    //Create a window
    cWindow = Window(WindowProcedure, hThisInstance, "MealTrackApp", nCmdShow);
    cWindow.Create("MealTrack - Untitled", 462, 375);

    //Actually create the button with the window as its parent
    RECT rEditBox = {16, 280, 272, 24};
    cEditBox = EditBox(cWindow, rEditBox, "Disconnected");
    cEditBox.SetReadOnly(1);

    //Create the Button
    RECT rButton = {304, 280, 128, 24};
    cButton = Button(cWindow, rButton, "Start Meal", IDR_START_BUTTON);
    cButton.SetEnabled(0);

    //Create the listbox
    RECT rListBox = {16, 16, 272, 272};
    cListBox = ListBox(cWindow, rListBox, "MealListBox");

    //Meal wait box
    RECT rLabelDelay = {304, 16, 128, 16};
    RECT rEditDelay = {304, 32, 128, 24};
    cLabelDelay = Label(cWindow, rLabelDelay, "Meal wait (seconds)");
    cEditDelay = EditBox(cWindow, rEditDelay, "10");

    //Create Date format box
    RECT rLabelDate = {304, 64, 128, 16};
    RECT rComboDate = {304, 80, 128, 24};
    cLabelDate = Label(cWindow, rLabelDate, "Date format");
    cComboDate = ComboBox(cWindow, rComboDate, "ComboBoxDate");
    cComboDate.AddItem("12 Hour AM/PM");
    cComboDate.AddItem("24 Hour");
    cComboDate.SetDefaultItem(1);

    //Record format box
    RECT rLabelRecord = {304, 112, 128, 16};
    RECT rComboRecord = {304, 128, 128, 24};
    cLabelRecord = Label(cWindow, rLabelRecord, "Record change type");
    cComboRecord = ComboBox(cWindow, rComboRecord, "ComboBoxRecord");
    cComboRecord.AddItem("Increases");
    cComboRecord.AddItem("Decreases");
    cComboRecord.AddItem("Both");
    cComboRecord.SetDefaultItem(1);

    //Record format box
    RECT rLabelSensitivity = {304, 160, 128, 16};
    RECT rComboSensitivity = {304, 176, 128, 24};
    cLabelSensitivity = Label(cWindow, rLabelSensitivity, "Sensitivity");
    cComboSensitivity = ComboBox(cWindow, rComboSensitivity, "ComboBoxSensitivity");
    cComboSensitivity.AddItem("0.01 g");
    cComboSensitivity.AddItem("0.02 g");
    cComboSensitivity.AddItem("0.03 g");
    cComboSensitivity.AddItem("0.04 g");
    cComboSensitivity.AddItem("0.05 g");
    cComboSensitivity.AddItem("0.06 g");
    cComboSensitivity.AddItem("0.07 g");
    cComboSensitivity.AddItem("0.08 g");
    cComboSensitivity.AddItem("0.09 g");
    cComboSensitivity.SetDefaultItem(2);

    //Custom function to creeate window
    CreateWindowMenu(cWindow);

    //Message loop
    MSG msg;
    while (cWindow.GetMessage(&msg))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    // The program return-value is 0 - The value that PostQuitMessage() gave
    return msg.wParam;
}
コード例 #15
0
ファイル: main.cpp プロジェクト: JoshuaBrookover/Jatta
int main()
{
    Jatta::Matrix wee;
    wee[1][2] = 5;
    std::cout << wee << std::endl;
    try
    {
        // Setup the window
        WindowStyle style;
        style.title = "A Quick Brown Fox Jumps Over The Lazy Dog";
        style.width = 800;
        style.height = 350;
        style.backgroundColor = Colors::black;
        style.resizable = false;
        Window window;
        window.Create(style);

        // Create the OpenGL context
        OpenGL::Context context;
        context.Create(&window);

        OpenGL::Program program = LoadShader("Resources/screen.vert", "Resources/screen.frag");

        Font font;
        if (font.Load("Resources/Arial.ttf") == -1)
        { throw std::runtime_error("Failed to load 'Resources/Arial.ttf'."); }
        if (font.Load("Resources/epgyosho.ttf") == -1)
        { throw std::runtime_error("Failed to load 'Resources/epgyosho.ttf'."); }
        if (font.Load("Resources/LastResort.ttf") == -1)
        { throw std::runtime_error("Failed to load 'Resources/LastResort.ttf'."); }
        font.SetStyle(FontStyles::OBLIQUE | FontStyles::UNDERLINED);

        Image image[22];
        OpenGL::Texture texture[22];
        OpenGL::VertexArray box[22];

        for (unsigned int i = 7; i < 27; ++i)
        {
            font.SetSize(i);
            image[i-7] = font.GenerateText(Jatta::Colors::white,"A Quick Brown Fox Jumps Over The Lazy Dog 0123456789");

            texture[i-7].Create(OpenGL::GL::TEXTURE_2D);
            texture[i-7].Bind();
            texture[i-7].SetTextureWrapS(OpenGL::GL::REPEAT);
            texture[i-7].SetTextureWrapT(OpenGL::GL::REPEAT);
            texture[i-7].SetMinFilter(OpenGL::GL::LINEAR);
            texture[i-7].SetMagFilter(OpenGL::GL::LINEAR);
            texture[i-7].Image2D(0, OpenGL::GL::RGBA, image[i-7].GetWidth(), image[i-7].GetHeight(), 0, OpenGL::GL::RGBA, OpenGL::GL::UNSIGNED_BYTE, image[i-7].GetData());
            texture[i-7].Unbind();

            box[i-7] = MakeBox(Float2(image[i-7].GetWidth(), image[i-7].GetHeight()));
        }

        font.SetSize(16);
        font.SetStyle(FontStyles::OVERLINED | FontStyles::UNDERLINED);
        image[21] = font.GenerateText(Jatta::Colors::white,"こんにちわ");

        texture[21].Create(OpenGL::GL::TEXTURE_2D);
        texture[21].Bind();
        texture[21].SetTextureWrapS(OpenGL::GL::REPEAT);
        texture[21].SetTextureWrapT(OpenGL::GL::REPEAT);
        texture[21].SetMinFilter(OpenGL::GL::LINEAR);
        texture[21].SetMagFilter(OpenGL::GL::LINEAR);
        texture[21].Image2D(0, OpenGL::GL::RGBA, image[21].GetWidth(), image[21].GetHeight(), 0, OpenGL::GL::RGBA, OpenGL::GL::UNSIGNED_BYTE, image[21].GetData());
        texture[21].Unbind();

        box[21] = MakeBox(Float2(image[21].GetWidth(), image[21].GetHeight()));

        while (window.IsOpen())
        {
            Window::Update();

            context.Viewport(0, 0, window.GetWidth(), window.GetHeight());
            context.Clear(OpenGL::GL::COLOR_BUFFER_BIT | OpenGL::GL::DEPTH_BUFFER_BIT);

            UInt32 y = 0;

            program.Bind();
            OpenGL::Program::UniformMatrix4f(program.GetUniformLocation("orthoMatrix"), false, Matrix::MakeOrtho(0, window.GetWidth(), window.GetHeight(), 0));
            for (unsigned int i = 7; i < 27; ++i)
            {
                OpenGL::Program::UniformMatrix4f(program.GetUniformLocation("modelMatrix"), false, Matrix::MakeTranslation(Float2(0,y)));
                OpenGL::Program::Uniform1i(program.GetUniformLocation("texture"), texture[i-7].GetID());
                OpenGL::ClearErrors();
                OpenGL::Texture::Active(texture[i-7].GetID());
                texture[i-7].Bind();
                box[i-7].Bind();
                box[i-7].DrawArrays(OpenGL::GL::QUADS, 0, 4);
                box[i-7].Unbind();
                y += image[i-7].GetHeight();
            }

            OpenGL::Program::UniformMatrix4f(program.GetUniformLocation("modelMatrix"), false, Matrix::MakeTranslation(Float2(800-image[21].GetWidth(),0)));
            OpenGL::Program::Uniform1i(program.GetUniformLocation("texture"), texture[21].GetID());
            OpenGL::ClearErrors();
            OpenGL::Texture::Active(texture[21].GetID());
            texture[21].Bind();
            box[21].Bind();
            box[21].DrawArrays(OpenGL::GL::QUADS, 0, 4);
            box[21].Unbind();

            program.Unbind();

            context.SwapBuffers();
        }
    }
    catch (std::exception& e)
    {
        std::cout << e.what() << std::endl;
    }
}
コード例 #16
0
ファイル: Main.cpp プロジェクト: sirwolfgang/FTLEngine
int CALLBACK WinMain(HINSTANCE _hInstance, 
					 HINSTANCE _hPrevInstance, 
					 LPSTR _lpCmdLine, 
					 int _nCmdShow)
{
	Window Window;
	Window.Initialize(_hInstance, _nCmdShow);
	Window.Create(Platform::Window::eWindow_Mode_Normal, L"FTL Engine", 0, 0, 1024, 768);

	RendererDLL		rendererDLL;
	Renderer*		pRenderer;

	rendererDLL.Create(&pRenderer);
	{
		Graphics::Renderer::Settings Settings;

		Settings.nWidth			= 1024;
		Settings.nHeight		= 768;
		Settings.nRefreshRate	= 0;
		Settings.nMSAASamples	= 1;
		Settings.nSampleQuality = 0;
		Settings.nBufferCount	= 1;
		Settings.eDriverMode	= Graphics::Renderer::eDriverMode_Hardware;
		Settings.hOutput		= Window.GetHandle();
		Settings.bDebugMode		= true;

		pRenderer->Initialize(Settings);
		pRenderer->Startup();
		{


			// Shaders
			Graphics::HShader VertexShader	= pRenderer->CompileFromFile(L"Source/Shader.hlsl", "VShader", Graphics::Shader::eSHADER_TYPE_VERTEX);
			Graphics::HShader PixelShader	= pRenderer->CompileFromFile(L"Source/Shader.hlsl", "PShader", Graphics::Shader::eSHADER_TYPE_PIXEL);

			// Vertex Format
			Graphics::VertexFormat::VertDataPair VertFormat[2] = 
			{
				{ Graphics::VertexFormat::eSEMANTICS_POSITION,	Graphics::VertexFormat::eDATASIZES_FLOAT3},
				{ Graphics::VertexFormat::eSEMANTICS_COLOR,		Graphics::VertexFormat::eDATASIZES_FLOAT4},
			};

			Graphics::HVertexFormat hVertexFormat = pRenderer->CreateVertexFormat(VertFormat, 2);

			// Vertex Buffer
			Vertex VertexBuffer[] =
			{
				{ 0.00f,  0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f},
				{ 0.45f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
				{-0.45f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f},
			};

			Graphics::HVertexBuffer hVertexBuffer = pRenderer->CreateVertexBuffer(3, &VertexBuffer, hVertexFormat);

			// Index Buffer
			uint32 IntexBuffer[] =
			{
				0, 1, 2,
			};

			Graphics::HIndexBuffer hIndexBuffer = pRenderer->CreateIndexBuffer(3, IntexBuffer);

			// Activate Settings
			VertexShader->SetShaderActive();
			PixelShader->SetShaderActive();

			hVertexBuffer->SetBufferActive();
			hIndexBuffer->SetBufferActive();
			pRenderer->SetPrimitiveTopology(Graphics::Primitive::eTOPOLOGY_TRIANGLELIST);

			//while(Window.Update())
			Window.Update();
			{
				float Color[4] = {0.33f, 0.33f, 0.33f, 1.00f};

				pRenderer->ClearBackBuffer(Color);
				pRenderer->Draw(3, 0, 0);
				pRenderer->Present();
			}
			Window.Update();
		}
		pRenderer->Shutdown();
	}
	rendererDLL.Release();

	return NULL;
}
コード例 #17
0
ファイル: main.cpp プロジェクト: Zethes/CGUL
int main()
{
    try
    {
        Image image;
        image.Load("resources/jattabox.png");

        WindowStyle style;
        style.title = U8("CGUL - 3D World");
        style.size = UCoord32(640, 480);
        style.backgroundColor = Colors::black;
        style.resizable = true;

        Window window;
        window.Create(style);

        OpenGL::Context context;
        context.Create(&window);

        GL::BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        GL::Enable(GL_BLEND);
        GL::Enable(GL_ALPHA_TEST);
        GL::Enable(GL_TEXTURE_2D);
        GL::Enable(GL_DEPTH_TEST);
        GL::Enable(GL_CULL_FACE);
        glCullFace(GL_BACK);

        UIntN program = LoadShader(U8("resources/shader.vert"), U8("resources/shader.frag"));

        UIntN box = MakeBox();

        UIntN texture;
        GL::GenTextures(1, &texture);
        GL::BindTexture(GL_TEXTURE_2D, texture);
        GL::TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
        GL::TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
        GL::TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        GL::TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        GL::TexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
        GL::PixelStorei(GL_UNPACK_ALIGNMENT, 1);
        GL::TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.GetWidth(), image.GetHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, image.GetData< void >());
        GL::BindTexture(GL_TEXTURE_2D, 0);

        Timer timer;
        Float32 hue = 0.0f;
        while (window.IsOpen())
        {
            Float32 deltaTime = timer.GetDeltaTime();
            Timer::Sleep(1);
            hue = Math::Mod(hue + deltaTime * 0.125f, 1.0f);
            context.ClearColor(Color::MakeHSV(hue, 0.156862745098039f, 1.0f));

            Float32 movement = 1 + Math::Cos(hue / 10.0f);
            static Float32 rot = 0;
            rot += deltaTime / 1.0f;

            context.Viewport(0, 0, window.GetWidth(), window.GetHeight());
            context.Clear(GL::COLOR_BUFFER_BIT | GL::DEPTH_BUFFER_BIT);
            GL::UseProgram(program);
            //GL::UniformMatrix4fv(GL::GetUniformLocation(program, "orthoMatrix"), 1, false, Matrix::MakeOrtho2D(0, 1280, 768, 0).GetData());
            MatrixF view = MatrixF::MakeLookAt(Vector3F(Math::Cos(rot) * 50, Math::Cos(rot) * 50, Math::Sin(rot) * 50), Vector3F(0, 0, 0), Vector3F(0, -1, 0));
            MatrixF projection = MatrixF::MakePerspective(45.0, window.GetWidth() / (Float32)window.GetHeight(), 1, 1000);
            MatrixF vp = view * projection;

            MatrixF model;
            model = MatrixF::MakeScaling(Vector3F(20, 20, 20)) * model;

            //Matrix wvp = model * Matrix::MakeOrtho2D(0, 1280, 768, 0);
            MatrixF wvp = model * vp;
            GL::UniformMatrix4fv(GL::GetUniformLocation(program, "matrix"), 1, false, wvp.GetData());
            GL::Uniform1i(GL::GetUniformLocation(program, "texture"), 0);
            GL::ActiveTexture(GL_TEXTURE0);
            GL::BindTexture(GL_TEXTURE_2D, texture);
            GL::BindVertexArray(box);
            GL::DrawArrays(GL_QUADS, 0, 24);
            GL::BindVertexArray(0);
            GL::UseProgram(0);
            context.SwapBuffers();

            Window::Update();
        }
    }
    catch (Exception& e)
    {
        std::cout << e.what() << std::endl;
        std::cout << std::hex << "Error code: 0x" << e.unique << std::dec << " (decimal " << e.unique << ")" << std::endl;
    }
}