Example #1
0
void loginWindowUpdate(const string &username, int pwdLen){
	if(loginSelectTexture[0] == 0) loginSelectTexture[0] = loadImg("res/loginsel0.png");
	if(loginSelectTexture[1] == 0) loginSelectTexture[1] = loadImg("res/loginsel1.png");
	if(loginSelectTexture[2] == 0) loginSelectTexture[2] = loadImg("res/loginsel2.png");
		
	if(loginSurface == NULL){
		loginSurface = IMG_Load("res/login.png");
	
		SDL_Color white, black;
		white.r = white.g = white.b = 0xFF;
		black.r = black.g = black.b = 0x00;
		
		SDL_Surface *titleText = TTF_RenderUTF8_Blended(font, "Login", white);
		SDL_Rect rTitle = {6,5,0,0};	
		SDL_BlitSurface(titleText, NULL, loginSurface, &rTitle);
		SDL_FreeSurface(titleText);	

		SDL_Surface *userLblText = TTF_RenderUTF8_Blended(font, "Usuario:", black);
		SDL_Rect rUserLbl = {8,35,0,0};
		SDL_BlitSurface(userLblText, NULL, loginSurface, &rUserLbl);
		SDL_FreeSurface(userLblText);		
		
		SDL_Surface *passLblText = TTF_RenderUTF8_Blended(font, "Password:"******"Aceptar", black);
		SDL_Rect rButton = {128,107,0,0};
		rButton.x -= buttonText->w/2;
		rButton.y -= buttonText->h/2;
		SDL_BlitSurface(buttonText, NULL, loginSurface, &rButton);
		SDL_FreeSurface(buttonText);			
		
		loginTexture = genTexture(loginSurface, loginTexture);	
	}
	
	SDL_Color black;
	black.r = black.g = black.b = 0x00;
	
	SDL_Surface *tempSurface = SDL_ConvertSurface(loginSurface, loginSurface->format, loginSurface->flags);
	
	SDL_Surface *userNameText = TTF_RenderUTF8_Blended(font, username.c_str(), black);
	SDL_Rect rUserName = {91,35,0,0};
	SDL_BlitSurface(userNameText, NULL, tempSurface, &rUserName);
	SDL_FreeSurface(userNameText);
	
	string tempPass;
	for(int i=0;i<pwdLen;i++) tempPass += '*';
	
	SDL_Surface *passWordText = TTF_RenderUTF8_Blended(font, tempPass.c_str(), black);
	SDL_Rect rPassWord = {91,67,0,0};
	SDL_BlitSurface(passWordText, NULL, tempSurface, &rPassWord);
	SDL_FreeSurface(passWordText);	
	
	loginTexture = genTexture(tempSurface, loginTexture);	
	SDL_FreeSurface(tempSurface);
}
Example #2
0
void alertShow(char *text, char *title){
	if(alertSelectTexture == 0)
		alertSelectTexture = loadImg("res/alertsel0.png");
		
	gameStatePrev = gameState;
	gameState = gameStates::alert;

	SDL_Surface *alertSurface = IMG_Load("res/alert.png");

	SDL_Color white, black;
	white.r = white.g = white.b = 0xFF;
	black.r = black.g = black.b = 0x00;
	
	SDL_Surface *titleText = TTF_RenderUTF8_Blended(font, title, white);
	SDL_Rect rTitle = {6,5,0,0};	
	SDL_BlitSurface(titleText, NULL, alertSurface, &rTitle);
	SDL_FreeSurface(titleText);	

	SDL_Surface *bodyText = TTF_RenderUTF8_Blended(font, text, black);
	SDL_Rect rBody = {8,30,0,0};
	SDL_BlitSurface(bodyText, NULL, alertSurface, &rBody);
	SDL_FreeSurface(bodyText);		
	
	SDL_Surface *buttonText = TTF_RenderUTF8_Blended(font, "Aceptar", black);
	SDL_Rect rButton = {128,106,0,0};
	rButton.x -= buttonText->w/2;
	rButton.y -= buttonText->h/2;
	SDL_BlitSurface(buttonText, NULL, alertSurface, &rButton);
	SDL_FreeSurface(buttonText);			
	
	alertTexture = genTexture(alertSurface, alertTexture);
	SDL_FreeSurface(alertSurface);	
}
Example #3
0
void selectionUpdate(const string &title, const string &first, const string &second){
	if(selectionIdxTexture[0] == 0) selectionIdxTexture[0] = loadImg("res/selection0.png");
	if(selectionIdxTexture[1] == 0) selectionIdxTexture[1] = loadImg("res/selection1.png");
	
	SDL_Surface *selectionSurface = IMG_Load("res/selection.png");

	SDL_Color white, black;
	white.r = white.g = white.b = 0xFF;
	black.r = black.g = black.b = 0x00;
	
	SDL_Surface *titleText = TTF_RenderUTF8_Blended(font, title.c_str(), white);
	SDL_Rect rTitle = {6,5,0,0};	
	SDL_BlitSurface(titleText, NULL, selectionSurface, &rTitle);
	SDL_FreeSurface(titleText);	

	SDL_Surface *firstText = TTF_RenderUTF8_Blended(font, first.c_str(), black);
	SDL_Rect rFirst = {60,67,0,0};
	rFirst.x -= firstText->w/2;
	SDL_BlitSurface(firstText, NULL, selectionSurface, &rFirst);
	SDL_FreeSurface(firstText);		
	
	SDL_Surface *secondText = TTF_RenderUTF8_Blended(font, second.c_str(), black);
	SDL_Rect rSecond = {195,67,0,0};
	rSecond.x -= secondText->w/2;
	SDL_BlitSurface(secondText, NULL, selectionSurface, &rSecond);
	SDL_FreeSurface(secondText);			
	
	selectionTexture = genTexture(selectionSurface, selectionTexture);	
	SDL_FreeSurface(selectionSurface);	
}
EmTexture* TextureUtil::loadTexture(const char* filename) {
  EmTexture* texture = 0;
#if EM_USE_SDL
  // look if the texture is already loaded
  if (m_hEmTexture.find(string(filename)) != m_hEmTexture.end()) {
    EM_COUT("TextureUtil::loadTexture found texture "
            << filename << " in cache", 0);
    map<string, EmTexture*>::iterator element
      = m_hEmTexture.find(string(filename));
    return (*element).second;
  }

  texture =  new EmTexture;
  int t = genTexture( filename, texture); //!rzr {
  if ( t < 0 ) { delete texture; return 0; } // could have been written better

  //EM_GLERROR(" In TextureUtil::loadTexture ");
  // insert the texture into the cache
  m_hEmTexture.insert(pair<string, EmTexture*>(string(filename), texture));
  m_hImageName.insert(pair<EmTexture*, string>(texture, string(filename)));
  //cout<<"- TextureUtil::loadTexture"<<endl;
  return texture;
#endif // EM_USE_SDL
#if EM_USE_ALLEGRO
  RGB pal[256];
  BITMAP * bm = load_bitmap(filename, pal);
  if (bm == NULL) {
    cerr << "TextureUtil::loadTexture Unable to load "
         << filename << " : " << allegro_error << endl;
  }
  return bm;
#endif // EM_USE_ALLEGRO
  return texture;
}
Example #5
0
Texture::Texture(int width, int height, GLuint target, int flag)
  : target(target)
{
  extractParams(flag);
  genTexture();
  glTexImage2D(target, 0, internalFormat, width, height, 0, format, type, NULL);
  texParameter(GL_TEXTURE_MAG_FILTER, magFilter);
  texParameter(GL_TEXTURE_MIN_FILTER, minFilter);
}
Example #6
0
GLuint loadTextureFromPNGData(png_byte* image_data, int &width, int &height)
{
	if (image_data == NULL) LOGE("loadTextureFromPNGData:Image data == NULL");
	GLuint texture = genTexture();
	bindTexture2D(texture);
	texImage2D(width, height, static_cast<GLvoid*>(image_data));
	texParameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	texParameter(GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	return texture;
}
Example #7
0
//-- Constructor
UIObjectSliced::UIObjectSliced(char* name, char* imagePath, GLuint width, GLuint height, GLuint program)
{
	this->name = name;
	this->width = width;
	this->height = height;
	this->program = program;

	genTexture(imagePath);
	genBuffer();

	std::cout << name << " Created!" << std::endl;
}
Example #8
0
OpenGLImage::OpenGLImage(SDL_Surface *surface)
    : Image(std::string()), tex(genTexture(true)), w(surface->w), h(surface->h) {
    int texture_format;
    bool colorNoAlpha = (surface->format->BitsPerPixel == 24 && surface->format->BytesPerPixel==3);
    bool colorAlpha = (surface->format->BitsPerPixel == 32 && surface->format->BytesPerPixel==4);
    uint32_t v255shift24 = 255;
    v255shift24 <<= 24;
    if (colorNoAlpha && surface->format->Rmask == 255 && surface->format->Gmask == (255 << 8) && surface->format->Bmask == (255 << 16)) {
        texture_format = GL_RGB;
#ifndef USE_GLES
    } else if (colorNoAlpha && surface->format->Bmask == 255 && surface->format->Gmask == (255 << 8) && surface->format->Rmask == (255 << 16)) {
        texture_format = GL_BGR;
    } else if (colorAlpha && surface->format->Bmask == 255 && surface->format->Gmask == (255 << 8) && surface->format->Rmask == (255 << 16)  && surface->format->Amask == v255shift24) {
        texture_format = GL_BGRA;
#endif
    } else if (colorAlpha && surface->format->Rmask == 255 && surface->format->Gmask == (255 << 8) && surface->format->Bmask == (255 << 16)  && surface->format->Amask == v255shift24) {
        texture_format = GL_RGBA;
    } else {
#ifdef USE_SDL2
        SDL_Surface *newSurf = SDL_ConvertSurfaceFormat(
                surface, SDL_PIXELFORMAT_ABGR8888, 0);
#else
        SDL_Surface *newSurf = SDL_CreateRGBSurface(
                SDL_SWSURFACE, surface->w, surface->h, 32,
                255, (255 << 8), (255 << 16), v255shift24);
        SDL_Rect r;
        r.x = 0;
        r.y = 0;
        r.w = surface->w;
        r.h = surface->h;
        if ( (surface->flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
            surface->flags &= ~SDL_SRCALPHA;
        }
        SDL_LowerBlit(surface, &r, newSurf, &r);
#endif
        SDL_FreeSurface(surface);
        surface = newSurf;
        texture_format = GL_RGBA;
        colorNoAlpha = false;
        colorAlpha = true;
    }

    if (!SDL_LockSurface(surface)) {
        glTexImage2D( GL_TEXTURE_2D, 0, colorAlpha ? GL_RGBA : GL_RGB, w, h, 0,
                      texture_format, GL_UNSIGNED_BYTE, surface->pixels);
        stage = COMPLETE;
#ifndef EMSCRIPTEN
        SDL_UnlockSurface(surface);
#endif
    }
    SDL_FreeSurface(surface);
}
ColorFrameBufferObj::ColorFrameBufferObj(GLsizei width, GLsizei height)
	:FrameBufferObject(width, height)
{
	genTexture(width, height);
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureID, 0);

	GLuint renderBufferID;
	glGenRenderbuffers(1, &renderBufferID);
	glBindRenderbuffer(GL_RENDERBUFFER, renderBufferID);
	glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height);
	glBindRenderbuffer(GL_RENDERBUFFER, 0);
	glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, renderBufferID);
}
Example #10
0
GLuint safeImgLoad(const char * img_file)
{
    printf("loading image: %s\n", img_file);
    SDL_Surface *img = IMG_Load(img_file);
    if (img == NULL)
    {
        fprintf(stderr, "image loading fail: %s\n", SDL_GetError());
        exit(1);
    }
    printf("creating texture\n");
    GLuint texture = genTexture(img);
    return texture;
}
Example #11
0
int main() {
	initGL();

	GLuint texHandle = genTexture();
	renderHandle = genRenderProg(texHandle);
	computeHandle = genComputeProg(texHandle);

	for (int i = 0; i < 1024; ++i) {
		updateTex(i);
		draw();
	}

	return 0;
}
Example #12
0
Texture::Texture(const char *filename, GLuint target, int flag)
  : name(filename), target(target)
{
  flag |= UNSIGNED_BYTE|RGB; //RGB avoid an exception in extractParams
  extractParams(flag);
  genTexture();

  if(target == TEXTURE_CUBE_MAP)
    loadCubemap(flag);
  else if(target == TEXTURE_2D)
    loadTexture2D(name, target, flag);

  texParameter(GL_TEXTURE_MAG_FILTER, magFilter);
  texParameter(GL_TEXTURE_MIN_FILTER, minFilter);
}
Example #13
0
void Game::start(Process* previous, bool push)
{
	mPrevious = previous;

	sgLevel.lightMap = genTexture();

	glBindTexture(GL_TEXTURE_2D, sgLevel.lightMap);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE8, sgAtlas->gLightMapSizeX,
	    sgAtlas->gLightMapSizeY, 0, GL_LUMINANCE, GL_FLOAT,
	    sgAtlas->gLightMapData);

	initGameField();

	resetGame();
}
Example #14
0
void VSMPerPixelRenderer::reshape(int w,int h)
{
    DefaultRenderer::reshape(w,h);
    release();
    for(int i=0; i<MAX_LIGHTS; i++) {
        genTexture(_tid[i],w,h,GL_DEPTH_COMPONENT,GL_DEPTH_COMPONENT,GL_UNSIGNED_BYTE);
        genTexture(_ctid[i],w,h,GL_RGB32F_ARB,GL_RGB,GL_FLOAT,GL_LINEAR);
        //create a framebuffer object
        glGenFramebuffersEXT(1,&(_fboId[i]));
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,_fboId[i]);
        //Instruct openGL that we won't bind a color texture with the currently binded FBO
        //glDrawBuffer(GL_NONE);
        //glReadBuffer(GL_NONE);
        //attach the texture to FBO depth attachment point
        glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_DEPTH_ATTACHMENT_EXT,GL_TEXTURE_2D,_tid[i],0);
        glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_COLOR_ATTACHMENT0_EXT,GL_TEXTURE_2D,_ctid[i],0);
        checkFBO();
        //switch back to window-system-provided framebuffer
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,0);
    }
    {
        genTexture(_ctTmp,w,h,GL_RGB32F_ARB,GL_RGB,GL_FLOAT,GL_LINEAR);
        //create a framebuffer object
        glGenFramebuffersEXT(1,&_fboTmp);
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,_fboTmp);
        //Instruct openGL that we won't bind a color texture with the currently binded FBO
        //glDrawBuffer(GL_NONE);
        //glReadBuffer(GL_NONE);
        //attach the texture to FBO depth attachment point
        glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_COLOR_ATTACHMENT0_EXT,GL_TEXTURE_2D,_ctTmp,0);
        checkFBO();
        //switch back to window-system-provided framebuffer
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,0);
    }
    _released=false;
}
Example #15
0
void ViewPort::initializeGL()
{
    id_timer=startTimer(1);
    qglClearColor(Qt::black);
    glEnable(GL_DEPTH_TEST);
    glShadeModel(GL_SMOOTH);
    //glShadeModel(GL_FLAT);
    m_nPyramid = createPyramid();


    genTexture(); // создать текстуры
    glEnable(GL_TEXTURE_2D);

    // активизируем массив текстурных координат
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
}
// may solve the w32 bug on resize //TODO check it @w32
void TextureUtil::reloadTextures()  {
  //cout<<"+ TextureUtil::reloadTextures"<<endl;
#if EM_USE_SDL
  m_hImageName.clear();
  map<string,EmTexture*>::iterator i;
  for ( i = m_hEmTexture.begin();
        i != m_hEmTexture.end();
        i++) {
    glDeleteTextures (1, (GLuint*) ((*i).second) ); //is that correct ?
    genTexture( (*i).first.c_str() ,  (*i).second  );
    m_hImageName.insert(pair<EmTexture*,string>(  (*i).second, (*i).first ));
  }
#endif    // TODO ALLEGRO
  //EM_CERR("- TextureUtil::reloadTextures");
  //cout<<"- TextureUtil::reloadTextures"<<endl;
}
Example #17
0
Cursor::Cursor(void) {
   _cursorTexture = NULL;

   _requestedCursorChange = false;

#ifdef _WIN32
   _blinkTime = GetCaretBlinkTime();
#else
   _blinkTime = 700;
#endif // _WIN32

   _timebase = _time = (int)(glfwGetTime() / 1000.0);				// Glut used milliseconds but GLFW uses senconds.
   _isShowingCursor = true;
   _cursorInMovement = false;

   _insert = false;

   genTexture();
}
Example #18
0
GLuint loadTextureFromPNG(const ResourcePtr& pngData, int &width, int &height)
{
	//Now generate the OpenGL texture object
	GLuint texture = genTexture();
	bindTexture2D(texture);
	png_byte* image_data = loadImageFromPNG(pngData, width, height);
	// got this logic from android_source/frameworks/base/cmds/bootanimation/BootAnimation.cpp,
	// but it doesn't seem to work right. The odd-sized texture loads, but it is squished. I could probably fix
	// that, but I'm not going to worry about it for now.
//    int tw = 1 << (31 - __builtin_clz(width));
//    int th = 1 << (31 - __builtin_clz(height));
//    if (tw < width) tw <<= 1;
//    if (th < height) th <<= 1;
//
//    if (tw != width || th != height)
//    {
//        GLint crop[4] = { 0, height, width, -height };
//    	texImage2D(tw, th, 0);
//    	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, static_cast<GLvoid*>(image_data));
//    	checkGLError("glTexSubImage2D");
//        glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
//        checkGLError("glTexParameteriv");
//    }
//    else
//    {
    	texImage2D(width, height, static_cast<GLvoid*>(image_data));
//    }

	texParameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	texParameter(GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	// I thought these might help with random black pixels on the edge of a rotated texture, but they didn't.
//	texParameter(GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
//	texParameter(GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

	//clean up memory and close stuff
	//png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
	//delete[] image_data;
	//delete[] row_pointers;
	delete[] image_data;
	return texture;
}
void PassInfoDemo::addToFakeOutput(WidgetRenderer * renderer, Camera& myCam, DebugMenuManager * menu) {
	myCam.lookAt(glm::vec3(0,1,-7),glm::vec3(0,0,0));
	teapot.magnitude = .6;
	menu->edit("magnitude",teapot.magnitude,0,2);

	ShaderProgram * deformWithTexture = renderer->addShader("./../shaders/NoiseMapDeformv.glsl","./../shaders/NoiseMapDeformF.glsl");
	renderer->saveViewTransform(deformWithTexture,"viewTransform");
		
	auto  teaPotGeo = renderer->addGeometry((NUShapeEditor::rotate(Neumont::ShapeGenerator::makeTeapot(30,glm::mat4()),-90,0,0)),GL_TRIANGLES);
	teapot.noiseTexture = renderer->addTexture("./../textures/seamlessNoise.png");
		
	teapot.Teapot = renderer->addRenderable(teaPotGeo,deformWithTexture,teapot.noiseTexture);
	teapot.Teapot->saveMatrixInfo("model2WorldTransform");
	teapot.Teapot->saveTexture("myTexture");
	teapot.Teapot->addUniformParameter("noiseMap",ParameterType::PT_TEXTURE,&teapot.noiseTexture);
	teapot.Teapot->addUniformParameter("uvOffset",ParameterType::PT_VEC2,&teapot.uvOffset[0]);
	teapot.Teapot->addUniformParameter("magnitude",teapot.magnitude);
	teapot.Teapot->transformData.scale = glm::vec3(.75,.75,.75);
	teapot.Teapot->transformData.position.y = -.5;

	int bearTexture = renderer->addTexture("./../textures/ToonTeddyBear.png");
	auto bearGeo = renderer->addGeometry(BinaryToShapeLoader::loadFromFile("./../models/TeddyBear.bin"),GL_TRIANGLES);// doo it
	auto bearShader = renderer->addShader("./../shaders/NoiseMapDissolveV.glsl","./../shaders/NoiseMapDissolveF.glsl");
	renderer->saveViewTransform(bearShader,"viewTransform");

	for (int i = 0; i < sizeof(bears) / sizeof(*bears); i++)
	{
		bears[i].noiseTexture = genTexture(renderer,Random::randomInt(0,20));
		bears[i].percent = (float)i/(sizeof(bears) / sizeof(*bears));
		bears[i].discardThreshold = .01;
		bears[i].renderable = renderer->addRenderable(bearGeo,bearShader,bearTexture);

		bears[i].renderable->transformData.scale = glm::vec3(4,4,4);
		bears[i].renderable->transformData.rotation.y = 90;

		bears[i].renderable->saveMatrixInfo("model2WorldTransform");
		bears[i].renderable->saveTexture("myTexture");
		bears[i].renderable->addUniformParameter("noiseMap",ParameterType::PT_TEXTURE,&bears[i].noiseTexture);
		bears[i].renderable->addUniformParameter("discardThreshold",ParameterType::PT_FLOAT,&bears[i].discardThreshold);
	}
}
Example #20
0
GLuint loadTextureFromPKM(const ResourcePtr& pkmData, int &width, int &height)
{
#ifdef GL_ETC1_RGB8_OES
	const unsigned ETC_PKM_HEADER_SIZE = 16;
	if (pkmData->data().size() <= ETC_PKM_HEADER_SIZE)
	{
		LOGE("pkmData is not the right size. expected > %u, is: %zu", ETC_PKM_HEADER_SIZE, pkmData->data().size());
		return TEXTURE_LOAD_ERROR;
	}

	etc1_byte* header = &pkmData->data()[0];

	if (!etc1_pkm_is_valid(header))
		return TEXTURE_LOAD_ERROR;

	width = etc1_pkm_get_width(header);
	height = etc1_pkm_get_height(header);

	size_t encodedDataSize = etc1_get_encoded_data_size(width, height);

	if (pkmData->data().size() != ETC_PKM_HEADER_SIZE + encodedDataSize)
	{
		LOGE("pkmData is not the right size. expected: %zu, is: %zu", ETC_PKM_HEADER_SIZE + encodedDataSize, pkmData->data().size());
		return TEXTURE_LOAD_ERROR;
	}

	//Now generate the OpenGL texture object
	GLuint texture = genTexture();
	bindTexture2D(texture);
	compressedTexImage2D(GL_ETC1_RGB8_OES, width, height, encodedDataSize, static_cast<GLvoid*> (&pkmData->data()[ETC_PKM_HEADER_SIZE]));
	texParameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	texParameter(GL_TEXTURE_MAG_FILTER, GL_NEAREST);

	return texture;
#else
	LOGE("PKM texture format not supported by this platform");
	return TEXTURE_LOAD_ERROR;
#endif
}
Example #21
0
File: gbuffer.cpp Project: pakt/gfx
void GBuffer::init(unsigned int width, unsigned int height){
	glGenFramebuffers(1, &m_fbo);
	glBindFramebuffer(GL_FRAMEBUFFER, m_fbo);

  for (int i = 0; i < GBUFFER_NUM_TEXTURES; i++) {
    m_textures[i] = genTexture(width, height);
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, 
                           GL_TEXTURE_2D, m_textures[i], 0);
  }
  // depth / stencil
  glGenTextures(1, &m_texDepthStencil);
  glBindTexture(GL_TEXTURE_2D, m_texDepthStencil);
  glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH32F_STENCIL8, width, height, 0, 
      GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, NULL);
  glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, 
      GL_TEXTURE_2D, m_texDepthStencil, 0);
  
  // Always check that our framebuffer is ok
  if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE){
    fatal("GBuffer::init: setting framebuffer failed");
  }
}
Example #22
0
OpenGLImage::OpenGLImage(const std::shared_ptr<AsyncIOTask>& asyncIOTask, const std::string &filename)
    : Image(filename), tex(genTexture()), w(0), h(0) {
    if (!filename.empty()) {
        downloadAndLoad(asyncIOTask);
    }
}
Example #23
0
void registerUpdate(const string &field1, const string &field2, const string &field3, const string &field4, const string &button, const string &title){
	if(regSelectTexture[0] == 0) regSelectTexture[0] = loadImg("res/regsel0.png");
	if(regSelectTexture[1] == 0) regSelectTexture[1] = loadImg("res/regsel1.png");
	if(regSelectTexture[2] == 0) regSelectTexture[2] = loadImg("res/regsel2.png");
	if(regSelectTexture[3] == 0) regSelectTexture[3] = loadImg("res/regsel3.png");
	if(regSelectTexture[4] == 0) regSelectTexture[4] = loadImg("res/regsel4.png");
	
	if(registerSurface == NULL){
		registerSurface = IMG_Load("res/register.png");
	
		SDL_Color white, black;
		white.r = white.g = white.b = 0xFF;
		black.r = black.g = black.b = 0x00;
		
		SDL_Surface *titleText = TTF_RenderUTF8_Blended(font, title.c_str(), white);
		SDL_Rect rTitle = {6,5,0,0};	
		SDL_BlitSurface(titleText, NULL, registerSurface, &rTitle);
		SDL_FreeSurface(titleText);	

		SDL_Surface *userLblText = TTF_RenderUTF8_Blended(font, "Usuario:", black);
		SDL_Rect rUserLbl = {8,48,0,0};
		SDL_BlitSurface(userLblText, NULL, registerSurface, &rUserLbl);
		SDL_FreeSurface(userLblText);		
		
		SDL_Surface *passLblText = TTF_RenderUTF8_Blended(font, "Password:"******"Mail:", black);
		SDL_Rect rMailLbl = {8,134,0,0};
		SDL_BlitSurface(mailLblText, NULL, registerSurface, &rMailLbl);
		SDL_FreeSurface(mailLblText);			
		
		SDL_Surface *nameLblText = TTF_RenderUTF8_Blended(font, "Nombre:", black);
		SDL_Rect rNameLbl = {8,177,0,0};
		SDL_BlitSurface(nameLblText, NULL, registerSurface, &rNameLbl);
		SDL_FreeSurface(nameLblText);					
		
		SDL_Surface *buttonText = TTF_RenderUTF8_Blended(font, button.c_str(), black);
		SDL_Rect rButton = {128,234,0,0};
		rButton.x -= buttonText->w/2;
		rButton.y -= buttonText->h/2;
		SDL_BlitSurface(buttonText, NULL, registerSurface, &rButton);
		SDL_FreeSurface(buttonText);			
		
		registerTexture = genTexture(registerSurface, registerTexture);	
	}
	
	SDL_Color black;
	black.r = black.g = black.b = 0x00;
	
	SDL_Surface *tempSurface = SDL_ConvertSurface(registerSurface, registerSurface->format, registerSurface->flags);
	
	SDL_Surface *f1Text = TTF_RenderUTF8_Blended(font, field1.c_str(), black);
	SDL_Rect rF1 = {88,48,0,0};
	SDL_BlitSurface(f1Text, NULL, tempSurface, &rF1);
	SDL_FreeSurface(f1Text);
	
	SDL_Surface *f2Text = TTF_RenderUTF8_Blended(font, field2.c_str(), black);
	SDL_Rect rF2 = {88,91,0,0};
	SDL_BlitSurface(f2Text, NULL, tempSurface, &rF2);
	SDL_FreeSurface(f2Text);	
	
	SDL_Surface *f3Text = TTF_RenderUTF8_Blended(font, field3.c_str(), black);
	SDL_Rect rF3 = {88,134,0,0};
	SDL_BlitSurface(f3Text, NULL, tempSurface, &rF3);
	SDL_FreeSurface(f3Text);	

	SDL_Surface *f4Text = TTF_RenderUTF8_Blended(font, field4.c_str(), black);
	SDL_Rect rF4 = {88,177,0,0};
	SDL_BlitSurface(f4Text, NULL, tempSurface, &rF4);
	SDL_FreeSurface(f4Text);		
	
	registerTexture = genTexture(tempSurface, registerTexture);	
	SDL_FreeSurface(tempSurface);
}
Example #24
0
int main(int argc, char **argv)
#endif
{
    GLuint  ui32Vbo = 0; // Vertex buffer object handle
    GLuint  ui32IndexVbo;
    GLuint  ui32Texture;

    int nframes = 100;
    bool immidateMode     = false;
    bool useIndices       = true;
    bool useTexture       = false;
    bool useCompTexture   = false;
    bool useConvertedType = true;
    bool useFixed         = false;
    bool usePoints        = false;
    bool useCopy          = false;
    bool useSubCopy       = false;

    int c;
    extern char *optarg;

    #ifdef _WIN32
        HWND   windowId = NULL;
    #elif __linux__
        Window windowId = NULL;
    #elif __APPLE__
        void* windowId = NULL;
    #endif

        //      // Inialize SDL window
        //
        if (SDL_Init(SDL_INIT_NOPARACHUTE | SDL_INIT_VIDEO)) {
            fprintf(stderr,"SDL init failed: %s\n", SDL_GetError());
            return -1;
        }

        SDL_Surface *surface = SDL_SetVideoMode(WINDOW_WIDTH,WINDOW_HEIGHT, 32, SDL_HWSURFACE);
        if (surface == NULL) {
            fprintf(stderr,"Failed to set video mode: %s\n", SDL_GetError());
            return -1;
        }

        SDL_SysWMinfo  wminfo;
        memset(&wminfo, 0, sizeof(wminfo));
        SDL_GetWMInfo(&wminfo);
    #ifdef _WIN32
        windowId = wminfo.window;
    #elif __linux__
        windowId = wminfo.info.x11.window;
    #elif __APPLE__
        windowId = createGLView(wminfo.nsWindowPtr,0,0,WINDOW_WIDTH,WINDOW_HEIGHT);

    #endif

        int major,minor,num_config;
        EGLConfig configs[150];
        EGLSurface egl_surface;
        EGLContext ctx;
        EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY);
        eglInitialize(d,&major,&minor);
        printf("DISPLAY == %p major =%d minor = %d\n",d,major,minor);
        eglChooseConfig(d, attribute_list, configs, 150, &num_config);
        printf("config returned %d\n",num_config);
        egl_surface = eglCreateWindowSurface(d,configs[0],windowId,NULL);
        printf("before creating context..\n");
        ctx = eglCreateContext(d,configs[0],EGL_NO_CONTEXT,NULL);
        printf("SURFACE == %p CONTEXT == %p\n",egl_surface,ctx);
        if(eglMakeCurrent(d,egl_surface,egl_surface,ctx)!= EGL_TRUE){
            printf("make current failed\n");
            return false;
        }
        printf("after make current\n");

        GLenum err = glGetError();
        if(err != GL_NO_ERROR) {
        printf("error before drawing ->>> %d  \n",err);
        } else {
        printf("no error before drawing\n");
        }

    if (useTexture) {

        glEnable(GL_TEXTURE_2D);
        ui32Texture = 1;
        glBindTexture(GL_TEXTURE_2D, ui32Texture);
                GLenum err = glGetError();

        unsigned char *pixels = NULL;
                if(useCompTexture) {
                        pixels = genPalette4_rgb8(TEX_WIDTH,TEX_HEIGHT,3);
                        glCompressedTexImage2D(GL_TEXTURE_2D,0,GL_PALETTE4_RGB8_OES,TEX_WIDTH,TEX_HEIGHT,0,3*16+TEX_WIDTH*TEX_HEIGHT/2,pixels);

                } else {
                        pixels = genTexture(TEX_WIDTH, TEX_HEIGHT, 4);
            glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEX_WIDTH, TEX_HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
                }

        delete pixels;

                err = glGetError();
                if(err != GL_NO_ERROR)
            printf("error %d after image \n",err);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
                err = glGetError();
                if(err != GL_NO_ERROR)
            printf("error after min filter \n");
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
                err = glGetError();
                if(err != GL_NO_ERROR)
            printf("error after mag filter \n");
        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
                err = glGetError();
                if(err != GL_NO_ERROR)
            printf("error after env mode \n");

                if(useCompTexture) {
                    pixels = genPalette4_rgb8(TEX_WIDTH,TEX_HEIGHT,1);
                    glCompressedTexSubImage2D(GL_TEXTURE_2D,0,TEX_WIDTH/4,TEX_HEIGHT/4,TEX_WIDTH/8,TEX_HEIGHT/8,GL_PALETTE4_RGB8_OES,3*16+(TEX_WIDTH*TEX_HEIGHT/128),pixels);
                } else {
            pixels = genRedTexture(TEX_WIDTH/8, TEX_HEIGHT/8, 4);
                    glTexSubImage2D(GL_TEXTURE_2D,0,TEX_WIDTH/4,TEX_HEIGHT/4,TEX_WIDTH/8,TEX_HEIGHT/8,GL_RGBA,GL_UNSIGNED_BYTE,pixels);
                }
                 err = glGetError();
                if(err != GL_NO_ERROR)
            printf("error %d after subimage \n",err);
        delete pixels;

    }

    glClearColor(0.6f, 0.8f, 1.0f, 1.0f); // clear blue

    float afVertices[] = {  -0.4f,-0.4f,0.0f, // Position
                 1.0f,0.0f,0.0f,1.0f, // Color
                 0.0f, 0.0f, // texture
                 12.f, //point size

                 0.4f,-0.4f,0.0f,
                 0.0f,1.0f,0.0f,1.0f,
                 1.0f, 0.0f,
                 47.0f,

                 0.0f,0.4f,0.0f,
                 0.0f,0.0f,1.0f,1.0f,
                 0.5f, 1.0f,
                 14.0f
    };

