Example #1
0
void FrameBuffer::Init(GLuint ntexbuffers, GLuint width, GLuint height, bool depthbuffer)
{
  m_ntexbuffers = ntexbuffers;
  m_depthbuffer = depthbuffer;

  glGenFramebuffers(1, &m_id);
  glBindFramebuffer(GL_FRAMEBUFFER, m_id);

  GLuint* textures_id = new GLuint[ntexbuffers];
  GLuint depth_id;

  glGenTextures(ntexbuffers, textures_id);
  if (depthbuffer)
    glGenTextures(1, &depth_id);

  for (GLuint i = 0; i < ntexbuffers; ++i) {
    FBTexture* tex = new FBTexture(textures_id[i]);
    m_fbtextures.insert(std::make_pair(GL_COLOR_ATTACHMENT0 + i, tex));
  }

  if (m_depthbuffer) {
    m_depthtex = new FBTexture(depth_id);
  }

  glBindFramebuffer(GL_FRAMEBUFFER, m_id);
  InitTextures(width, height);

  delete[] textures_id;
}
Example #2
0
int SDLWin::Run()
{
	WM->CreateSDLWindow();										// Initialize SDL
	WM->InitOpenGL();											// Initialize OpenGL
	Game->InitResources();
	Game->Pause();												// Switch to Menu Mode
	WM->GetRenderer()->Init();									// Initialize Renderer
	InitGeometry();												// Create Menus
	InitTextures();												// Initialize Menu Textures
	WM->GetRenderer()->To2D();									// Switch to 2D Rendering

    SDL_Event Event;											// Create an event variable for catching events that SDL sends
    while(WM->IsRunning())									// Main Loop starts here
    {
        if(SDL_PollEvent(&Event)) {
			GEM->ProcessEvent(&Event);				// Send Events to the 'Events' function for processing
        }
		if(WM->IsActive())
		{
			Loop();						// Game loop processing
			Render();					// Draw to the screen
			_CrtCheckMemory( );
		}
		SDL_Delay(TimeLeft());			// Limit the frame rate
    }

    Cleanup();							// Once everything is done, make sure to clean up all loose ends
    return 1;							// Return 1 so that we know everything went fine
}
Example #3
0
void World::InitWorldObjects() {
	InitTextures();
	InitImages();
	InitSounds();
	InitObjects();
	InitSprites();
}
Example #4
0
static bool UploadData(IDirect3DDevice9* aDevice,
                       RefPtr<IDirect3DTexture9>& aTexture,
                       HANDLE& aHandle,
                       uint8_t* aSrc,
                       const gfx::IntSize& aSrcSize,
                       int32_t aSrcStride)
{
  RefPtr<IDirect3DSurface9> surf;
  D3DLOCKED_RECT rect;
  aTexture = InitTextures(aDevice, aSrcSize, D3DFMT_A8, surf, aHandle, rect);
  if (!aTexture) {
    return false;
  }

  if (aSrcStride == rect.Pitch) {
    memcpy(rect.pBits, aSrc, rect.Pitch * aSrcSize.height);
  } else {
    for (int i = 0; i < aSrcSize.height; i++) {
      memcpy((uint8_t*)rect.pBits + i * rect.Pitch,
             aSrc + i * aSrcStride,
             aSrcSize.width);
    }
  }

  FinishTextures(aDevice, aTexture, surf);
  return true;
}
Example #5
0
void LoadState::Draw()
{
	InitTextures();

	int x = Texture::GetWindowCenter(bg->Width());
	int y = Window::height / 2 - bg->Height() / 2;

	sprite_renderer->DrawSprite(*bg, glm::vec2(x, y), glm::vec2(bg->Width(), bg->Height()), 0.0f, glm::vec3(1.0f, 1.0f, 1.0f));
}
//-----------------------------------------------------------------------------
//! RestoreContextResources
//    - this function restores all of the CL/D3D resources and contexts
//-----------------------------------------------------------------------------
HRESULT RestoreContextResources()
{
    // Reinitialize D3D9 resources, CL resources/contexts
    InitCL(0, NULL);
    InitTextures();
    RegisterD3D9ResourceWithCL();

    return S_OK;
}
Example #7
0
DestroyChipsOrder::DestroyChipsOrder(Objective objective, int count, bool _reset_after_move)
	: _count(count)
	, _count_selected(0)
	, _count_killed(0)
	, _cell_type(objective)
	, _reset_after_move(_reset_after_move)
	, _drawShowCount(count)
{
	InitTextures();
}
Example #8
0
int rt_initialize(int * argc, char ***argv) {
  InitTextures();

  if (!parinitted) {
    rt_par_init(argc, argv);
    parinitted=1;
  }

  return rt_mynode(); /* return our node id */ 
}
Example #9
0
void SceneBase::Init(string vertexShader, string fragmentShader)
{
	// Debug
	m_bShowDebug = false;

	// Simulation Speed
	m_speed = 1.0f;

	// Dark Blue Background
	glClearColor(0.0f, 0.0f, 0.4f, 0.0f);
	// Enable depth test
	glEnable(GL_DEPTH_TEST);
	// Accept fragment if it closer to the camera than the former one
	glDepthFunc(GL_LESS);

	// Face Culling
	glEnable(GL_CULL_FACE);
	m_bCull = true;

	// Filled/Wireframe Mode
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	m_bWireframe = false;

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	glGenVertexArrays(1, &m_vertexArrayID);
	glBindVertexArray(m_vertexArrayID);

	Math::InitRNG();
	InitShadersAndLights(vertexShader, fragmentShader);
	InitFog();


	/*
	* Resource Initialization
	*/
	// Colors
	InitColors();
	// Materials
	InitMaterials();
	// Textures
	InitTextures();
	// Meshes
	InitMeshes();

	// Projection matrix : 45° Field of View, 4:3 ratio, display range : 0.1 unit <-> 1000 units
	Mtx44 perspective;
	perspective.SetToPerspective(45.0f, 4.0f / 3.0f, 0.1f, 12000.0f);
	//perspective.SetToOrtho(-80, 80, -60, 60, -1000, 1000);
	projectionStack.LoadMatrix(perspective);

	bLightEnabled = true;
}
Example #10
0
DestroyChipsOrder::DestroyChipsOrder(rapidxml::xml_node<> *elem)
	: _count_selected(0)
	, _count_killed(0)
	, _drawShowCount(0.f)
{
	_count = Xml::GetIntAttribute(elem, "count");
	_drawShowCount = _count;
	_reset_after_move = Xml::GetBoolAttributeOrDef(elem, "one_move", true);
	_cell_type = Objective( Xml::GetIntAttribute(elem, "cell") );
	InitTextures();
}
Example #11
0
void GLEngine::Init(HWND hWnd)
{
	logging::add_file_log("log.txt");
	m_hdc = GetDC(hWnd);
	
	m_viewManager = CreateManager();
	m_Object = m_viewManager->CreateObject();
	
	RECT rc;
	GetWindowRect(hWnd, &rc);
	m_camera.SetCenter(rc.left+(rc.right-rc.left)/2,rc.top+(rc.bottom-rc.top)/2);

	GLuint		PixelFormat;
	static	PIXELFORMATDESCRIPTOR pfd=				// pfd Tells Windows How We Want Things To Be
	{
		sizeof(PIXELFORMATDESCRIPTOR),				// Size Of This Pixel Format Descriptor
		1,											// Version Number
		PFD_DRAW_TO_WINDOW |						// Format Must Support Window
		PFD_SUPPORT_OPENGL |						// Format Must Support OpenGL
		PFD_DOUBLEBUFFER,							// Must Support Double Buffering
		PFD_TYPE_RGBA,								// Request An RGBA Format
		16,										// Select Our Color Depth
		0, 0, 0, 0, 0, 0,							// Color Bits Ignored
		0,											// No Alpha Buffer
		0,											// Shift Bit Ignored
		0,											// No Accumulation Buffer
		0, 0, 0, 0,									// Accumulation Bits Ignored
		16,											// 16Bit Z-Buffer (Depth Buffer)  
		0,											// No Stencil Buffer
		0,											// No Auxiliary Buffer
		PFD_MAIN_PLANE,								// Main Drawing Layer
		0,											// Reserved
		0, 0, 0										// Layer Masks Ignored
	};

	PixelFormat=ChoosePixelFormat(m_hdc, &pfd);	// Did Windows Find A Matching Pixel Format?

	BOOL res = SetPixelFormat(m_hdc, PixelFormat, &pfd);		// Are We Able To Set The Pixel Format?	

	m_hglrc = wglCreateContext(m_hdc);
	if(!m_hglrc)
	{
		BOOST_LOG_TRIVIAL(error) << "Error wglCreateContext: " << __LINE__;
		DWORD error = GetLastError();
	}

	if(!wglMakeCurrent(m_hdc, m_hglrc))
		BOOST_LOG_TRIVIAL(error) << "Error wglMakeCurrent: " << __LINE__;

	ResizeScene(800, 600);	
	InitGL();
	InitTextures();
}
Example #12
0
void nGraphics::RestoreDeviceObjects()
{
	//
	// TODO Add any device object restoration here
	//

	InitTextures();

	m_pSprite->OnResetDevice();
	m_pLine->OnResetDevice();
	m_pFontBold->OnResetDevice();
	m_pFontNormal->OnResetDevice();
}
Example #13
0
void rt_initialize() {
  rpcmsg msg;

  reset_object();
  reset_lights();
  InitTextures();

  if (!parinitted) {
    parinitted=1;

    msg.type=1; /* setup a ping message */
  }
}
Example #14
0
/**
 * Creates the OpenGL ES 2.X context and builds the shaders.
 * @param raspitex_state A pointer to the GL preview state.
 * @return Zero if successful.
 */
