Beispiel #1
0
void GLRender::drawRect(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2, const GLPaint& paint, GLCamera* camera) {
	GLCamera* cam = (camera != NULL) ? camera : this->cameras->gui;
	cam->update();
	GLfloat* projection16fv = cam->projection16fv.v;
	
	if (((paint.m_color & 0xFF000000) != 0) && (shaderSquareFill != NULL)) {
		if ((paint.m_color & 0xFF000000) != 0xFF000000)
			enableBlend();
		else
			disableBlend();
		
		glUseProgram(shaderSquareFill->program);
		
		glUniformMatrix4fv(shaderSquareFill->uLayerProjectionMatrix, 1, GL_FALSE, projection16fv);
		
		GLfloat* c = makeColor(&paint.m_color, 1);
		glUniform4fv(shaderSquareFill->uColor, 1, c);
		
		glBindBuffer(GL_ARRAY_BUFFER, m_squareBuffer);
		glBufferData(GL_ARRAY_BUFFER, 8 * sizeof(GLfloat), makeRect(x1, y1, x2, y2), GL_DYNAMIC_DRAW);
		glVertexAttribPointer(shaderSquareFill->aVertexPosition, 2, GL_FLOAT, GL_FALSE, 0, NULL);
		glEnableVertexAttribArray(shaderSquareFill->aVertexPosition);
		
		glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
		
		glDisableVertexAttribArray(shaderSquareFill->aVertexPosition);
		glUseProgram(0);
	}
	
	if (((paint.m_strokeColor & 0xFF000000) != 0) && (shaderSquareStroke != NULL)) {
		enableBlend();
		glUseProgram(shaderSquareStroke->program);
		
		glUniformMatrix4fv(shaderSquareStroke->uLayerProjectionMatrix, 1, GL_FALSE, projection16fv);
		
		GLfloat half = floorf((GLfloat)(paint.m_strokeWidth) / 2.0f);
		GLfloat corners[4] = { x1 - half, y1 - half, x2 + half, y2 + half };
		glUniform2fv(shaderSquareStroke->uCorners, 2, corners);
		glUniform1f(shaderSquareStroke->uBorder, paint.m_strokeWidth);
		
		GLfloat* c = makeColor(&paint.m_strokeColor, 1);
		glUniform4fv(shaderSquareStroke->uColor, 1, c);
		
		glBindBuffer(GL_ARRAY_BUFFER, m_squareBuffer);
		glBufferData(GL_ARRAY_BUFFER, 8 * sizeof(GLfloat), makeRect(x1-half, y1-half, x2+half, y2+half), GL_DYNAMIC_DRAW);
		glVertexAttribPointer(shaderSquareStroke->aVertexPosition, 2, GL_FLOAT, GL_FALSE, 0, NULL);
		glEnableVertexAttribArray(shaderSquareStroke->aVertexPosition);
		
		glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
		
		glDisableVertexAttribArray(shaderSquareStroke->aVertexPosition);
		glUseProgram(0);
	}
}
Beispiel #2
0
void GLRender::drawTexture(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2, const CString& key, GLCamera* camera) {
	GLCamera* cam = (camera != NULL) ? camera : this->cameras->gui;
	cam->update();
	GLfloat* projection16fv = cam->projection16fv.v;
	
	if (shaderSquareTexture == NULL)
		return;
	
	enableBlend();
	glUseProgram(shaderSquareTexture->program);
	
	glUniformMatrix4fv(shaderSquareTexture->uLayerProjectionMatrix, 1, GL_FALSE, projection16fv);
	
	glBindBuffer(GL_ARRAY_BUFFER, m_squareBuffer);
	glBufferData(GL_ARRAY_BUFFER, 8 * sizeof(GLfloat), makeRect(x1, y1, x2, y2), GL_DYNAMIC_DRAW);
	glVertexAttribPointer(shaderSquareTexture->aVertexPosition, 2, GL_FLOAT, GL_FALSE, 0, NULL);
	glEnableVertexAttribArray(shaderSquareTexture->aVertexPosition);
	
	glBindBuffer(GL_ARRAY_BUFFER, m_textureBuffer);
	glBufferData(GL_ARRAY_BUFFER, 8 * sizeof(GLfloat), makeRect(0, 0, 1, 1), GL_DYNAMIC_DRAW);
	glVertexAttribPointer(shaderSquareTexture->aTextureCoord, 2, GL_FLOAT, GL_FALSE, 0, NULL);
	glEnableVertexAttribArray(shaderSquareTexture->aTextureCoord);
	
	GLuint index = textures->get((wchar_t*)key)->bind(0, shaderSquareTexture->uTexture);
	
	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
	
	glDisableVertexAttribArray(shaderSquareTexture->aVertexPosition);
	glDisableVertexAttribArray(shaderSquareTexture->aTextureCoord);
	
	cleanup(index);
}
Beispiel #3
0
	//==================================================================================
	int Window::create(std::string windowName, int screenWidth, int screenHeight, unsigned int currentFlags) {

		Uint32 flags = SDL_WINDOW_OPENGL;
		m_screenWidth = screenWidth;
		m_screenHeight = screenHeight;

		if (currentFlags & INVISIBLE) {
			flags |= SDL_WINDOW_HIDDEN;
		}
		if (currentFlags & FULLSCREEN) {
			flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
		}
		if (currentFlags & BORDERLESS) {
			flags |= SDL_WINDOW_BORDERLESS;
		}

		//Open an SDL window
		m_sdlWindow = SDL_CreateWindow(windowName.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, screenWidth, screenHeight, flags);
		if (m_sdlWindow == nullptr) {
			std::cerr << "SDL Window could not be created! " << std::endl;
		}

		//Set up our OpenGL context
		SDL_GLContext glContext = SDL_GL_CreateContext(m_sdlWindow);
		if (glContext == nullptr) {
			std::cerr << "SDL_GL context could not be created!" << std::endl;
		}

		//Set up glew (optional but recommended)
		GLenum error = glewInit();
		if (error != GLEW_OK) {
			std::cerr << "Could not initialize glew!" << std::endl;
		}

		//Check the OpenGL version
		std::printf("***   OpenGL Version: %s   ***\n", glGetString(GL_VERSION));

		//Set the background color to blue
		glClearColor(0.0f, 0.0f, 1.0f, 1.0f);


		VSYNC(0);

		enableBlend();

		return 0;
	}
Beispiel #4
0
void GLRender::drawEffectMobile(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2, const CString& key, GLfloat localTime, GLfloat worldTime) {
	GLCamera* cam = this->cameras->gui;
	cam->update();
	GLfloat* projection16fv = cam->projection16fv.v;

	GLShader* shader;
	try {
		shader = shaders->get(key);
	} catch (...) {
		return;
	}
	GLuint program = shader->program;
	GLuint uLayerProjectionMatrix = (GLuint)glGetUniformLocation(program, "uLayerProjectionMatrix");
	GLuint aVertexPosition = (GLuint)glGetAttribLocation(program, "aVertexPosition");
	GLuint aTextureCoord = (GLuint)glGetAttribLocation(program, "aTextureCoord");
	GLuint uTime = (GLuint)glGetUniformLocation(program, "uTime");
	GLuint uTexture0 = (GLuint)glGetUniformLocation(program, "uTexture0");
	GLuint uTexture1 = (GLuint)glGetUniformLocation(program, "uTexture1");
 
	static Vector<GLint> effectTexturesVector = Vector<GLint>(2);
	static GLint* effectTextures = effectTexturesVector.items();
	effectTextures[0] = uTexture0;
	effectTextures[1] = uTexture1;
	enableBlend();
	GLuint index = shader->bind(0, effectTexturesVector);
	
	glUniform2f(uTime, localTime - floorf(localTime), worldTime - floorf(worldTime));
 
	glUniformMatrix4fv(uLayerProjectionMatrix, 1, GL_FALSE, projection16fv);
 
	glBindBuffer(GL_ARRAY_BUFFER, m_squareBuffer);
	glBufferData(GL_ARRAY_BUFFER, 8 * sizeof(GLfloat), makeRect(x1, y1, x2, y2), GL_DYNAMIC_DRAW);
	glVertexAttribPointer(aVertexPosition, 2, GL_FLOAT, GL_FALSE, 0, NULL);
	glEnableVertexAttribArray(aVertexPosition);
	
	glBindBuffer(GL_ARRAY_BUFFER, m_textureBuffer);
	glBufferData(GL_ARRAY_BUFFER, 8 * sizeof(GLfloat), makeRect(0, 0, 1, 1), GL_DYNAMIC_DRAW);
	glVertexAttribPointer(aTextureCoord, 2, GL_FLOAT, GL_FALSE, 0, NULL);
	glEnableVertexAttribArray(aTextureCoord);
	
	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
 
	glDisableVertexAttribArray(aVertexPosition);
	glDisableVertexAttribArray(aTextureCoord);
 
	cleanup(index);
}