#define MAX_T 1
#define MID_T 0
#define MIN_T 0

    GLbyte byteVertices[] = { -1,-1,0, // Position
                             255,0,0,255, // Color
                             MIN_T, MIN_T, // texture
                             12, //point size

                             1,-1,0,
                             0,255,0,255,
                             MAX_T,MIN_T,
                             47,

                            0,1,0,
                            0,0,255,255,
                            MID_T, MAX_T,
                            14
    };

    GLfixed fixedVertices[] = { F_to_X(-0.4f),F_to_X(-0.4f),F_to_X(0.0f), // Position
                    F_to_X(1.0f),F_to_X(0.0f),F_to_X(0.0f),F_to_X(1.0f), // Color
                    F_to_X(0.0f),F_to_X(0.0f), // texture
                    F_to_X(12.0f),//points size

                    F_to_X(0.4f),F_to_X(-0.4f),F_to_X(0.0f),
                    F_to_X(0.0f),F_to_X(1.0f),F_to_X(0.0f),F_to_X(1.0f),
                    F_to_X(1.0f),F_to_X( 0.0f),
                    F_to_X(30.0f),

                    F_to_X(0.0f),F_to_X(0.4f),F_to_X(0.0f),
                    F_to_X(0.0f),F_to_X(0.0f),F_to_X(1.0f),F_to_X(1.0f),
                    F_to_X(0.5f), F_to_X(1.0f),
                    F_to_X(30.0)
    };

    unsigned short indices[] = { 2, 1, 0 };

    if (!immidateMode) {
        glGenBuffers(1, &ui32Vbo);
        ui32Vbo = 1;
         printf("ui32Vbo = %d\n", ui32Vbo);

        glBindBuffer(GL_ARRAY_BUFFER, ui32Vbo);
        void* data = (void*)afVertices;
        unsigned int uiSize = 3*(sizeof(float)*10);
        if(useConvertedType){
           if(useFixed){
               data = (void*)fixedVertices;
           } else {
               data   = (void*)byteVertices;
               uiSize = 3*(sizeof(GLbyte)*10);
           }
        }
        glBufferData(GL_ARRAY_BUFFER, uiSize,data, GL_STATIC_DRAW);

        ui32IndexVbo = 2;
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ui32IndexVbo);
        glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
    }

    // Draws a triangle for 800 frames
    float angle = 0.0;
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    GLvoid* arr = NULL;
    GLenum  type;
    GLenum  drawType;
    GLenum  colorType;
    int     size_of;

    if(useConvertedType){
        if(useFixed)
        {
            arr = fixedVertices;
            colorType = type = GL_FIXED;
            size_of = sizeof(GLfixed);
        } else {
            arr = byteVertices;
            colorType = GL_UNSIGNED_BYTE;
            type = GL_BYTE;
            size_of = sizeof(GLbyte);
        }
    }else {
        arr = afVertices;
        colorType = type = GL_FLOAT;
        size_of = sizeof(float);
    }

    if(usePoints)
    {
        drawType = GL_POINTS;
    }
    else
        drawType = GL_TRIANGLES;

    GLvoid* data = NULL;
    for (int i = 0; i < 100; i++) {

        glClear(GL_COLOR_BUFFER_BIT);
        glPushMatrix();
        glRotatef(angle, 0.0, 0.0, 1.0);
        angle += 360.0 / nframes;
        // Enable vertex arrays
        glEnableClientState(GL_VERTEX_ARRAY);
        if (immidateMode) {
            glVertexPointer(3,type, size_of * 10, arr);
        } else {
            glVertexPointer(3,type, size_of * 10, 0);
        }

        // Set color data in the same way
        glEnableClientState(GL_COLOR_ARRAY);
        if (immidateMode) {
            SWITCH_SOURCE(3)
            glColorPointer(4, colorType, size_of * 10, data);
        } else {
            glColorPointer(4,colorType,size_of * 10, (GLvoid*) (size_of * 3) );
        }
        if (useTexture) {
            glEnableClientState(GL_TEXTURE_COORD_ARRAY);
            if (immidateMode) {
                SWITCH_SOURCE(7)
                glTexCoordPointer(2, type, size_of * 10,data);
            } else {
                glTexCoordPointer(2, type, size_of * 10, (GLvoid*)(size_of * 7));
            }
        }
        if(usePoints)
        {
            glEnableClientState(GL_POINT_SIZE_ARRAY_OES);
            if (immidateMode) {
                SWITCH_SOURCE(9)
                glPointSizePointerOES(type,size_of * 10,data);
                        } else {
                glPointSizePointerOES(type,size_of * 10,(GLvoid*)(size_of * 9));
                        }
        }

        if (useIndices) {
            if (immidateMode) {
                glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
                glDrawElements(drawType, 3, GL_UNSIGNED_SHORT, indices);
            } else {
                glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ui32IndexVbo);
                glDrawElements(drawType, 3, GL_UNSIGNED_SHORT, 0);
            }
        } else {
            glDrawArrays(drawType, 0, 3);
        }

                GLenum err = glGetError();
                if(err != GL_NO_ERROR)
            printf(" error %d has occured while drawing\n",err);


        glPopMatrix();
                eglSwapBuffers(d,egl_surface);

                if(useTexture && useCopy)
                    glCopyTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,0,0,256,256,0);
                else if(useTexture && useSubCopy)
                    glCopyTexSubImage2D(GL_TEXTURE_2D,0,100,100,WINDOW_WIDTH/2,WINDOW_HEIGHT/2,50,50);
    }
                err = glGetError();
                if(err != GL_NO_ERROR)
            printf("error ->>> %d  \n",err);
        eglDestroySurface(d,egl_surface);
        eglDestroyContext(d,ctx);

