vrchess

diff src/texture.cc @ 2:879194e4b1f0

fixed line-endings
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 25 Apr 2014 05:44:09 +0300
parents b326d53321f7
children 3c36bc28c6c2
line diff
     1.1 --- a/src/texture.cc	Fri Apr 25 05:43:26 2014 +0300
     1.2 +++ b/src/texture.cc	Fri Apr 25 05:44:09 2014 +0300
     1.3 @@ -1,77 +1,77 @@
     1.4 -#include "texture.h"
     1.5 -#include "opengl.h"
     1.6 -
     1.7 -Texture::Texture()
     1.8 -{
     1.9 -	tex = 0;
    1.10 -	type = GL_TEXTURE_2D;
    1.11 -}
    1.12 -
    1.13 -Texture::~Texture()
    1.14 -{
    1.15 -	destroy();
    1.16 -}
    1.17 -
    1.18 -void Texture::create2d(int xsz, int ysz)
    1.19 -{
    1.20 -	destroy();
    1.21 -
    1.22 -	type = GL_TEXTURE_2D;
    1.23 -	img.create(xsz, ysz);
    1.24 -
    1.25 -	if(!tex) {
    1.26 -		glGenTextures(1, &tex);
    1.27 -	}
    1.28 -	glBindTexture(type, tex);
    1.29 -	glTexParameteri(type, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    1.30 -	glTexParameteri(type, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    1.31 -	glTexImage2D(type, 0, GL_RGBA, xsz, ysz, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
    1.32 -}
    1.33 -
    1.34 -void Texture::destroy()
    1.35 -{
    1.36 -	if(tex) {
    1.37 -		glDeleteTextures(1, &tex);
    1.38 -	}
    1.39 -}
    1.40 -
    1.41 -void Texture::set_image(const Image &img)
    1.42 -{
    1.43 -	this->img = img;
    1.44 -	create2d(img.get_width(), img.get_height());
    1.45 -
    1.46 -	glTexSubImage2D(type, 0, 0, 0, img.get_width(), img.get_height(),
    1.47 -			GL_RGBA, GL_UNSIGNED_BYTE, img.get_pixels());
    1.48 -}
    1.49 -
    1.50 -Image &Texture::get_image()
    1.51 -{
    1.52 -	return img;
    1.53 -}
    1.54 -
    1.55 -const Image &Texture::get_image() const
    1.56 -{
    1.57 -	return img;
    1.58 -}
    1.59 -
    1.60 -unsigned int Texture::get_texture_id() const
    1.61 -{
    1.62 -	return tex;
    1.63 -}
    1.64 -
    1.65 -void Texture::bind(int tunit) const
    1.66 -{
    1.67 -	glActiveTextureARB(GL_TEXTURE0_ARB + tunit);
    1.68 -	glBindTexture(type, tex);
    1.69 -	glActiveTextureARB(GL_TEXTURE0_ARB);
    1.70 -}
    1.71 -
    1.72 -bool Texture::load(const char *fname)
    1.73 -{
    1.74 -	Image image;
    1.75 -	if(!image.load(fname)) {
    1.76 -		return false;
    1.77 -	}
    1.78 -	set_image(image);
    1.79 -	return true;
    1.80 -}
    1.81 \ No newline at end of file
    1.82 +#include "texture.h"
    1.83 +#include "opengl.h"
    1.84 +
    1.85 +Texture::Texture()
    1.86 +{
    1.87 +	tex = 0;
    1.88 +	type = GL_TEXTURE_2D;
    1.89 +}
    1.90 +
    1.91 +Texture::~Texture()
    1.92 +{
    1.93 +	destroy();
    1.94 +}
    1.95 +
    1.96 +void Texture::create2d(int xsz, int ysz)
    1.97 +{
    1.98 +	destroy();
    1.99 +
   1.100 +	type = GL_TEXTURE_2D;
   1.101 +	img.create(xsz, ysz);
   1.102 +
   1.103 +	if(!tex) {
   1.104 +		glGenTextures(1, &tex);
   1.105 +	}
   1.106 +	glBindTexture(type, tex);
   1.107 +	glTexParameteri(type, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
   1.108 +	glTexParameteri(type, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
   1.109 +	glTexImage2D(type, 0, GL_RGBA, xsz, ysz, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
   1.110 +}
   1.111 +
   1.112 +void Texture::destroy()
   1.113 +{
   1.114 +	if(tex) {
   1.115 +		glDeleteTextures(1, &tex);
   1.116 +	}
   1.117 +}
   1.118 +
   1.119 +void Texture::set_image(const Image &img)
   1.120 +{
   1.121 +	this->img = img;
   1.122 +	create2d(img.get_width(), img.get_height());
   1.123 +
   1.124 +	glTexSubImage2D(type, 0, 0, 0, img.get_width(), img.get_height(),
   1.125 +			GL_RGBA, GL_UNSIGNED_BYTE, img.get_pixels());
   1.126 +}
   1.127 +
   1.128 +Image &Texture::get_image()
   1.129 +{
   1.130 +	return img;
   1.131 +}
   1.132 +
   1.133 +const Image &Texture::get_image() const
   1.134 +{
   1.135 +	return img;
   1.136 +}
   1.137 +
   1.138 +unsigned int Texture::get_texture_id() const
   1.139 +{
   1.140 +	return tex;
   1.141 +}
   1.142 +
   1.143 +void Texture::bind(int tunit) const
   1.144 +{
   1.145 +	glActiveTextureARB(GL_TEXTURE0_ARB + tunit);
   1.146 +	glBindTexture(type, tex);
   1.147 +	glActiveTextureARB(GL_TEXTURE0_ARB);
   1.148 +}
   1.149 +
   1.150 +bool Texture::load(const char *fname)
   1.151 +{
   1.152 +	Image image;
   1.153 +	if(!image.load(fname)) {
   1.154 +		return false;
   1.155 +	}
   1.156 +	set_image(image);
   1.157 +	return true;
   1.158 +}