示例#1
0
/*
 * Load and create all of our resources:
 */
static int make_resources(void)
{
    g_resources.vertex_buffer = make_buffer(
        GL_ARRAY_BUFFER,
        g_vertex_buffer_data,
        sizeof(g_vertex_buffer_data)
        );
    g_resources.element_buffer = make_buffer(
        GL_ELEMENT_ARRAY_BUFFER,
        g_element_buffer_data,
        sizeof(g_element_buffer_data)
        );

    g_resources.textures[0] = make_texture("data/hello1.tga");
    g_resources.textures[1] = make_texture("data/hello2.tga");

    if (g_resources.textures[0] == 0 || g_resources.textures[1] == 0)
        return 0;

    g_resources.vertex_shader = make_shader(
        GL_VERTEX_SHADER,
        "hello-gl.v.glsl"
        );
    if (g_resources.vertex_shader == 0)
        return 0;

    g_resources.fragment_shader = make_shader(
        GL_FRAGMENT_SHADER,
        "hello-gl.f.glsl"
        );
    if (g_resources.fragment_shader == 0)
        return 0;

    g_resources.program = make_program(g_resources.vertex_shader, g_resources.fragment_shader);
    if (g_resources.program == 0)
        return 0;

    g_resources.uniforms.fade_factor
        = glGetUniformLocation(g_resources.program, "fade_factor");
    g_resources.uniforms.textures[0]
        = glGetUniformLocation(g_resources.program, "textures[0]");
    g_resources.uniforms.textures[1]
        = glGetUniformLocation(g_resources.program, "textures[1]");

    g_resources.attributes.position
        = glGetAttribLocation(g_resources.program, "position");

    return 1;
}
示例#2
0
OOBase::SharedPtr<Indigo::Render::UIDrawable> Indigo::NinePatch::make_drawable(const glm::vec4& colour, bool visible, const glm::ivec2& position, const glm::uvec2& size) const
{
	ASSERT_RENDER_THREAD();

	if (!valid())
		LOG_ERROR_RETURN(("NinePatch::make_drawable called when invalid!"),OOBase::SharedPtr<Indigo::Render::UIDrawable>());

	bool is_9 = (m_info->m_borders != glm::uvec4(0));
	bool cached = true;

	OOBase::SharedPtr<OOGL::Texture> texture = make_texture(GL_RGBA8,cached,is_9 ? 1 : 0);
	if (!texture)
		return OOBase::SharedPtr<Indigo::Render::UIDrawable>();

	if (cached)
	{
		texture->parameter(GL_TEXTURE_MAG_FILTER,GL_LINEAR);
		texture->parameter(GL_TEXTURE_MIN_FILTER,is_9 ? GL_LINEAR : GL_LINEAR_MIPMAP_LINEAR);
		texture->parameter(GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
		texture->parameter(GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
	}

	if (is_9)
		return OOBase::allocate_shared<Render::UINinePatch,OOBase::ThreadLocalAllocator>(texture,colour,m_info,visible,position,size);
	else
		return OOBase::allocate_shared<Render::UIImage,OOBase::ThreadLocalAllocator>(texture,colour,visible,position,size);
}
示例#3
0
static void
init(void)
{
   static const GLfloat red[4] = {1, 0, 0, 0};
   static const GLfloat white[4] = {1.0, 1.0, 1.0, 1.0};
   static const GLfloat diffuse[4] = {0.7, 0.7, 0.7, 1.0};
   static const GLfloat specular[4] = {0.001, 0.001, 0.001, 1.0};
   static const GLfloat pos[4] = {20, 20, 50, 1};

   glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, red);
   glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, white);
   glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 9.0);

   glEnable(GL_LIGHTING);
   glEnable(GL_LIGHT0);
   glLightfv(GL_LIGHT0, GL_POSITION, pos);
   glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
   glLightfv(GL_LIGHT0, GL_SPECULAR, specular);

   glClearColor(0.4, 0.4, 0.4, 0.0);
   glEnable(GL_DEPTH_TEST);

   make_texture();
   glEnable(GL_TEXTURE_2D);

   /* Enable automatic normalizing to get proper lighting when torus is
    * scaled down via glScalef
    */
   glEnable(GL_NORMALIZE);
}
示例#4
0
void
test_backface_culling (void)
{
  TestState state;
  CoglTexture *tex;

  state.width = cogl_framebuffer_get_width (test_fb);
  state.height = cogl_framebuffer_get_height (test_fb);

  state.offscreen = NULL;

  state.texture = make_texture ();

  tex = cogl_texture_new_with_size (state.width, state.height,
                                    COGL_TEXTURE_NO_SLICING,
                                    COGL_PIXEL_FORMAT_ANY); /* internal fmt */
  state.offscreen = COGL_FRAMEBUFFER (cogl_offscreen_new_to_texture (tex));
  state.offscreen_tex = tex;

  paint (&state);

  cogl_object_unref (state.offscreen);
  cogl_object_unref (state.offscreen_tex);
  cogl_object_unref (state.texture);

  if (cogl_test_verbose ())
    g_print ("OK\n");
}
示例#5
0
static void
key(unsigned char key)
{
   switch (key) {
   case ' ':
      animate = !animate;
      break;
   case 't':
      {
         GLint size;
         tex_format = (tex_format + 1) % (NUM_CPAL_FORMATS + 1);
         if (tex_format < NUM_CPAL_FORMATS) {
            size = make_cpal_texture(tex_format);
            printf("Using %s (%d bytes)\n",
                  cpal_formats[tex_format].name, size);
         }
         else {
            size = make_texture();
            printf("Using uncompressed texture (%d bytes)\n", size);
         }

         eglutPostRedisplay();
      }
      break;
   case 27:
      eglutDestroyWindow(win);
      exit(0);
      break;
   default:
      break;
   }
}
示例#6
0
文件: texture.cpp 项目: rolfrm/pigame
Texture make_texture(const char * _path, int interp_param, int wrap_param){
  std::string path(_path);
  ILuint ilid;
  ilGenImages(1,&ilid);
  ilBindImage(ilid);

  if(ilLoadImage(path.c_str())){
    std::cout<<"texture "<<path<<" loaded\n";
    ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);
    
  }else{
    std::cout << "Problems converting image" <<path<<"\n";
  }
	
  std::cout<<ilGetInteger(IL_IMAGE_WIDTH)<<" "<< ilGetInteger(IL_IMAGE_HEIGHT)