// Just wait until the window is closed
        SDL_Event ev;
        while( SDL_WaitEvent(&ev) ) {
            if (ev.type == SDL_QUIT) {
                break;
            }
        }
    return 0;
}
Example #25
0
void IplTexture::loadTexture()
{
#ifdef HAVE_GL
    if (im==0) return;
    if (!textureGenerated) genTexture();

    IplImage *im = (downsampled ? downsampled : this->im);

    if ((im->width > texWidth) || (im->height > texHeight)) {
        if (downsampled) cvReleaseImage(&downsampled);
        downsampled = cvCreateImage(cvSize(texWidth, texHeight), this->im->depth, this->im->nChannels);
        im = downsampled;
    }

    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, texture);

    if (allowCache && !reload) return;
    reload = false;

    if (downsampled)
        cvResize(this->im, downsampled, CV_INTER_AREA);

    GLenum format;
    GLenum type;
    switch (im->depth) {
    case IPL_DEPTH_8U:
        type = GL_UNSIGNED_BYTE;
        break;
    case IPL_DEPTH_8S:
        type = GL_BYTE;
        break;
    case IPL_DEPTH_16S:
        type = GL_SHORT;
        break;
    case IPL_DEPTH_32F:
        type = GL_FLOAT;
        break;
    default:
        std::cerr << "IplTexture::loadTexture(): unsupported pixel type.\n";
        return;
    }
    switch (im->nChannels) {
    case 1:
        format = (isAlpha ? GL_ALPHA : GL_LUMINANCE);
        break;
    case 3:
        format = (im->channelSeq[0] == 'B') ? GL_BGR_EXT : GL_RGB;
        break;
    case 4:
        format = GL_RGBA;
        break;
    default:
        std::cerr << "IplTexture::loadTexture(): unsupported number of channels.\n";
        return;
    }

    // pixel storage mode
    glPixelStorei(GL_UNPACK_ALIGNMENT, im->align);

    glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, im->width, im->height,
                    format, type, im->imageData);

    uScale = (double(im->width)/double(this->im->width))/double(texWidth);
    vScale = (double(im->height)/double(this->im->height))/double(texHeight);
    vOrigin = 0;

    if (im->origin) {
        vScale = -vScale;
        vOrigin = double(im->height)/double(texHeight);
    }
#endif
}
Example #26
0
void OpenGLImage::reload(const std::shared_ptr<AsyncIOTask>&asyncIOTask) {
    stage = LOADING;
    tex = genTexture();
    downloadAndLoad(asyncIOTask);
}
Example #27
0
texture::texture(){
	genTexture();
};