textureGen.cpp
资源名称:brm2.rar [点击查看]
上传用户:liujun12jf
上传日期:2022-07-12
资源大小:638k
文件大小:3k
源码类别:
OpenGL
开发平台:
Visual C++
- #include "textureGen.h"
- void FillArray(float *data, int size, float c)
- {
- for (int i=0 ; i < size ; i++)
- {
- data[i] = c;
- }
- }
- void GenTexture(GLuint *id, float *data, int size_x, int size_y, int type)
- {
- if (*id == 0) glGenTextures(1, id); // texture still not created
- glBindTexture(GL_TEXTURE_2D, *id);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexImage2D(GL_TEXTURE_2D, 0, type, size_x, size_y, 0, type, GL_FLOAT, data);
- }
- void CreateCircle(float *data, int size_x, int x_offs, int y_offs, float radius, float contrast)
- {
- float aspect = 3.14159f / radius;
- x_offs -= radius/2-2;
- y_offs -= radius/2;
- for (int y=0 ; y < radius ; y++){
- for (int x=0 ; x < radius ; x++)
- {
- float c = sin(x*aspect) + sin(y*aspect);
- c /= 2;
- c = pow(c, contrast);
- float cc = data[size_x * (y+y_offs) + x+x_offs];
- data[size_x * (y+y_offs) + x+x_offs] = c+cc;
- }}
- }
- GLuint CreateLineObjectTexture(unsigned int size) // returns opengl texture id
- {
- float contrast = 3;
- float *data = new float[size*size];
- int x_offs = size/2-3;
- int y_offs = 15;
- int line_x = 5;
- int line_y = size-y_offs*2;
- int circles_radius = y_offs;
- float qx = 3.14159f;
- float qy = 3.14159f;
- qx /= line_x;
- qy /= line_y;
- FillArray(data, size*size*1, 0);
- {
- for (int y=0 ; y < line_y ; y++){
- for (int x=0 ; x < line_x ; x++)
- {
- float c = sin(x*qx);
- c = pow(c, contrast);
- data[size * (y+y_offs) + x+x_offs] = c;
- }}
- }
- CreateCircle(data, size, x_offs, y_offs, circles_radius, contrast);
- CreateCircle(data, size, x_offs, y_offs+line_y, circles_radius, contrast);
- static GLuint id = 0;
- GenTexture(&id, data, size, size, GL_LUMINANCE);
- delete[] data;
- return id;
- }
- GLuint CreateStarTexture(unsigned int size) // returns opengl texture id
- {
- float contrast = 5;
- float q = 3.14159f;
- q /= size;
- float *data = new float[size*size];
- for (int y=0 ; y < size ; y++)
- {
- for (int x=0 ; x < size ; x++)
- {
- float c = ( sin(x*q) + sin(y*q) ) / 2;
- c = pow(c, contrast);
- data[size * y + x] = c;
- }
- }
- static GLuint id = 0;
- GenTexture(&id, data, size, size, GL_LUMINANCE);
- delete[] data;
- return id;
- }
- GLuint CreateOneColourTexture(unsigned int size) // returns opengl texture id
- {
- float *data = new float[size*size];
- for (int y=0 ; y < size ; y++)
- {
- for (int x=0 ; x < size ; x++)
- {
- data[size * y + x] = rnd(0.7f, 1);
- }
- }
- static GLuint id = 0;
- GenTexture(&id, data, size, size, GL_LUMINANCE);
- delete[] data;
- return id;
- }
- GLuint CreateChaosTexture(unsigned int size) // returns opengl texture id
- {
- float contrast = 3;
- float q = 3.14159f;
- q /= size;
- float *data = new float[size*size];
- for (int y=0 ; y < size ; y++)
- {
- for (int x=0 ; x < size ; x++)
- {
- float c = rnd(0, 1);
- c = pow(c, contrast);
- data[size * y + x] = c;
- }
- }
- static GLuint id = 0;
- GenTexture(&id, data, size, size, GL_LUMINANCE);
- delete[] data;
- return id;
- }
English