<<" dimensions\n";	
  Texture temp = make_texture((void *)ilGetData(),ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT),4,interp_param,wrap_param);
  int error = glGetError();
  if(error != 0){
    std::cout << "Error loading texture: " << error << "\n";
  }
  ilDeleteImage(ilid);
 
  return temp;
	
}
示例#7
0
文件: texture.cpp 项目: rolfrm/pigame
void texture_test(){
	unsigned char data[8] = {1,2,3,4,5,6,7,8};
	Texture tex = make_texture(data,4,2,1);	
	Texture tex2 = cpy_tex(tex2);
	del_tex(tex2);
	del_tex(tex);
}	
示例#8
0
ENTRYPOINT void 
init_rubikblocks(ModeInfo *mi) 
{
  rubikblocks_conf *cp;
  if(!rubikblocks) 
  {
    rubikblocks = (rubikblocks_conf *)calloc(MI_NUM_SCREENS(mi), sizeof(rubikblocks_conf));
    if(!rubikblocks) return;
  }
  cp = &rubikblocks[MI_SCREEN(mi)];

  if(tex)
    make_texture(cp);

  if ((cp->glx_context = init_GL(mi)) != NULL) 
  {
    init_gl(mi);
    init_cp(cp);
    init_lists(cp);
    reshape_rubikblocks(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
  }
  else 
  {
    MI_CLEARWINDOW(mi);
  }
}
示例#9
0
static void
paint (void)
{
  cg_pipeline_t *pipeline = cg_pipeline_new (test_dev);
  cg_texture_t *texture = make_texture ();
  int y, x;

  cg_pipeline_set_layer_texture (pipeline, 0, texture);

  /* Just render the texture in the top left corner */
  /* Render the texture using four separate rectangles */
  for (y = 0; y < 2; y++)
    for (x = 0; x < 2; x++)
      cg_framebuffer_draw_textured_rectangle (test_fb,
                                                pipeline,
                                                x * TEXTURE_RENDER_SIZE / 2,
                                                y * TEXTURE_RENDER_SIZE / 2,
                                                (x + 1) *
                                                TEXTURE_RENDER_SIZE / 2,
                                                (y + 1) *
                                                TEXTURE_RENDER_SIZE / 2,
                                                x / 2.0f,
                                                y / 2.0f,
                                                (x + 1) / 2.0f,
                                                (y + 1) / 2.0f);

  cg_object_unref (pipeline);
  cg_object_unref (texture);
}
示例#10
0
ENTRYPOINT void init_cube21(ModeInfo *mi) 
{
  cube21_conf *cp;
  MI_INIT(mi, cube21);
  cp = &cube21[MI_SCREEN(mi)];

  cp->trackball = gltrackball_init (False);

  if(!cp->texp) {
    init_posc(cp);
    make_texture(cp);
  }

#ifdef HAVE_MOBILE
  size *= 2;
#endif

  if ((cp->glx_context = init_GL(mi)) != NULL) {
    init_gl(mi);
    init_cp(cp);
    reshape_cube21(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
  } else {
    MI_CLEARWINDOW(mi);
  }
}
示例#11
0
static PyObject* image_preload( PyObject* self )
{
    make_texture( (ImageObject*)self );

    Py_INCREF( Py_None );
    return Py_None;
}
示例#12
0
void
test_cogl_backface_culling (TestUtilsGTestFixture *fixture,
                            void *data)
{
  TestUtilsSharedState *shared_state = data;
  TestState state;
  CoglHandle tex;

  state.fb = shared_state->fb;
  state.width = cogl_framebuffer_get_width (shared_state->fb);
  state.height = cogl_framebuffer_get_height (shared_state->fb);

  state.offscreen = COGL_INVALID_HANDLE;

  state.texture = make_texture ();

  tex = cogl_texture_new_with_size (state.width, state.height,
                                    COGL_TEXTURE_NO_SLICING,
                                    COGL_PIXEL_FORMAT_ANY); /* internal fmt */
  state.offscreen = cogl_offscreen_new_to_texture (tex);
  state.offscreen_tex = tex;

  paint (&state);

  cogl_object_unref (state.offscreen);
  cogl_handle_unref (state.offscreen_tex);
  cogl_handle_unref (state.texture);

  if (g_test_verbose ())
    g_print ("OK\n");
}
示例#13
0
文件: flag.c 项目: jckarter/ch5-flag
static int make_resources(void)
{
    GLuint vertex_shader, fragment_shader, program;

    g_resources.flag_vertex_array = init_flag_mesh(&g_resources.flag);
    init_background_mesh(&g_resources.background);

    g_resources.flag.texture = make_texture("flag.tga");
    g_resources.background.texture = make_texture("background.tga");

    if (!make_shadow_framebuffer(
        &g_resources.shadowmap_texture,
        &g_resources.shadowmap_framebuffer
    )) {
        return 0;
    }

    if (g_resources.flag.texture == 0 || g_resources.background.texture == 0)
        return 0;

    struct flag_shaders shaders;

    if (!make_flag_programs(&shaders))
        return 0;

    enact_flag_programs(&shaders);

    g_resources.eye_offset[0] = 0.0f;
    g_resources.eye_offset[1] = 0.0f;
    g_resources.window_size[0] = INITIAL_WINDOW_WIDTH;
    g_resources.window_size[1] = INITIAL_WINDOW_HEIGHT;

    g_resources.light_direction[0] =  0.408248;
    g_resources.light_direction[1] = -0.816497;
    g_resources.light_direction[2] =  0.408248;

    update_p_matrix(
        g_resources.p_matrix,
        INITIAL_WINDOW_WIDTH,
        INITIAL_WINDOW_HEIGHT
    );
    update_mv_matrix(g_resources.mv_matrix, g_resources.eye_offset);
    update_shadow_matrix(g_resources.shadow_matrix, g_resources.light_direction);

    return 1;
}
示例#14
0
void init_scene()
{
   static GLfloat lightpos[4]={50.0f, 50.0f, -320.f, 1.0f};
   GLubyte* tex;

   /* Clear error */
   glGetError();

   /* draw a perspective scene */
   glMatrixMode(GL_PROJECTION);
   glFrustumf(-100.f, 100.f, -100.f, 100.f, 320.f, 640.f);
   glMatrixMode(GL_MODELVIEW);

   /* turn on features */
   glEnable(GL_DEPTH_TEST);
   glEnable(GL_LIGHTING);
   glEnable(GL_LIGHT0);

   /* place light 0 in the right place */
   glLightfv(GL_LIGHT0, GL_POSITION, lightpos);

   /* enable filtering */
   glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
   glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

   tex=make_texture(256, 256);
   glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 256, 256, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, tex);
   free(tex);

   disk_fill=gluNewQuadric();
   gluQuadricDrawStyle(disk_fill, GLU_FILL);
   gluQuadricNormals(disk_fill, GLU_SMOOTH);

   disk_fill_flat=gluNewQuadric();
   gluQuadricDrawStyle(disk_fill_flat, GLU_FILL);
   gluQuadricNormals(disk_fill_flat, GLU_FLAT);

   disk_fill_texture=gluNewQuadric();
   gluQuadricDrawStyle(disk_fill_texture, GLU_FILL);
   gluQuadricNormals(disk_fill_texture, GLU_SMOOTH);
   gluQuadricTexture(disk_fill_texture, GLU_TRUE);

   disk_point=gluNewQuadric();
   gluQuadricDrawStyle(disk_point, GLU_POINT);
   gluQuadricNormals(disk_point, GLU_SMOOTH);

   disk_line=gluNewQuadric();
   gluQuadricDrawStyle(disk_line, GLU_LINE);
   gluQuadricNormals(disk_line, GLU_SMOOTH);

   disk_silh=gluNewQuadric();
   gluQuadricDrawStyle(disk_silh, GLU_SILHOUETTE);

   if (glGetError())
   {
      printf("Oops! I screwed up my OpenGL ES calls somewhere\n");
   }
}
示例#15
0
            // TODO: fix
            void font::render_to( SDL_Renderer* renderer, std::string const& s )
            {
                auto tex = make_texture( renderer, s );
                int w, h;
                ::SDL_QueryTexture( tex.get(), nullptr, nullptr, &w, &h );
                ::SDL_Rect render_quad = { 0, 0, w, h };

                SDL_RenderCopy( renderer, tex.get(), nullptr, &render_quad );
            }
示例#16
0
		inline GLuint make_texture(std::string fileName, GLint minFilter, GLint magFilter)
		{
			GLuint tex = make_texture(fileName);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magFilter);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
			return tex;
		}
