Skip to content
Snippets Groups Projects
Commit 0a853665 authored by Ansgar Philippsen's avatar Ansgar Philippsen
Browse files

added texture to gfx; fixed gl includes

parent 9480a02f
Branches
Tags
No related merge requests found
......@@ -19,13 +19,14 @@
#include <boost/python.hpp>
using namespace boost::python;
#include <ost/gfx/module_config.hh>
#if OST_SHADER_SUPPORT_ENABLED
#include <ost/gfx/shader.hh>
#endif
#include <ost/info/info.hh>
#include <ost/gfx/prim_list.hh>
#include <ost/gfx/gradient.hh>
#include <ost/gfx/gfx_test_object.hh>
#if OST_SHADER_SUPPORT_ENABLED
#include <ost/gfx/shader.hh>
#endif
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
extern void export_Scene();
......
......@@ -22,6 +22,7 @@ prim_list.hh
scene.hh
selection.hh
surface.hh
texture.hh
vertex_array.hh
vertex_array_helper.hh
scene_observer.hh
......@@ -90,9 +91,7 @@ bitmap_io.cc
color.cc
primitives.cc
entity.cc
symmetry_node.cc
gfx_node.cc
gfx_object.cc
gfx_prim.cc
......@@ -107,6 +106,7 @@ vertex_array.cc
vertex_array_helper.cc
material.cc
povray.cc
texture.cc
color_ops/color_op.cc
color_ops/by_element_color_op.cc
color_ops/by_chain_color_op.cc
......
......@@ -148,7 +148,7 @@ Bitmap import_png(const String& filename)
channels=png_get_channels(png_ptr,info_ptr);
if(channels<1 || channels>4) {
LOGN_ERROR("error importing bitmap: " << filename << " has " << channels << " channels, excpected 1-4");
LOGN_ERROR("error importing bitmap: " << filename << " has " << channels << " channels, expected 1-4");
return bm;
}
......
......@@ -26,6 +26,7 @@
#include <boost/filesystem/fstream.hpp>
#include <ost/platform.hh>
#include "texture.hh"
#include "glext_include.hh"
#include "gfx_test_object.hh"
#include "scene.hh"
......@@ -59,8 +60,8 @@ GfxTestObj::GfxTestObj():
String ost_root=GetSharedDataPath();
bf::path ost_root_dir(ost_root);
bf::path tex_file(ost_root_dir / "textures/test_texture.png");
Bitmap bm = BitmapImport(tex_file.string(),".png");
if(!bm.data) {
Texture tex(BitmapImport(tex_file.string(),".png"));
if(!tex.IsValid()) {
LOGN_ERROR("error loading " << tex_file.string());
} else {
LOGN_VERBOSE("importing tex with id " << tex_id);
......@@ -70,11 +71,7 @@ GfxTestObj::GfxTestObj():
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
if(bm.channels==3) {
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,bm.width,bm.height,0,GL_RGB,GL_UNSIGNED_BYTE,bm.data.get());
} else if(bm.channels==4) {
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,bm.width,bm.height,0,GL_RGBA,GL_UNSIGNED_BYTE,bm.data.get());
}
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,tex.width(),tex.height(),tex.border(),tex.format(),tex.type(),tex.data());
}
}
......
......@@ -26,7 +26,7 @@
*/
#include "gfx_object.hh"
#include "gl_include.hh"
#include "glext_include.hh"
namespace ost { namespace gfx {
......
......@@ -36,7 +36,6 @@ Author: Juergen Haas
#include <ost/geom/vec3.hh>
#include "glext_include.hh"
#include "gl_include.hh"
#include <ost/log.hh>
......
......@@ -29,8 +29,8 @@
#include <ost/geom/geom.hh>
#include <ost/img/map.hh>
#include <ost/gfx/gl_include.hh>
#include "glext_include.hh"
#include "gfx_object.hh"
namespace ost { namespace gfx {
......
......@@ -32,6 +32,7 @@
#include <ost/gfx/module_config.hh>
#include <ost/mol/transform.hh>
#include "gl_include.hh"
#include "color.hh"
#include "gfx_object_fw.hh"
#include "gfx_node_fw.hh"
......@@ -40,7 +41,6 @@
#include "glwin_base.hh"
#include "scene_observer.hh"
#include "gfx_prim.hh"
#include "gl_include.hh"
#include "povray_fw.hh"
namespace ost { namespace gfx {
......
......@@ -29,7 +29,7 @@
#include <map>
#include <stack>
#include <ost/gfx/module_config.hh>
#include "gl_include.hh"
#include "glext_include.hh"
namespace ost { namespace gfx {
......
#include "texture.hh"
namespace ost { namespace gfx {
Texture::Texture(const Bitmap& bm):
w_(bm.width), h_(bm.height),
d_()
{
if(!bm.data) return;
d_=boost::shared_array<Color>(new Color[w_*h_]);
static float f=1.0/255.0;
for(GLint v=0;v<h_;++v) {
for(GLint u=0;u<w_;++u) {
int p=v*w_+u;
Color& c = d_[p];
if(bm.channels==1) {
c[0]=f*static_cast<float>(bm.data[p]);
c[1]=c[0];
c[2]=c[0];
c[3]=1.0;
} else if(bm.channels==2) {
c[0]=f*static_cast<float>(bm.data[p*2+0]);
c[1]=c[0];
c[2]=c[0];
c[3]=f*static_cast<float>(bm.data[p*2+1]);
} else if(bm.channels==3) {
c[0]=f*static_cast<float>(bm.data[p*3+0]);
c[1]=f*static_cast<float>(bm.data[p*3+1]);
c[2]=f*static_cast<float>(bm.data[p*3+2]);
c[3]=1.0;
} else if(bm.channels==4) {
c[0]=f*static_cast<float>(bm.data[p*4+0]);
c[1]=f*static_cast<float>(bm.data[p*4+1]);
c[2]=f*static_cast<float>(bm.data[p*4+2]);
c[2]=f*static_cast<float>(bm.data[p*4+3]);
}
}
}
}
}}
//------------------------------------------------------------------------------
// This file is part of the OpenStructure project <www.openstructure.org>
//
// Copyright (C) 2008-2010 by the OpenStructure authors
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License as published by the Free
// Software Foundation; either version 3.0 of the License, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
// details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this library; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//------------------------------------------------------------------------------
#ifndef OST_GFX_TEXTURE_HH
#define OST_GFX_TEXTURE_HH
/*
texture
Author: Ansgar Philippsen
*/
#include <boost/shared_array.hpp>
#include "module_config.hh"
#include "glext_include.hh"
#include "color.hh"
#include "bitmap_io.hh"
namespace ost { namespace gfx {
class Texture
{
public:
Texture():
w_(0),
h_(0),
d_()
{}
Texture(GLint w, GLint h):
w_(w),
h_(h),
d_(new Color[w*h])
{}
Texture(const Bitmap& b);
bool IsValid() const {return d_;}
Color& operator()(uint u, uint v) {return d_[v*w_+u];}
const Color& operator()(uint u, uint v) const {return d_[v*w_+u];}
float* data() {return d_[0];}
GLint width() const {return w_;}
GLint height() const {return h_;}
GLint format() const {return GL_RGBA;}
GLint type() const {return GL_FLOAT;}
GLint border() const {return 0;}
private:
GLint w_,h_;
boost::shared_array<Color> d_;
};
}} // ns
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment