Table of contents
1.
Introduction
2.
About Cinder
3.
Textures in Cinder
4.
Frequently Asked Questions
4.1.
Why use Cinder?
4.2.
What is OpenGL in Cinder?
4.3.
What is CinderBlocks?
4.4.
What is TinderBox?
4.5.
What distinguishes Cinder from C++-based open frameworks?
5.
Conclusion
Last Updated: Mar 27, 2024
Medium

Cinder-Textures

Author Ayush Mishra
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Hey! Ninjas, As the name suggests, Textures are surface characteristics and appearance of an object determined by its size, density, shape, and arrangement.  So, Ninjas, can you know about using texture in the cinder framework? If not, read the article to know about it. In this blog, we will discuss Cinder-Textures in deep detail. Let’s start going!

Cinder-Textures

About Cinder

Cinder is a C++ library for programming with an eye toward appearance, also known as creative coding. This covers areas like computational geometry, audio, video, and graphics. With official support for macOS, Windows, Linux, iOS, and Windows UWP, Cinder is cross-platform.

Cinder is a powerful, production-tested tool that can serve as a professional's primary tool while also being appropriate for learning and experimentation.

Textures in Cinder

Cinder-textures exposes this functionality through the class gl::Texture2d and its siblings, representing images in OpenGL as textures. It increases the surface characteristics and appearance of the object in the image by changing its size, density and functionality.

Let’s look at the given below example to understand cinder-textures:-

class NinjasApp: public App {
  public: void setup() override;
  void draw() override;

  gl::Texture2dRef mTex;
};

void NinjasApp::setup() {
  auto img = loadImage(loadAsset("clouds.jpg"));
  mTex = gl::Texture2d::create(img);
}

void NinjasApp::draw() {
  gl::clear();
  gl::draw(mTex);
}


Output:

Textures in Cinder

We can also apply one (or more) a process known as texture mapping to the vertices of a 2D or 3D model. Let's understand from the example given below.

class NinjasApp: public App {
  public: void setup() override;
  void draw() override;

  CameraPersp mCam;
  gl::BatchRef mSphere;
  gl::TextureRef mTexture;
  gl::GlslProgRef mGlsl;
};

void NinjasApp::setup() {
  mCam.lookAt(vec3(3, 2, 4), vec3(0));

  auto img = loadImage(loadAsset("checkerboard.png"));
  mTexture = gl::Texture::create(img);
  mTexture -> bind();

  auto shader = gl::ShaderDef().texture().lambert();
  mGlsl = gl::getStockShader(shader);
  auto sphere = geom::Sphere().subdivisions(50);
  mSphere = gl::Batch::create(sphere, mGlsl);

  gl::enableDepthWrite();
  gl::enableDepthRead();
}

void NinjasApp::draw() {
  gl::clear(Color(0.2 f, 0.2 f, 0.2 f));
  gl::setMatrices(mCam);

  mSphere -> draw();

  // Draw the texture itself in the upper right corner
  gl::setMatricesWindow(getWindowSize());
  Rectf drawRect(0, 0, mTexture -> getWidth() / 3,
    mTexture -> getHeight() / 3);
  gl::draw(mTexture, drawRect);
}


Output:

output of cinder texture

Similar to the previous example, we load the cinder-textures from a checkerboard.png file in this one. But in this instance, we're creating a gl::GlslProg from a gl::ShaderDef that has both texture(), and lambert() applied.

We are using the bind() method on mTexture, another important distinction. Making a texture active is known as binding that texture. Since we always bind just one texture, we do this from setup().

By calling mSphere->draw in the draw() method, the sphere is drawn (). Finally, for illustrational purposes, we draw the texture itself.

Frequently Asked Questions

Why use Cinder?

The library is suitable for highly abstract projects, such as art installations, advertising campaigns, and other advanced animation work, because it combines Cinder with quick C++.

What is OpenGL in Cinder?

With a focus on GPU hardware acceleration, OpenGL is an open standard for graphics programming. On Microsoft Windows and OS X, Cinder supports desktop OpenGL, and on iOS and Android, Cinder supports the OpenGL ES API.

What is CinderBlocks?

A prepackaged set of code and libraries called a CinderBlock implements a feature or exposes a library in Cinder. This includes standalone implementations of features like TUIO support and bridges to libraries like OpenCV and FMOD.

What is TinderBox?

TinderBox is a program that comes with Cinder and makes it easier to start new projects. It has the ability to produce Xcode and Visual Studio projects. CinderBlocks can also be integrated into your program.

What distinguishes Cinder from C++-based open frameworks?

Better performance is achieved by Cinder using system-specific libraries, whereas openFrameworks offers greater control over the underlying libraries.

Conclusion

Congratulations on finishing the blog! We have discussed the Cinder-Textures. We further discussed the working of Cinder on the image's texture with an example.

We hope this blog has helped you enhance your knowledge of Cinder-Textures. Do not stop learning! We recommend you read some of our articles related to cinder-textures: 

Refer to our Guided Path to upskill yourself in DSACompetitive ProgrammingJavaScriptSystem Design, and many more! If you want to test your competency in coding, check out the mock test series and participate in the contests hosted on Coding Ninjas Studio!

But you have just started your learning process and are looking for questions from tech giants like Amazon, Microsoft, Uber, etc. For placement preparations, you must look at the problemsinterview experiences, and interview bundles.

We wish you Good Luck! 

Happy Learning!

Live masterclass