示例#17
0
/** c-tor used for creation text using TTF
    text -- text, used for texture cration
    font -- contains font and size of text
    color -- color of text
    x, y, w, h -- position and size of texture
    w, h defaulted to 0 (means they'll use texture w and h)*/
Texture::Texture(std::string text, TTF_Font* font, SDL_Color text_color,
                 uint16_t x, uint16_t y, uint16_t w, uint16_t h)
    : form( {
    x, y, w, h
}) {
    obj_counter++;
    path = "text";
    //making surface with text
    make_texture(TTF_RenderText_Solid(font, text.c_str(), text_color));
}
示例#18
0
// not this function take the vertex shader file as input
static int make_resources(const char *vertex_shader_file)
{
    g_resources.vertex_buffer = make_buffer(GL_ARRAY_BUFFER,
                                            g_vertex_buffer_data,
                                            sizeof(g_vertex_buffer_data));
    g_resources.element_buffer = make_buffer(GL_ELEMENT_ARRAY_BUFFER,
                                 g_element_buffer_data,
                                 sizeof(g_element_buffer_data));
    /* make textures*/
    g_resources.textures[0] = make_texture("hello1.tga");
    g_resources.textures[1] = make_texture("hello2.tga");
    if(g_resources.textures[0] == 0 || g_resources.textures[1] == 0)
    {
        return 0;
    }

    /*make shaders */
    g_resources.vertex_shader = make_shader(GL_VERTEX_SHADER, vertex_shader_file);
    if(g_resources.vertex_shader == 0)
    {
        return 0;
    }
    g_resources.fragment_shader = make_shader(GL_FRAGMENT_SHADER, "hello-gl.f.glsl");
    if(g_resources.fragment_shader == 0)
    {
        return 0;
    }

    g_resources.program = make_program(g_resources.vertex_shader, g_resources.fragment_shader);
    if(g_resources.program == 0)
    {
        return 0;
    }

    g_resources.uniforms.timer = glGetUniformLocation(g_resources.program, "timer");
    g_resources.uniforms.textures[0] = glGetUniformLocation(g_resources.program, "textures[0]");
    g_resources.uniforms.textures[1] = glGetUniformLocation(g_resources.program, "textures[1]");

    g_resources.attributes.position = glGetAttribLocation(g_resources.program, "position");

    return 1;
}
示例#19
0
文件: texture.cpp 项目: rolfrm/pigame
Texture get_texture(std::string path){
  std::map<std::string,Texture>::iterator it=TextureMap.find(path);
  if(it==TextureMap.end()){
    Texture temptex=make_texture(path.c_str());
    TextureMap.insert(std::pair<std::string,Texture>(path,temptex));
    it=TextureMap.find(path);
  }

  return it->second;
	
}
示例#20
0
bool
ImageBufAlgo::make_texture (ImageBufAlgo::MakeTextureMode mode,
                            const std::string &filename,
                            const std::string &outputfilename,
                            const ImageSpec &configspec,
                            std::ostream *outstream)
{
    std::vector<std::string> filenames;
    filenames.push_back (filename);
    return make_texture (mode, filenames, outputfilename, configspec, outstream);
}
示例#21
0
void init_scene(int width, int height)
{
   static GLfloat lightpos[4]={50.0f, 50.0f, -320.f, 1.0f};
   GLubyte* tex;

   if (height==0)
   {
      height=1;
   }

   /* Clear error */
   glGetError();

   /* Setup our viewport */
   glViewport(0, 0, (GLint)width, (GLint)height);

   /* draw a perspective scene */
   glMatrixMode(GL_PROJECTION);
   gluPerspective(35.0f, (GLfloat)width/(GLfloat)height, 320.0f, 6000.0f);

   glMatrixMode(GL_MODELVIEW);

   /* turn on features */
   glEnable(GL_DEPTH_TEST);
   glEnable(GL_LIGHTING);
   glEnable(GL_LIGHT0);

   /* place light 0 in the right place */
   glLightfv(GL_LIGHT0, GL_POSITION, lightpos);

   /* enable filtering */
   glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
   glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

   tex=make_texture(512, 512);
   gluBuild2DMipmaps(GL_TEXTURE_2D, GL_LUMINANCE, 512, 512, GL_LUMINANCE,
                     GL_UNSIGNED_BYTE, tex);
   free(tex);

   sphere=gluNewQuadric();
   gluQuadricDrawStyle(sphere, GLU_FILL);
   gluQuadricTexture(sphere, GLU_TRUE);

   cone=gluNewQuadric();
   gluQuadricDrawStyle(cone, GLU_FILL);
   gluQuadricTexture(cone, GLU_TRUE);

   if (glGetError())
   {
      printf("Oops! I screwed up my OpenGL ES calls somewhere\n");
   }
}
示例#22
0
/** c-tor used for creation wrapped text using TTF
    text -- text, used for texture cration
    font -- contains font and size of text
    color -- color of text
    x, y, w, h -- position and size of texture
    w, h defaulted to 0 (means they'll use texture w and h)*/
Texture::Texture(std::string text,
                 uint16_t wrap_width,
                 TTF_Font* font,
                 SDL_Color text_color,
                 uint16_t x,
                 uint16_t y
                 )
    : form({x, y, 0, 0}) {
    obj_counter++;
    path = "text";
    //making surface with text
    make_texture(TTF_RenderText_Blended_Wrapped(font, text.c_str(), text_color, wrap_width));
}
示例#23
0
/**
 * Called via ctx->Driver.DrawPixels()
 */
static void
st_DrawPixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height,
              GLenum format, GLenum type,
              const struct gl_pixelstore_attrib *unpack, const GLvoid *pixels)
{
   struct st_fragment_program *stfp;
   struct st_vertex_program *stvp;
   struct st_context *st = ctx->st;
   struct pipe_surface *ps;
   const GLfloat *color;

   if (format == GL_STENCIL_INDEX ||
       format == GL_DEPTH_STENCIL) {
      draw_stencil_pixels(ctx, x, y, width, height, format, type,
                          unpack, pixels);
      return;
   }

   _mesa_set_vp_override( ctx, TRUE );
   _mesa_update_state( ctx );

   st_validate_state(st);

   if (format == GL_DEPTH_COMPONENT) {
      ps = st->state.framebuffer.zsbuf;
      stfp = make_fragment_shader_z(ctx->st);
      stvp = st_make_passthrough_vertex_shader(ctx->st, GL_TRUE);
      color = ctx->Current.RasterColor;
   }
   else {
      ps = st->state.framebuffer.cbufs[0];
      stfp = combined_drawpix_fragment_program(ctx);
      stvp = st_make_passthrough_vertex_shader(ctx->st, GL_FALSE);
      color = NULL;
   }

   /* draw with textured quad */
   {
      struct pipe_texture *pt
         = make_texture(ctx->st, width, height, format, type, unpack, pixels);
      if (pt) {
         draw_textured_quad(ctx, x, y, ctx->Current.RasterPos[2],
                            width, height, ctx->Pixel.ZoomX, ctx->Pixel.ZoomY,
                            pt, stvp, stfp, color, GL_FALSE);
         pipe_texture_reference(&pt, NULL);
      }
   }

   _mesa_set_vp_override( ctx, FALSE );
}
示例#24
0
文件: theme.c 项目: AMDmi3/neverball
static GLuint theme_image(const char *path)
{
    const int W = video.device_w;
    const int H = video.device_h;

    int W2, H2;

    int w, h, b;
    void *p;

    GLuint o = 0;

    /*
     * Disable mipmapping and do a manual downscale.  Heuristic for
     * downscaling the texture: assume target size to be roughly 1/16
     * of a full screen texture, smallest size being 32x32.
     */

    image_near2(&W2, &H2, W, H);

    W2 = MAX(W2 / 16, 32);
    H2 = MAX(H2 / 16, 32);

    if ((p = image_load(path, &w, &h, &b)))
    {
        void *q;

        /* Prefer a small scale factor. */

        int s = MAX(w, h) / MAX(W2, H2);

        if (s > 1 && (q = image_scale(p, w, h, b, &w, &h, s)))
        {
            free(p);
            p = q;
        }

        o = make_texture(p, w, h, b, 0);

        free(p);
        p = NULL;
    }

    return o;
}
示例#25
0
void OBJPolygon::Initialize(){
	//this assumes all data has already been properly loaded
	glGenVertexArrays(1, &VertexArrayID);

	glGenBuffers(1, &vertexbuffer);
	glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
	glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(glm::vec3), &vertices[0], GL_STATIC_DRAW);

	glGenBuffers(1, &normalbuffer);
	glBindBuffer(GL_ARRAY_BUFFER, normalbuffer);
	glBufferData(GL_ARRAY_BUFFER, normals.size() * sizeof(glm::vec3), &normals[0], GL_STATIC_DRAW);

	glGenBuffers(1, &uvbuffer);
	glBindBuffer(GL_ARRAY_BUFFER, uvbuffer);
	glBufferData(GL_ARRAY_BUFFER, uvs.size() * sizeof(glm::vec2), &uvs[0], GL_STATIC_DRAW);

	texture = make_texture(material->getTexturePath());
}
示例#26
0
int initialize_menu_renderer(struct menu_renderer *self,
			     struct renderer *renderer,
			     const struct b6_clock *clock,
			     const char *skin_id)
{
	static const struct renderer_observer_ops h_renderer_observer_ops = {
		.on_render = menu_renderer_image_on_render_h,
	};
	static const struct renderer_observer_ops v_renderer_observer_ops = {
		.on_render = menu_renderer_image_on_render_v,
	};
	static const struct renderer_observer_ops renderer_observer_ops = {
		.on_render = menu_renderer_on_render,
	};
	struct renderer_base *root;
	self->renderer = renderer;
	self->clock = clock;
	self->menu = NULL;
	root = get_renderer_base(renderer);
	if (make_font(&self->normal_font, skin_id, MENU_NORMAL_FONT_DATA_ID))
		return -1;
	make_font(&self->bright_font, skin_id, MENU_BRIGHT_FONT_DATA_ID);
	if ((self->background = create_renderer_tile(renderer, root, 0, 0,
						     640, 480, NULL)))
		set_renderer_tile_texture(self->background, make_texture(
			renderer, skin_id, MENU_BACKGROUND_DATA_ID));
	initialize_menu_renderer_image(&self->title, renderer, self->clock,
				       70, -118, 500, 150, 32, 3e-4,
				       skin_id, MENU_TITLE_DATA_ID,
				       &v_renderer_observer_ops);
	initialize_menu_renderer_image(&self->pacman, renderer, self->clock,
				       640, 328, 96, 96, 440, 4e-4,
				       skin_id, MENU_PACMAN_DATA_ID,
				       &h_renderer_observer_ops);
	initialize_menu_renderer_image(&self->ghost, renderer, self->clock,
				       -100, 304, 100, 124, 100, 4e-4,
				       skin_id, MENU_GHOST_DATA_ID,
				       &h_renderer_observer_ops);
	add_renderer_observer(self->renderer, setup_renderer_observer(
			&self->renderer_observer,
			"menu_renderer",
			&renderer_observer_ops));
	return 0;
}
示例#27
0
void
test_texture_rg (void)
{
  CoglPipeline *pipeline;
  CoglTexture2D *tex;
  int fb_width, fb_height;
  int x, y;

  fb_width = cogl_framebuffer_get_width (test_fb);
  fb_height = cogl_framebuffer_get_height (test_fb);

  tex = make_texture ();

  g_assert (cogl_texture_get_components (tex) == COGL_TEXTURE_COMPONENTS_RG);

  pipeline = cogl_pipeline_new (test_ctx);

  cogl_pipeline_set_layer_texture (pipeline, 0, tex);
  cogl_pipeline_set_layer_filters (pipeline,
                                   0,
                                   COGL_PIPELINE_FILTER_NEAREST,
                                   COGL_PIPELINE_FILTER_NEAREST);

  cogl_framebuffer_draw_rectangle (test_fb,
                                   pipeline,
                                   -1.0f, 1.0f,
                                   1.0f, -1.0f);

  for (y = 0; y < TEX_HEIGHT; y++)
    for (x = 0; x < TEX_WIDTH; x++)
      {
        test_utils_check_pixel_rgb (test_fb,
                                    x * fb_width / TEX_WIDTH +
                                    fb_width / (TEX_WIDTH * 2),
                                    y * fb_height / TEX_HEIGHT +
                                    fb_height / (TEX_HEIGHT * 2),
                                    x * 256 / TEX_WIDTH,
                                    y * 256 / TEX_HEIGHT,
                                    0);
      }

  cogl_object_unref (pipeline);
  cogl_object_unref (tex);
}
示例#28
0
enum piglit_result
piglit_display(void)
{
    /*
     * Simply draw a textured tri.  The texture is solid red.
     * The tri is clipped.
     */
    static const GLfloat v[3][4] = {
        { 10.0, 10.0, 0.0, 1.0 },
        { 10.0, 1.0, 0.0, 1.0 },
        { 1.0, 1.0, 0.0, 1.0 },
    };
    static const GLfloat t[3][2] = {
        { 0, 0 },
        { 1, 0 },
        { 1, 1 }
    };
    static const GLfloat red[4] = { 1, 0, 0, 1 };
    enum piglit_result result;

    make_texture();

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glBegin(GL_TRIANGLES);
    glTexCoord2fv(t[0]);
    glVertex4fv(v[0]);
    glTexCoord2fv(t[1]);
    glVertex4fv(v[1]);
    glTexCoord2fv(t[2]);
    glVertex4fv(v[2]);
    glEnd();

    if (piglit_probe_pixel_rgb(piglit_width-5, piglit_height-20, red))
        result = PIGLIT_PASS;
    else
        result = PIGLIT_FAIL;

    piglit_present_results();

    return result;
}
示例#29
0
/** c-tor used for texture creation
    path -- path to file with texture
    x, y, w, h -- position and size of texture
    w, h defaulted to 0 (means they'll use texture w and h)*/
Texture::Texture(std::string path,
                 uint16_t x,
                 uint16_t y,
                 uint16_t w,
                 uint16_t h
                 )
    : form({x, y, w, h})
    , path(path) {
    obj_counter++;
    if (path == "") {
        texture = nullptr;
        form = {};
        part_to_render = {};
        width = 0;
        height = 0;
        return;
    }
    //loading surface
    make_texture(IMG_Load(path.c_str()));
}
示例#30
0
void
test_texture_mipmap_get_set (void)
{
  cg_texture_t *texture = make_texture ();

  cg_framebuffer_orthographic (test_fb,
                                 0, 0,
                                 cg_framebuffer_get_width (test_fb),
                                 cg_framebuffer_get_height (test_fb),
                                 -1,
                                 100);

  update_mipmap_levels (texture);
  paint (texture);

  validate_results ();

  if (test_verbose ())
    c_print ("OK\n");
}