Example #1
0
void setTextureRepeat(textureT* tex, bool value) {
    tex->repeat = value;

    textureT* old_tex = useTexture(tex, 0);

    GLint wrap_param = value ? GL_REPEAT : GL_CLAMP_TO_EDGE;
    glTexParameteri(texTarget(tex), GL_TEXTURE_WRAP_S, wrap_param);
    glTexParameteri(texTarget(tex), GL_TEXTURE_WRAP_T, wrap_param);

    useTexture(old_tex, 0);
}
Example #2
0
void loadTextureFromScreen(textureT* tex) {
    int width  = screenWidth(),
        height = screenHeight();

    renderTargetT* old_rt  = useRenderTarget(NULL);
    textureT*      old_tex = useTexture(tex, 0);

    glCopyTexImage2D(texTarget(tex), 0, GL_RGBA8, 0, 0, width, height, 0);

    useTexture     (old_tex, 0);
    useRenderTarget(old_rt);
}
Example #3
0
textureT* whiteTexture(void) {
    static textureT* white_tex = NULL;

    if (!white_tex) {
        white_tex = createTexture();

        textureT* old_tex = useTexture(white_tex, 0);
        float     data[]  = { 1.0f, 1.0f, 1.0f };
        glTexImage2D(texTarget(white_tex), 0, GL_RGBA8, 1, 1, 0, GL_RGB, GL_FLOAT, data);
        useTexture(old_tex, 0);
    }

    return (white_tex);
}
Example #4
0
void OpenGLRenderer::setDrawState(const glm::mat4& model, DrawBuffer* draw,
                                  const Renderer::DrawParameters& p) {
    useDrawBuffer(draw);

    for (GLuint u = 0; u < p.textures.size(); ++u) {
        useTexture(u, p.textures[u]);
    }

    setBlend(p.blendMode);
    setDepthWrite(p.depthWrite);
    setDepthMode(p.depthMode);

    ObjectUniformData objectData{model,
                             glm::vec4(p.colour.r / 255.f, p.colour.g / 255.f,
                                       p.colour.b / 255.f, p.colour.a / 255.f),
                             1.f, 1.f, p.visibility};
    uploadUBO(UBOObject, objectData);

    drawCounter++;
#ifdef RW_GRAPHICS_STATS
    if (currentDebugDepth > 0) {
        profileInfo[currentDebugDepth - 1].draws++;
        profileInfo[currentDebugDepth - 1].primitives += p.count;
    }
#endif
}
Example #5
0
void po::drawTexturedRect(poTexture *tex, poRect rect, poRect coords) {
	GLfloat quad[4*3] = {
		rect.x,  rect.y, 0, 
		rect.x+rect.width, rect.y, 0, 
		rect.x+rect.width, rect.y+rect.height, 0,
		rect.x,  rect.y+rect.height, 0,
	};
	
	GLfloat tcoords[4*2] = {
		coords.x, coords.y+coords.height,
		coords.x+coords.width, coords.y+coords.height,
		coords.x+coords.width, coords.y,
		coords.x, coords.y,
	};
	
	useTexture(tex->getUid(), tex->hasAlpha());
	
	if(tex->getConfig().internalFormat == GL_ALPHA)
		useTex2DMaskShader();
	else
		useTex2DShader();
	
	updateActiveShader();
	
	glEnableVertexAttribArray(0);
	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, quad);
	glEnableVertexAttribArray(1);
	glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, tcoords);
	glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
	glDisableVertexAttribArray(0);
	glDisableVertexAttribArray(1);
}
Example #6
0
textureT* createTexture(void) {
    textureT* tex = malloc(sizeof(textureT));

    glGenTextures(1, &tex->id);
    tex->multisample = false;

    textureT* old_tex = useTexture(tex, 0);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    setTextureRepeat(tex, false);

    useTexture(old_tex, 0);

    return (tex);
}
Example #7
0
textureT* loadTextureFromMemory(const void* data) {
    textureT* tex = NULL;

    if (((uint8_t*)data)[0]=='B' && ((uint8_t*)data)[1]=='M')
        tex = loadBMP(data);

    if (!tex)
        return (NULL);

    textureT* old_tex = useTexture(tex, 0);

    //glGenerateMipmap(texTarget(tex));

    useTexture(old_tex, 0);

    return (tex);
}
Example #8
0
void freeTexture(textureT* tex) {
    // @To-do: Is this pointless?
    for (int i = 0; i < MaxTextures; i++) {
        if (active_textures[i] == tex)
            useTexture(NULL, i);
    }

    glDeleteTextures(1, &tex->id);
    free(tex);
}
CardProgram::CardProgram() : ShaderProgram(2)
{
    attachShader("card.vs");
    attachShader("card.fs");

    glBindAttribLocation(handle(), VERTEX, "CardVertex");
    glBindAttribLocation(handle(), TEXTURE, "CardTextureCoordinate");
    linkAndBind();
    glUniform1i(mUniformCardTexture, 0);
    useTexture(true);
}
Example #10
0
void OpenGLRenderer::drawBatched(const RenderList& list) {
    RW_PROFILE_SCOPE(__func__);
#if 0  // Needs shader changes
	// Determine how many batches we need to process the entire list
	auto entries = list.size();
	glBindBuffer(GL_UNIFORM_BUFFER, UBOObject);
	for (int b = 0; b < entries; b += maxObjectEntries)
	{
		auto toConsume = std::min((GLuint)entries, b + maxObjectEntries) - b;
		std::vector<ObjectUniformData> uploadBuffer;
		uploadBuffer.resize(toConsume);
		for (int d = 0; d < toConsume; ++d)
		{
			auto& draw = list[b+d];
			uploadBuffer[d] = {
				draw.model,
				glm::vec4(draw.drawInfo.colour.r/255.f,
				draw.drawInfo.colour.g/255.f,
				draw.drawInfo.colour.b/255.f, 1.f),
				1.f,
				1.f,
				draw.drawInfo.colour.a/255.f
			};
		}
		glBufferData(GL_UNIFORM_BUFFER,
					 toConsume * sizeof(ObjectUniformData),
					 uploadBuffer.data(),
					 GL_STREAM_DRAW);

		// Dispatch individual draws
		for (int d = 0; d < toConsume; ++d)
		{
			auto& draw = list[b+d];
			useDrawBuffer(draw.dbuff);

			for( GLuint u = 0; u < draw.drawInfo.textures.size(); ++u )
			{
				useTexture(u, draw.drawInfo.textures[u]);
			}

			glDrawElements(draw.dbuff->getFaceType(), draw.drawInfo.count, GL_UNSIGNED_INT,
                           reinterpret_cast<void*>(sizeof(RenderIndex) * draw.drawInfo.start));
		}
	}
#else
    for (auto& ri : list) {
        draw(ri.model, ri.dbuff, ri.drawInfo);
    }
#endif
}
Example #11
0
void Fence::Draw(ModelviewStack* ms)
{
	useTexture(FENCE_TEXTURE);
	setColour(1.0f, 1.0f, 1.0f);
	//vec3 c = vec3(1.0f, 1.0f, 1.0f);
	//setMaterial(0.4f * c, c, c, 60.0f);
	useLighting(0);
	ms->Push();
	{
		ms->Translate(_transform.position);
		ms->Rotate(_rotationAngle, _transform.rotation);
		ms->Scale(_transform.scale);
		drawSquare(*ms);
	}
	ms->Pop();
	useLighting(1);
}
Example #12
0
bool Engine::useShaders() {
	// Texture Loading
	// Add a map later to avoid loading the same texture multiple times.
	for (iter it = om.objects.begin(); it != om.objects.end(); it++) {
		std::string i = it->first;
		GameObject* current = om.objects.at(it->first).get();
		current->set_texture(useTexture(current->texDir, current->wrap));
	}

	// Shader Loading
	GLuint index = shader_manager.loadShaders("Shaders/vShader.glsl",
		"Shaders/fShader.glsl");
	if (index == true) {
		glUseProgram(shader_manager.getProgram());
		return true;
	}
	return false;
}
Example #13
0
void Billboard::Draw(ModelviewStack* ms)
{
	if (!Utility::isVisible(_transform.position, *_cameraPosition, *_cameraDirection))
		return;

	useTexture(_textureID);
	setColour(1.0, 1.0, 1.0);

	useLighting(0);

	ms->Push();
	{
		float height =  _transform.position.y + _transform.scale.y / 4;
		ms->Translate(vec3(_transform.position.x,
						   height,
						   _transform.position.z));

		ms->Rotate(_rotationAngle, vec3(0.0, 1.0, 0.0));
		ms->Scale(vec3(_transform.scale.x / 2, _transform.scale.y / 2, 1.0));
		
		drawSquare(*ms);
	}
	ms->Pop();
}
Example #14
0
void QuaternionTest::Draw(ModelviewStack* ms)
{
    useTexture(0);
    setColour(1.0, 1.0, 1.0);

    ms->Push();
    {
        ms->Mult(mat4_cast(_orientation));
        ms->Translate(_transform.position);

        vec4 pos4 = mat4_cast(_orientation) * vec4(1.0, 1.0, 1.0, 1.0);

        drawCube(*ms);
    }
    ms->Pop();

    setColour(0.0, 0.0, 0.0);
    ms->Push();
    {
        ms->Scale(vec3(0.25f, 0.25f, 0.25f));
        drawSphere(*ms);
    }
    ms->Pop();
}
Example #15
0
void CGraphics::_drawCylinder_TopTextured (float l, float r, float zoffset,int tex_id,bool robot)
{
//    glEnable(GL_BLEND);
//    glBlendFunc(GL_SRC_COLOR,GL_ONE_MINUS_SRC_COLOR);
    if (graphicDisabled) return;
  int i;
  float tmp,ny,nz,a,ca,sa;
  const int n = 24; // number of sides to the cylinder (divisible by 4)

  l *= 0.5;
  a = float(M_PI*2.0)/float(n);
  sa = (float) sin(a);
  ca = (float) cos(a);

  // draw cylinder body
  ny=1; nz=0;     // normal vector = (0,ny,nz)
  float nny,nnz;
  glBegin (GL_TRIANGLE_STRIP);
  for (i=0; i<=n; i++) {
      if ((i>2 && i<n-2) || (!robot))
      {
    glNormal3d (ny,nz,0);
    glVertex3d (ny*r,nz*r,l+zoffset);
    glNormal3d (ny,nz,0);
    glVertex3d (ny*r,nz*r,-l+zoffset);    
    }
    // rotate ny,nz
    tmp = ca*ny - sa*nz;
    nz = sa*ny + ca*nz;
    ny = tmp;
  }

  for (i=0;i<=1;i++)
  {
      tmp = ca*ny - sa*nz;
      nz = sa*ny + ca*nz;
      ny = tmp;
  }
  glNormal3d (ny,nz,0);
  glVertex3d (ny*r,nz*r,l+zoffset);
  glNormal3d (ny,nz,0);
  glVertex3d (ny*r,nz*r,-l+zoffset);
  glEnd();

  glDisable(GL_LIGHTING);
  useTexture(tex_id);

  // draw top cap
  glShadeModel (GL_FLAT);

  ny=1; nz=0;     // normal vector = (0,ny,nz)
  glBegin (GL_TRIANGLE_FAN);

  for (i=0; i<n; i++) {
      if ((i>2 && i<n-2)  || (!robot))
      {

    glNormal3d (0,0,1);
    glTexCoord2f(-0.5*nz+0.5,0.5*ny+0.5);
    glVertex3d (ny*r,nz*r,l+zoffset);
}
    // rotate ny,nz
    tmp = ca*ny - sa*nz;
    nz = sa*ny + ca*nz;
    ny = tmp;
  }
  glEnd();
  noTexture();
  glEnable(GL_LIGHTING);

  // draw bottom cap
  ny=1; nz=0;     // normal vector = (0,ny,nz)
  glBegin (GL_TRIANGLE_FAN);
  glNormal3d (0,0,-1);
  glVertex3d (0,0,-l+zoffset);
  for (i=0; i<=n; i++) {
      if ((i>=2 && i<n-2)  || (!robot))
      {

    glNormal3d (0,0,-1);
    glVertex3d (ny*r,nz*r,-l+zoffset);
}
    // rotate ny,nz
    tmp = ca*ny + sa*nz;
    nz = -sa*ny + ca*nz;
    ny = tmp;
  }
  glEnd();
//    glDisable(GL_BLEND);
}
Example #16
0
void drawText(const string* text, float x, float y, const string* font_name, int font_size) {
    text = (string*)wstrdup(text);

    HDC hdc = CreateCompatibleDC(0);

    string* font_face = wstrdup(font_name);
    int font_height = -MulDiv(font_size, GetDeviceCaps(hdc, LOGPIXELSY), 72);
    HFONT hfont = CreateFontW(font_height, 0, 0, 0, FW_NORMAL, FALSE, FALSE,
                              FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS,
                              CLIP_DEFAULT_PRECIS, PROOF_QUALITY,
                              DEFAULT_PITCH, font_face);

    free(font_face);

    SelectObject(hdc, hfont);

    SetBkMode(hdc, TRANSPARENT);
    SetTextColor(hdc, RGB(255, 0, 0));

    RECT rect = { 0 };
    DrawTextW(hdc, text, -1, &rect, DT_CALCRECT | DT_NOCLIP);

    int width  = rect.right  - rect.left + 2,
        height = rect.bottom - rect.top  + 2;
    rect.left++;
    rect.top++;

    void* bitmap_data = calloc(width*height, sizeof(uint32_t));
    for (int i = 3; i < width*height*4; i+= 4)
        *((uint8_t*)bitmap_data+i) = 0xff;

    HBITMAP hbitmap = CreateBitmap(width, height, 1, 32, bitmap_data);
    SelectObject(hdc, hbitmap);

    DrawTextW(hdc, text, -1, &rect, DT_TOP | DT_LEFT);
    DeleteObject(hfont);
    free(text);

    GetBitmapBits(hbitmap, width*height*4, bitmap_data);

    DeleteObject(hbitmap);
    DeleteDC(hdc);

    for (int i = 0; i < width*height*4; i += 4) {
        *((uint8_t*)bitmap_data+i+3) = *((uint8_t*)bitmap_data+i+2);
        *((uint8_t*)bitmap_data+i  ) = 0x10;
        *((uint8_t*)bitmap_data+i+1) = 0x10;
        *((uint8_t*)bitmap_data+i+2) = 0x10;
    }

    textureT* tex = createTexture();
    textureT* old_tex = useTexture(tex, 0);

    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_BGRA,
                 GL_UNSIGNED_BYTE, bitmap_data);

    free(bitmap_data);

    triMeshT* text_quad = createQuad(2.0f, 2.0f);

    if (!text_shader)
        initTextShader();

    shaderT* old_shader = useShader(text_shader);

    setShaderParam("ScreenSize", &(vec2) { (float)screenWidth(), (float)screenHeight() });
    setShaderParam("TextRect"  , &(vec4) { (float)x, (float)y, (float)width, (float)height });

    GLint depth_mask;
    glGetIntegerv(GL_DEPTH_WRITEMASK, &depth_mask);

    GLboolean cull_face, depth_test;
    glGetBooleanv(GL_CULL_FACE, &cull_face);
    glGetBooleanv(GL_DEPTH_TEST, &depth_test);

    glDepthMask(GL_FALSE);
    glDisable  (GL_CULL_FACE);
    glDisable  (GL_DEPTH_TEST);

    drawMesh(text_quad);

    glDepthMask(depth_mask);

    if (cull_face)  glEnable(GL_CULL_FACE);
    if (depth_test) glEnable(GL_DEPTH_TEST);

    useTexture (old_tex, 0);
    useShader  (old_shader);
    freeTexture(tex);
    freeMesh   (text_quad);
}
Example #17
0
void cRenderer::drawModel(uint16 model_index,uint16 tex0,uint16 tex1,uint16 tex2,uint16 tex3,uint16 tex4){
	useTexture(tex0,tex1,tex2,tex3,tex4);															//textúrák használata
	glBindVertexArray(this->meshes[model_index].vao);												//vertex array kötése (vao)
	glDrawElements(GL_TRIANGLES,this->meshes[model_index].indice_count,GL_UNSIGNED_INT,nullptr);	//vertex array kirajzolása
}