static int motion_init(RASPITEX_STATE *state)
{
    int rc = raspitexutil_gl_init_2_0(state);
    if (rc != 0)
       goto end;

    rc = raspitexutil_build_shader_program(&motion_shader);

		//Call initialisation functions in c++ part (Graphics.cpp)
		InitTextures(state->width, state->height);
		InitShaders();
end:
    return rc;
}
Example #15
0
void KX_BlenderMaterial::OnConstruction()
{
	if (mConstructed)
		// when material are reused between objects
		return;
	
	if (mMaterial->glslmat)
		SetBlenderGLSLShader();

	InitTextures();

	mBlendFunc[0] =0;
	mBlendFunc[1] =0;
	mConstructed = true;
}
Example #16
0
// TextureData
TextureData::TextureData(GLenum _textureTarget, int _width, int _height, int _numTextures,
	unsigned char** _pixelData, GLfloat* _filters, GLenum* _internalFormat,
	GLenum* _format, bool _clamp, GLenum* _attachments) {
	m_textureID = new GLuint[_numTextures];
	m_textureTarget = _textureTarget;
	m_numTextures = _numTextures;

	width = _width;
	height = _height;

	m_frameBuffer = 0;
	m_renderBuffer = 0;

	InitTextures(_pixelData, _filters, _internalFormat, _format, _clamp);
	InitRenderTargets(_attachments);
}
Example #17
0
bool CMyGame::InitGame()
{
	if (!CGame::InitGame())
	{
		return false;
	}
	//资源
	InitTextures();
	//初始化各种场景
	m_pMenu = new CMenuScreen(this);
	//m_pMission = new CMission(this);
	//指定第一屏显示哪个场景
	m_pCurScreen = m_pMenu;

	return true;
}
Example #18
0
void CMenuState::Draw()
{
	InitTextures();

	////////////////// BACKGROUND//////////////////////////
	float x = Texture::GetWindowCenter(bg->Width());
	float y = Window::height / 2 - bg->Height() / 2;
	sprite_renderer->DrawSprite(*bg, glm::vec2(x, y), glm::vec2(bg->Width(), bg->Height()), 0.0f, glm::vec3(1.0f, 1.0f, 1.0f));

	////////////// USERNAME TEXTBOX /////////////////////////////////
	sprite_renderer->DrawSprite(*textbox, glm::vec2(x + 115, y + 555), glm::vec2(textbox->Width(), textbox->Height()), 0.0f, glm::vec3(1.0f, 1.0f, 1.0f));

	TextRenderer::RenderText(username.c_str(), x + 145, y + 585, 1.0f, glm::vec3(0.5f, 0.5f, 0.5f));

	////////////// JOIN BUTTON /////////////////////////////////////
	sprite_renderer->DrawSprite(*join,glm::vec2(x + 660, y + 555), glm::vec2(join->Width(), join->Height()), 0.0f, glm::vec3(1.0f, 1.0f, 1.0f));
}
Example #19
0
void CMenuState::RenderSelection() {
	InitTextures();

	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	////////////////// BACKGROUND//////////////////////////
	float x = Texture::GetWindowCenter(bg->Width());
	float y = Window::height / 2 - bg->Height() / 2;

	////////////// USERNAME TEXTBOX /////////////////////////////////
	sprite_renderer->RenderSelection(1, *textbox, glm::vec2(x + 115, y + 555), glm::vec2(textbox->Width(), textbox->Height()), 0.0f);

	////////////// JOIN BUTTON /////////////////////////////////////
	sprite_renderer->RenderSelection(2, *join, glm::vec2(x + 660, y + 555), glm::vec2(join->Width(), join->Height()), 0.0f);

	glClearColor(0.28f, 0.65f, 0.89f, 1.0f); // reset color
}
Example #20
0
void STKMeshSceneNode::updateGL()
{
    if (isGLInitialized)
        return;
    for (u32 i = 0; i < Mesh->getMeshBufferCount(); ++i)
    {
        scene::IMeshBuffer* mb = Mesh->getMeshBuffer(i);
        if (!mb)
            continue;
        GLMesh &mesh = GLmeshes[i];

        irr::video::IVideoDriver* driver = irr_driver->getVideoDriver();
        video::E_MATERIAL_TYPE type = mb->getMaterial().MaterialType;
        video::IMaterialRenderer* rnd = driver->getMaterialRenderer(type);


        if (!rnd->isTransparent())
        {
            Material* material = material_manager->getMaterialFor(mb->getMaterial().getTexture(0), mb);
            Material* material2 = NULL;
            if (mb->getMaterial().getTexture(1) != NULL)
                material2 = material_manager->getMaterialFor(mb->getMaterial().getTexture(1), mb);
            Material::ShaderType MatType = MaterialTypeToMeshMaterial(type, mb->getVertexType(), material, material2);
            if (!immediate_draw)
                InitTextures(mesh, MatType);
        }
        else if (!immediate_draw)
            InitTexturesTransparent(mesh);

        if (!immediate_draw && irr_driver->hasARB_base_instance())
        {
            std::pair<unsigned, unsigned> p = VAOManager::getInstance()->getBase(mb);
            mesh.vaoBaseVertex = p.first;
            mesh.vaoOffset = p.second;
        }
        else
        {
            fillLocalBuffer(mesh, mb);
            mesh.vao = createVAO(mesh.vertex_buffer, mesh.index_buffer, mb->getVertexType());
            glBindVertexArray(0);
        }
    }
    isGLInitialized = true;
}
Example #21
0
TextureData::TextureData(GLenum textureTarget, int width, int height, int numTextures, unsigned char** data, GLfloat* filters, GLenum* internalFormat, GLenum* format, bool clamp, GLenum* attachments)
{
	m_textureID = new GLuint[numTextures];
	m_textureTarget = textureTarget;
	m_numTextures = numTextures;
	
	#if PROFILING_SET_2x2_TEXTURE == 0
		m_width = width;
		m_height = height;
	#else
		m_width = 2;
		m_height = 2;
	#endif
	m_frameBuffer = 0;
	m_renderBuffer = 0;
	
	InitTextures(data, filters, internalFormat, format, clamp);
	InitRenderTargets(attachments);
}
//-----------------------------------------------------------------------------
// Program main
//-----------------------------------------------------------------------------
int main(int argc, char** argv)
{
	pArgc = &argc;
	pArgv = argv;

	// start logs 
    shrQAStart(argc, argv);
    shrSetLogFileName ("oclSimpleD3D9Texture.txt");
    shrLog("%s Starting...\n\n", argv[0]); 

    // process command line arguments
    if (argc > 1) 
    {
        bQATest   = shrCheckCmdLineFlag(argc, (const char **)argv, "qatest");
        bNoPrompt = shrCheckCmdLineFlag(argc, (const char **)argv, "noprompt");
    }

	//
	// create window
	//
    // Register the window class
    WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L,
                      GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
                      "OpenCL/D3D9 Texture InterOP", NULL };
    RegisterClassEx( &wc );

	int xBorder = ::GetSystemMetrics(SM_CXSIZEFRAME);
	int yMenu = ::GetSystemMetrics(SM_CYMENU);
	int yBorder = ::GetSystemMetrics(SM_CYSIZEFRAME);

    // Create the application's window (padding by window border for uniform BB sizes across OSs)
    HWND hWnd = CreateWindow( wc.lpszClassName, "OpenCL/D3D9 Texture InterOP",
                              WS_OVERLAPPEDWINDOW, 0, 0, g_WindowWidth + 2*xBorder, g_WindowHeight+ 2*yBorder+yMenu,
                              NULL, NULL, wc.hInstance, NULL );

    ShowWindow(hWnd, SW_SHOWDEFAULT);
    UpdateWindow(hWnd);

    // init fps timer
    shrDeltaT (1);

    // Initialize Direct3D
    if( SUCCEEDED( InitD3D9(hWnd) ) &&
        SUCCEEDED( InitCL(argc, (const char **)argv) ) &&
		SUCCEEDED( InitTextures() ) )
	{
        if (!g_bDeviceLost) 
		{
            RegisterD3D9ResourceWithCL();
        }
	}

	//
	// the main loop
	//
    while(false == g_bDone) 
	{
        RunCL();
        DrawScene();

		//
		// handle I/O
		//
		MSG msg;
		ZeroMemory( &msg, sizeof(msg) );
		while( msg.message!=WM_QUIT )
		{
			if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
			{
				TranslateMessage( &msg );
				DispatchMessage( &msg );
			}
			else
			{
				RunCL();
				DrawScene();

				if(bQATest)
				{
					for(int count=0;count<g_iFrameToCompare;count++)
					{
						RunCL();
						DrawScene();
					}

					const char *ref_image_path = "ref_oclSimpleD3D9Texture.ppm";
					const char *cur_image_path = "oclSimpleD3D9Texture.ppm";

					// Save a reference of our current test run image
					CheckRenderD3D9::BackbufferToPPM(g_pD3DDevice,cur_image_path);

					// compare to offical reference image, printing PASS or FAIL.
					g_bPassed = CheckRenderD3D9::PPMvsPPM(cur_image_path,ref_image_path,argv[0],MAX_EPSILON, 0.15f);

					PostQuitMessage(0);
					g_bDone = true;
				}
			}
		}
    };

	// Unregister windows class
	UnregisterClass( wc.lpszClassName, wc.hInstance );

    // Cleanup and leave
    Cleanup (g_bPassed ? EXIT_SUCCESS : EXIT_FAILURE);
}
Example #23
0
//====================================
// Setup/Init Stuff
//====================================
bool Init(int argc, char **argv){
    // Set window title to "Student Name: GPU Name"
    std::string deviceName;
    cudaDeviceProp deviceProp; 
    int gpudevice = 0;
    int device_count = 0;
    cudaGetDeviceCount(&device_count); 
    if(gpudevice > device_count){ 
        std::cout << "Error: GPU device number is greater than the number of devices!" << 
                     "Perhaps a CUDA-capable GPU is not installed?" << std::endl; 
        return false;
    } 
    cudaGetDeviceProperties(&deviceProp, gpudevice); 
    deviceName = deviceProp.name;
    deviceName = m_yourName + ": " + deviceProp.name;
    m_major = deviceProp.major;
    m_minor = deviceProp.minor;

    // Window setup stuff
#if _WIN32
	glutInit(&argc, argv);
	
	m_width = 800;
	m_height = 800;

	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
	glutInitWindowSize(m_width, m_height);
	m_window = glutCreateWindow(deviceName.c_str());
#else
    glfwSetErrorCallback(ErrorCallback);

    if (!glfwInit()){
        return false;
    }
    m_width = 800;
    m_height = 800;
    m_window = glfwCreateWindow(m_width, m_height, deviceName.c_str(), NULL, NULL);
    if (!m_window){
        glfwTerminate();
        return false;
    }
    glfwMakeContextCurrent(m_window);
    glfwSetKeyCallback(m_window, KeyCallback);
#endif

    glewExperimental = GL_TRUE;
    if(glewInit()!=GLEW_OK){
        return false;
    }

    // Init all of the things
    InitVAO();
    InitTextures();
    InitCuda();
    InitPBO(&m_pbo);

    GLuint passthroughProgram;
    passthroughProgram = InitShader();
    glUseProgram(passthroughProgram);
    glActiveTexture(GL_TEXTURE0);

    return true;
}
Example #24
0
//--------------------------------------------------------------------------------------------
void MEkranoplanGL::initializeGL()
{
//-    initializeGLFunctions();
  initializeOpenGLFunctions();
//-  qglClearColor(Qt::black);
//qglClearColor(QColor(127,127,127, 127));
qglClearColor(QColor(0,0,0, 255));

/*
glEnable(GL_BLEND); glEnable(GL_ALPHA_TEST);

//glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

glBlendColor(1.0f,1.0f,1.0f, 0.0f);
glBlendFuncSeparate(1.0f,1.0f,1.0f, 0.0f);

//setWindowFlags(Qt::FramelessWindowHint);  setAttribute(Qt::WA_TranslucentBackground);

//qglClearColor(QColor(127,127,127, 127));
//setAutoFillBackground(false);
glColor4f(1.0f, 1.0f, 1.0f, 0.0f);
setWindowOpacity(0.0);

//setOpacity(0.3);
//setStyleSheet(QLatin1String("background: transparent;"));

qglColor(overlayContext()->overlayTransparentColor());

//glClearColor(0.5f,0.5f,0.5f, 0.0f);
qglClearColor(overlayContext()->overlayTransparentColor());
//glBlendColor(0.5,0.5,0.5, 0.5);
*/

/*
setAttribute(Qt::WA_TranslucentBackground,true);
setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint );
setWindowOpacity(0.1);
bool t=testAttribute(Qt::WA_TranslucentBackground);
*/
/*
QLinearGradient alphaGradient(QPoint(0.0,0.0), QPoint(0.0,100.0));
alphaGradient.setColorAt(0.0, Qt::transparent);
alphaGradient.setColorAt(0.5, Qt::black);
alphaGradient.setColorAt(1.0, Qt::transparent);
QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect;
effect->setOpacity(0.5);//setOpacityMask(alphaGradient);
//setGraphicsEffect(effect);

//glColor4f(0.5f, 0.0f, 0.8f, 0.5f);
*/

//qglColor(QColor(127,127,127, 127));
//setStyleSheet("background-color: rgba(0,0,0, 0)");


  InitShaders();
  InitTextures();

  // Enable depth buffer
  glEnable(GL_DEPTH_TEST);

  // Enable back face culling
  glEnable(GL_CULL_FACE);

//-    geometries.init();
  Ekranoplan.Init();

    // Use QBasicTimer because its faster than QTimer
//-    timer.start(12, this);

//move(-300,0);

//setVisible(false);
//-------------------------------------
/*
    glClearColor(0.1f, 0.1f, 0.2f, 1.0f);

    QOpenGLShader *vshader = new QOpenGLShader(QOpenGLShader::Vertex, this);
    vshader->compileSourceCode(
        "attribute highp vec4 vertex;"
        "attribute mediump vec3 normal;"
        "uniform mediump mat4 matrix;"
        "uniform lowp vec4 sourceColor;"
        "varying mediump vec4 color;"
        "void main(void)"
        "{"
        "    vec3 toLight = normalize(vec3(0.0, 0.3, 1.0));"
        "    float angle = max(dot(normal, toLight), 0.0);"
        "    vec3 col = sourceColor.rgb;"
        "    color = vec4(col * 0.2 + col * 0.8 * angle, 1.0);"
        "    color = clamp(color, 0.0, 1.0);"
        "    gl_Position = matrix * vertex;"
        "}");

    QOpenGLShader *fshader = new QOpenGLShader(QOpenGLShader::Fragment, this);
    fshader->compileSourceCode(
        "varying mediump vec4 color;"
        "void main(void)"
        "{"
        "    gl_FragColor = color;"
        "}");

    m_program = new QOpenGLShaderProgram(this);
    m_program->addShader(vshader);
    m_program->addShader(fshader);
    m_program->link();

    vertexAttr = m_program->attributeLocation("vertex");
    normalAttr = m_program->attributeLocation("normal");
    matrixUniform = m_program->uniformLocation("matrix");
    colorUniform = m_program->uniformLocation("sourceColor");

    m_fAngle = 0;
    createGeometry();
*/
}
Example #25
0
void CGLImpl::Init()
{
	use_aa = 1;// not working

	// The device-creation presentation params with reasonable defaults
	D3DPRESENT_PARAMETERS d3dpp =
	{
		1280,                // BackBufferWidth;
		720,                // BackBufferHeight;
		D3DFMT_A8R8G8B8,    // BackBufferFormat;
		1,                  // BackBufferCount;
		D3DMULTISAMPLE_NONE,// MultiSampleType;
		0,                  // MultiSampleQuality;
		D3DSWAPEFFECT_DISCARD, // SwapEffect;
		NULL,               // hDeviceWindow;
		FALSE,              // Windowed;
		TRUE,               // EnableAutoDepthStencil;
		D3DFMT_D24S8,       // AutoDepthStencilFormat;
		0,                  // Flags;
		0,                  // FullScreen_RefreshRateInHz;
		D3DPRESENT_INTERVAL_IMMEDIATE, // FullScreen_PresentationInterval;
	};

	if (use_aa) {
		//d3dpp.BackBufferFormat = ( D3DFORMAT )MAKESRGBFMT( D3DFMT_A8R8G8B8 );
		d3dpp.BackBufferCount = 0;
		d3dpp.EnableAutoDepthStencil = FALSE;
		d3dpp.DisableAutoBackBuffer = TRUE;
		d3dpp.DisableAutoFrontBuffer = TRUE;
		d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
	}

	XDKGlGetScreenSize((int*)&d3dpp.BackBufferWidth, (int*)&d3dpp.BackBufferHeight);

	HRESULT hr;
	// Create Direct3D
    LPDIRECT3D9 pD3D = Direct3DCreate9( D3D_SDK_VERSION );

    // Create the D3D device
    if( FAILED( hr = pD3D->CreateDevice( 0, D3DDEVTYPE_HAL, NULL,
                                         NULL,
										 &d3dpp, &device ) ) )
    {
        printf( "Could not create D3D device!\n" );
        DebugBreak();
    }

    pD3D->Release();

	// init aa surface
	if (use_aa) {
		D3DSURFACE_PARAMETERS params = {0};
		int tile_w = 1280/4;
		int tile_h = 720;

		// render target
		params.Base = 0;
		device->CreateRenderTarget( tile_w, tile_h, D3DFMT_X8R8G8B8, D3DMULTISAMPLE_4_SAMPLES, 0, 0, &pRenderTarget, &params );

		// stencil+depth surface
		params.Base = pRenderTarget->Size / GPU_EDRAM_TILE_SIZE;
		params.HierarchicalZBase = D3DHIZFUNC_GREATER_EQUAL;
		device->CreateDepthStencilSurface( tile_w, tile_h, D3DFMT_D24S8, D3DMULTISAMPLE_4_SAMPLES, 0, 0, &pDepthStencilTarget, &params );

		device->CreateTexture( 1280, 720, 1, 0,
			( D3DFORMAT )MAKESRGBFMT( D3DFMT_LE_X8R8G8B8 ),
			D3DPOOL_DEFAULT,
			&pFrontBuffer,
			NULL );

		device->CreateTexture( 1280, 720, 1, 0,
			( D3DFORMAT )MAKESRGBFMT( D3DFMT_X8R8G8B8 ),
			D3DPOOL_DEFAULT,
			&pResolveBuffer,
			NULL );
	}

	// init stuff
	InitTextures();
	InitializeMatrices();
	InitStates();

	
	state.render_height = d3dpp.BackBufferHeight;
	state.render_width = d3dpp.BackBufferWidth;

#if USE_VB
	// create vb and stuff
	device->CreateVertexBuffer( 
		1024*1024*8,// 8 Mo
		0, 
		NULL,
		NULL, 
		&pVbGL, 
		NULL 
	);

	device->CreateIndexBuffer(
		1024*1024*8,// 8 Mo
		0,
		D3DFMT_INDEX32,
		NULL,
		&pIbGL,
		NULL);

	// refresh ib/vb cache
	GLImpl.pVbGL->Lock(0, 8*1024*1024, (void**)&GLImpl.prim.vertices.data, 0);
	//GLImpl.pVbGL->Unlock();
	GLImpl.pIbGL->Lock(0, 8*1024*1024, (void**)&GLImpl.prim.indices.data, 0);
	//GLImpl.pIbGL->Unlock();
#endif

	if (use_aa) {
		device->SetRenderTarget( 0, pRenderTarget );
		device->SetDepthStencilSurface( pDepthStencilTarget );
	}

	//device->SynchronizeToPresentationInterval();
	if (use_aa == 0) {
		device->GetFrontBuffer(&pFrontBuffer);
	}
}
Example #26
0
int WINAPI WinMain(HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine,
    int nCmdShow)
{
	startup_time = GetTickCount();
	previous_time = 0;
	frames = 0;
	fps = 1;
#ifdef _DEBUG_TIMINGS
	drawtime = 0;
	drawtime_prv = 0;
	drawtime_med = 1;
	cleartime = 0;
	cleartime_prv = 0;
	cleartime_med = 1;
	mainlooptime = 0;
	mainlooptime_prv = 0;
	mainlooptime_med = 1;
	fliptime = 0;
	fliptime_prv = 0;
	fliptime_med = 1;
#endif
	current_state = GAME_MAINMENU;
	difficulty_pick = 0;
	size_pick = 0;
	race_pick = 0;
	opponents_pick = 0;
	mouseX = 0;
	mouseY = 0;
	mouse[0] = false;
	mouse[1] = false;
	mouse[2] = false;
	tex_count = 0;
	font_count = 0;
	srand((unsigned)time(NULL));

	LogToFile("Log started");
	InitWindow(hInstance);
	InitPaths();
	InitTextures();
	InitFonts();
	InitStorages();
	InitDefinitions();
	InitGUI();
	InitOGLSettings();
	ResizeScene(cfg.scr_width, cfg.scr_height);
	LogPaths();

	//Load_v_03("test.txt");
	Load_v_04("test.txt");
	while(current_state != GAME_EXITING)
	{
		MainLoop();
		ClearScene();
		DrawScene();
		Flip(&hDC);
	}

	// Now terminating all
	KillWindow(hInstance);

	LogToFile("Finished logging");




}
Example #27
0
int Console::Input(SDL_Event action, SDL_keysym key)
{
	if(action.type==SDL_KEYDOWN)
	{
		if(key.sym == SDLK_BACKQUOTE  || key.sym == SDLK_TAB)//closes console
		{
			cur_gamestate = old_state; //return to saved gamestate
		}
		else if(key.sym == SDLK_BACKSPACE)
		{
			if(strlen(cur_line) > 0)
				cur_line[strlen(cur_line)-1] = '\0'; //remove last character
			
		}
		if(strlen(cur_line) < 128 && (char)key.unicode >= ' ' && (char)key.unicode <= '}')
		{
			cur_line[strlen(cur_line)] = (char)key.unicode;	
		}
		else if(key.sym == SDLK_RETURN)
		{
			if(!strcmp(cur_line,"wireframe on"))
			{
				wireframemode = true;	
				glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
				glDisable(GL_TEXTURE_2D);
				glDisable(GL_CULL_FACE);
				AddConsoleEntry("Wireframemode now on");
			}
			else if(!strcmp(cur_line,"wireframe off"))
			{
				wireframemode = false;	
				glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); 
				glEnable(GL_TEXTURE_2D);
				glEnable(GL_CULL_FACE);
				AddConsoleEntry("Wireframemode now off");
			
			}
			else if(!strcmp(cur_line,"debug off"))
			{
				debugmsgs = false;
				AddConsoleEntry("Debugmode now off");
			}
			else if(!strcmp(cur_line,"debug on"))
			{
				debugmsgs = true;
				AddConsoleEntry("Debugmode now on");
			}
			else if(!strcmp(cur_line,"speed off"))
			{
				set.speed = false;
				AddConsoleEntry("Speed-effect now off");
			}
			else if(!strcmp(cur_line,"speed on"))
			{
				set.speed = true;
				AddConsoleEntry("Speed-effect now on");
			}
			else if(!strcmp(cur_line,"glow off"))
			{
				set.glow = false;
				AddConsoleEntry("Glow effect now off");
			}
			else if(!strcmp(cur_line,"shadows off"))
			{
				set.shadows = false;
				AddConsoleEntry("Shadows now off");
			}
			else if(!strcmp(cur_line,"shadows on"))
			{
				set.shadows = true;
				AddConsoleEntry("Shadows now on");
			}
			else if(!strcmp(cur_line,"glow on"))
			{
				set.glow = true;
				AddConsoleEntry("Glow effect now on");
			}
			else if(!strcmp(cur_line,"details 0"))
			{
				set.details = 0;
				AddConsoleEntry("Details are now on low");
			}
			else if(!strcmp(cur_line,"details 1"))
			{
				set.details = 1;
				AddConsoleEntry("Details are now on medium");
			}
			else if(!strcmp(cur_line,"details 2"))
			{
				set.details = 2;
				AddConsoleEntry("Details are now on high");
			}
			else if(!strcmp(cur_line,"details 3"))
			{
				set.details = 3;
				AddConsoleEntry("Details are now on ultra");
			}
			else if(strstr(cur_line,"texset"))
			{
				set.textures = atoi(strstr(cur_line,"texset")+6);
				InitTextures();
				AddConsoleEntry("Changed set of textures");
			}
			else if(strstr(cur_line,"animspeed"))
			{
				
				set.animspeed = 53-atoi(strstr(cur_line,"animspeed")+10);
				AddConsoleEntry("Speed adjusted");
			}
			else //invalid command was entered
			{
				AddConsoleEntry("Available commands:");
				AddConsoleEntry("   texset [0-?]                Activates set of textures x");
				AddConsoleEntry("   details [0-2]            	Changes detail settings");
				AddConsoleEntry("   glow [on/off]               Activates/Deactivates glow effect");
				AddConsoleEntry("   debug [on/off]              Activates/Deactivates debug output");
				AddConsoleEntry("   wireframe [on/off]          Activates/Deactivates wireframe mode");
				AddConsoleEntry("   speed [on/off]          	Activates/Deactivates speed-effect");
				AddConsoleEntry("   shadows [on/off]          	Activates/Deactivates shadows");
				AddConsoleEntry("   animspeed [0-50]          	Adjusts speed of animations");
				
			}
		}
	}
	return 0;
}
Example #28
0
////////////////////////////////////////////////////////////////////////////////
// Program main
////////////////////////////////////////////////////////////////////////////////
int main(int argc, char *argv[])
{
    char device_name[NAME_LEN];
    char *ref_file = NULL;

    pArgc = &argc;
    pArgv = argv;

    printf("[%s] - Starting...\n", SDK_name);

    if (!findGraphicsGPU(device_name))
    {
        printf("> %s not supported on \"%s\" exiting...\n", SDK_name, device_name);
        exit(EXIT_SUCCESS);
    }

    // command line options
    if (argc > 1)
    {
        // automatied build testing harness
        if (checkCmdLineFlag(argc, (const char **)argv, "file"))
            getCmdLineArgumentString(argc, (const char **)argv, "file", &ref_file);
    }


    //
    // create window
    //
    // Register the window class
#if 1
    WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L,
                      GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
                      "CUDA/D3D9 Texture InterOP", NULL
                    };
    RegisterClassEx(&wc);

    int xBorder = ::GetSystemMetrics(SM_CXSIZEFRAME);
    int yMenu = ::GetSystemMetrics(SM_CYMENU);
    int yBorder = ::GetSystemMetrics(SM_CYSIZEFRAME);

    // Create the application's window (padding by window border for uniform BB sizes across OSs)
    HWND hWnd = CreateWindow(wc.lpszClassName, "CUDA/D3D9 Texture InterOP",
                             WS_OVERLAPPEDWINDOW, 0, 0, g_WindowWidth + 2*xBorder, g_WindowHeight+ 2*yBorder+yMenu,
                             NULL, NULL, wc.hInstance, NULL);


#else
    static WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL, "CudaD3D9Tex", NULL };
    RegisterClassEx(&wc);
    HWND hWnd = CreateWindow(
                    "CudaD3D9Tex", "CUDA D3D9 Texture Interop",
                    WS_OVERLAPPEDWINDOW,
                    0, 0, 800, 320,
                    GetDesktopWindow(),
                    NULL,
                    wc.hInstance,
                    NULL);
#endif

    ShowWindow(hWnd, SW_SHOWDEFAULT);
    UpdateWindow(hWnd);

    // Initialize Direct3D
    if (SUCCEEDED(InitD3D9(hWnd)) &&
        SUCCEEDED(InitCUDA()) &&
        SUCCEEDED(InitTextures()))
    {
        if (!g_bDeviceLost)
        {
            RegisterD3D9ResourceWithCUDA();
        }
    }

    //
    // the main loop
    //
    while (false == g_bDone)
    {
        RunCUDA();
        DrawScene();

        //
        // handle I/O
        //
        MSG msg;
        ZeroMemory(&msg, sizeof(msg));

        while (msg.message!=WM_QUIT)
        {
            if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
            {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
            else
            {
                RunCUDA();
                DrawScene();

                if (ref_file)
                {
                    for (int count=0; count<g_iFrameToCompare; count++)
                    {
                        RunCUDA();
                        DrawScene();
                    }

                    const char *cur_image_path = "simpleD3D9Texture.ppm";

                    // Save a reference of our current test run image
                    CheckRenderD3D9::BackbufferToPPM(g_pD3DDevice, cur_image_path);

                    // compare to offical reference image, printing PASS or FAIL.
                    g_bPassed = CheckRenderD3D9::PPMvsPPM(cur_image_path, ref_file, argv[0], MAX_EPSILON, 0.15f);

                    g_bDone = true;

                    Cleanup();
                    PostQuitMessage(0);
                }
            }
        }
    };

    // Unregister windows class
    UnregisterClass(wc.lpszClassName, wc.hInstance);

    //
    // and exit
    //
    printf("> %s running on %s exiting...\n", SDK_name, device_name);

    exit(g_bPassed ? EXIT_SUCCESS : EXIT_FAILURE);
}
TechniqueToon::TechniqueToon()
:   mCurrentLookup(0)
{
    InitTextures();
    InitShader();
}