Sign in to follow this  
coolkehon

OpenGL Drawing Images and Being able to modify them

Recommended Posts

I learned the psp's gu which is very similar to opengl and now i'm switching to opengl and the way that textures i loaded on the psp is different from opengl. i have an image class i created to holds the image data then renders it by uploading the texture and palette (if any) then draws the coordinates. I've looked at tutorials (nehe +some) and i see that i need to define and object or id and opengl will keep the texture so i should free the texture data i have loaded. my question is where does that texture go and if i should decide to modify the pixel data of that texture how can i do that. also how do i load data into vram in opengl. by the way i'm using SDL for my opengl setup because it's cross platform

Share this post


Link to post
Share on other sites
Texture pixel data is usually stored in VRAM, and swapped to RAM when necessary.

To update a texture, you can use glTexImage1D/2D/3D to respecifiy texture data completely, or glTexSubImage1D/2D/3D to update a region of the texture data.

Share this post


Link to post
Share on other sites
also what is the maximum texture size for opengl if any because i know the psp has a max blitting size of 512x512 and the textures need to be in a power of two which i hate and a max texture size of 1028(?)x1028(?) i know it's 1000 something i believe but i really hope opengl doesnt have this problem and doesnt have that power of two problem either

Share this post


Link to post
Share on other sites
Again, use glTexSubImage1D/2D/3D to upload your modification to the texture in VRAM.

For maximum texture sizes, that's implementation dependant, you can query the maximum with glGetIntegerv(GL_MAX_TEXTURE_SIZE, &i); DX10 GPUs support 8192x8192, DX9.0c GPUs support mostly 4096x4096, etc.

For NPOT textures, you need GL 2.0 or the GL_ARB_texture_non_power_of_two extension.

Share this post


Link to post
Share on other sites
how do i get the gl version and how do i use gltexsubimage can you provide an example and here is my image class (modified a wee bit) from the psp it's very simple. could someone help me modify this to get it working on opengl

header

/*
* Image.h
*
* Created on: Jul 7, 2009
* Author: kurt
*/


#ifndef IMAGE_H_
#define IMAGE_H_

#include "Resizable2DInterface.h"

namespace objdraw
{

class Image: public objdraw::Resizable2DInterface
{
public:
typedef struct PaletteData
{
bool in_vram;
short pixelFormat;
short nentries;
unsigned int * data;
unsigned int size;
} __PaletteData;

typedef struct ImageData
{
bool in_vram;
bool swizzled;
short pixelFormat;
int width;
int height;
int textureWidth;// the real width of data, 2^n with n>=0
int textureHeight; // the real height of data, 2^n with n>=0
unsigned int * data;
unsigned int size;
PaletteData * palette;
} __ImageData;
protected:
virtual ~Image();
std::string error;
bool mirroredVert, mirroredHori;
public:
ImageData * image;
static PaletteData * CreatePalette(int size, bool in_vram, short pixelFormat);

// Image();
Image(Image const & r);
Image(DrawingCanvas * c = NULL);

virtual void render();
virtual void render_big();

uint getPixel(uint x, uint y);
void setPixel(uint x, uint y, uint pixel);

uint getImageWidth();
uint getImageHeigth();

virtual void swizzle();
virtual void unswizzle();
virtual bool swizzled();

bool isMirroredVert();
bool isMirroredHori();
void mirrorVert();
void mirrorHori();
void setVertMirror(bool mir);
void setHoriMirror(bool mir);
// TODO virtual std::string toString();
friend class ImageUtil;
};

}

#endif /* IMAGE_H_ */




.cpp file (source)

/*
* Image.cpp
*
* Created on: Jul 7, 2009
* Author: kurt
*/


#include "Image.h"
#include "DrawingCanvas.h"
#include "Types.h"
#include "GraphicsInstance.h"
#include <GL/gl.h>
#include <malloc.h>
#include <cstring>
#include <sstream>
#include <math.h>
#include "ImageUtil.h"
using namespace std;
using namespace objdraw;

Image::PaletteData * Image::CreatePalette(int size, bool in_vram, short pixelFormat)
{
PaletteData * palette = (Image::PaletteData *)malloc(sizeof(Image::PaletteData));
if(palette == NULL)
return NULL;
palette->pixelFormat = pixelFormat;
palette->nentries = size;
palette->in_vram = in_vram;
palette->size = (palette->nentries * ImageUtil::paletteSizes[pixelFormat]) >> 3;
if(!in_vram)
palette->data = (uint *)memalign(16,palette->size);
else
palette->data = (uint *)valloc(palette->size);
if(palette->data == NULL)
{
free(palette);
return NULL;
}
memset(palette->data,0,palette->size);
return palette;
}

Image::~Image()
{
if(image != NULL)
{
if(image->data != NULL)
{
if(image->in_vram)
vfree(image->data);
else
free(image->data);
}
if(image->palette != NULL)
{
if(image->palette->data != NULL)
{
if(image->palette->in_vram)
vfree(image->palette->data);
else
free(image->palette->data);
}
free(image->palette);
}
free(image);
image = NULL;
}
}
//Image::Image()
//{
// start = Location(0,0);
// end = Location(0,0);
// color = Color(0,0,0);
// hidden = false;
// image = NULL;
// canvas = NULL;
// mirroredVert = mirroredHori = false;
//}
Image::Image(Image const & r)
{
start = r.start;
end = r.end;
color = r.color;
hidden = r.hidden;
canvas = r.canvas;
mirroredVert = r.mirroredVert;
mirroredHori = r.mirroredHori;

image = NULL;
if(r.image != NULL)
{
image = (ImageData *)malloc(sizeof(ImageData));
if(image == NULL)
return;
memcpy(image,r.image,sizeof(ImageData));
image->in_vram = false;
image->data = NULL;
image->palette = NULL;
if(r.image->data != NULL)
{
int size = r.image->size;
if(r.image->in_vram)
{
image->data = (unsigned int *)valloc(size);
if(image->data != NULL)
image->in_vram = true;
}
if(image->data == NULL)
image->data = (unsigned int *)memalign(16,size);
if(image->data != NULL)
memcpy(image->data,r.image->data,size);
}
if(r.image->palette != NULL)
{
image->palette = (PaletteData *)malloc(sizeof(PaletteData));
if(image->palette != NULL)
{
if(r.image->palette->in_vram)
image->palette->data = (unsigned int *)valloc(sizeof(r.image->palette->size));
else
image->palette->data = (unsigned int *)memalign(16,sizeof(r.image->palette->size));
if(image->palette->data != NULL)
{
memcpy(image->palette->data,r.image->palette->data,r.image->palette->size);
image->palette->nentries = r.image->palette->nentries;
image->palette->pixelFormat = r.image->palette->pixelFormat;
image->palette->size = r.image->palette->size;
}
}
}
}
if(canvas != NULL)
canvas->getCanvasContent().addDrawable(this);
}
Image::Image(DrawingCanvas * c)
{
start = Location(0,0);
end = Location(0,0);
color = Color(0,0,0);
hidden = false;
image = NULL;
canvas = c;
mirroredVert = mirroredHori = false;
if(canvas != NULL)
canvas->getCanvasContent().addDrawable(this);
}
uint Image::getPixel(uint x, uint y)
{
// TODO get swizzled pixel address
if(swizzled() || image == NULL || image->data == NULL)
return 0;
int index = (y * image->width) + x;
if(index >= image->size)
return 0;
return image->data[index];
}
void Image::setPixel(uint x, uint y, uint pixel)
{
// TODO get swizzled pixel address
if(swizzled() || image == NULL || image->data == NULL)
return;
int index = (y * image->width) + x;
if(index >= image->size)
return;
image->data[index] = pixel;
}
uint Image::getImageWidth()
{
if(image != NULL && image->data != NULL)
return image->width;
return 0;
}
uint Image::getImageHeigth()
{
if(image != NULL && image->data != NULL)
return image->height;
return 0;
}
void Image::swizzle()
{
if(image == NULL)
return;
if(image->data == NULL || image->swizzled)
return;

int _alignWidth = image->textureWidth;
int _alignHeight = image->textureHeight;
u32 * _data = (u32 *)image->data;

unsigned int swizwidth = (_alignWidth * sizeof(u32));
u32 * temp = (u32 *)memalign(16, _alignHeight * swizwidth);

if(temp == NULL)
return;

unsigned int blockx, blocky;
unsigned int j;
unsigned int width_blocks = swizwidth >> 4;
unsigned int height_blocks = _alignHeight >> 3;
unsigned int src_pitch = (swizwidth - 16) >> 2;
unsigned int src_row = swizwidth << 3;
const u8* ysrc = (u8*)_data;
u32* dst = temp;
for(blocky = 0; blocky < height_blocks; ++blocky)
{
const u8* xsrc = ysrc;
for(blockx = 0; blockx < width_blocks; ++blockx)
{
const u32* src = (u32*)xsrc;
for(j = 0; j < 8; ++j)
{
*(dst++) = *(src++);
*(dst++) = *(src++);
*(dst++) = *(src++);
*(dst++) = *(src++);
src += src_pitch;
}
xsrc += 16;
}
ysrc += src_row;
}
free(_data);
image->data = temp;
image->swizzled = true;
sceKernelDcacheWritebackAll();
}
void Image::unswizzle()
{
if(image == NULL)
return;
if(image->data == NULL || !image->swizzled)
return;

int _alignWidth = image->textureWidth;
int _alignHeight = image->textureHeight;
u32 * _data = (u32 *)image->data;

unsigned int swizwidth = (_alignWidth * sizeof(u32));

u32 * temp = (u32 *)memalign(16, swizwidth * _alignHeight);
if(temp == NULL)
return;

unsigned int blockx, blocky;
unsigned int j;
unsigned int width_blocks = swizwidth >> 4;
unsigned int height_blocks = _alignHeight >> 3;
unsigned int dst_pitch = (swizwidth - 16) >> 2;
unsigned int dst_row = swizwidth << 3;

const u8* ydst = (u8*)temp;
u32* src = _data;

for(blocky = 0; blocky < height_blocks; ++blocky)
{
const u8* xdst = ydst;
for(blockx = 0; blockx < width_blocks; ++blockx)
{
u32* dst = (u32*)xdst;
for(j = 0; j < 8; ++j)
{
*(dst++) = *(src++);
*(dst++) = *(src++);
*(dst++) = *(src++);
*(dst++) = *(src++);
dst += dst_pitch;
}
xdst += 16;
}
ydst += dst_row;
}
free(_data);
image->data = temp;
image->swizzled = false;
sceKernelDcacheWritebackAll();
}
bool Image::swizzled()
{
if(image != NULL)
return image->swizzled;
return false;
}
bool Image::isMirroredVert()
{
return mirroredVert;
}
bool Image::isMirroredHori()
{
return mirroredHori;
}
void Image::mirrorVert()
{
mirroredVert = true;
}
void Image::mirrorHori()
{
mirroredHori = true;
}
void Image::setVertMirror(bool mir)
{
mirroredVert = mir;
}
void Image::setHoriMirror(bool mir)
{
mirroredHori = mir;
}
void Image::render_big()
{
if(hidden || !(image != NULL && image->data != NULL))
return;
if(image->textureHeight < 512 && image->textureWidth < 512)
{
render();
return;
}

sceGuDisable(GU_DEPTH_TEST);
sceGuEnable(GU_TEXTURE_2D);
if(image->palette != NULL)
{
if(image->palette->data != NULL)
{
// upload palette
sceGuClutMode(image->palette->pixelFormat,0,0xff,0);
sceGuClutLoad((image->palette->nentries>>3), image->palette->data);
}
}
// setting the texture
sceGuTexMode(image->pixelFormat,0,0,image->swizzled);
sceGuTexFilter( GU_LINEAR, GU_LINEAR );
sceGuTexFunc(GU_TFX_REPLACE, image->pixelFormat == GU_PSM_5650 ? GU_TCC_RGB : GU_TCC_RGBA);
sceGuTexImage(0, image->textureWidth, image->textureHeight, image->textureWidth, image->data);

int slice = 64;
int sliceWidth = slice;
int width = getWidth();
int height = getHeight();
int dx = start.x, dy = start.y, sx = 0, sy = 0;

for(int j = 0; j < width; j += sliceWidth)
{

vertex2d * points = (vertex2d *)sceGuGetMemory(2 * sizeof(vertex2d));
sliceWidth = slice;
if (j + sliceWidth > width) sliceWidth = width - j;
points[0].u = sx + j;
points[0].v = sy;
points[0].x = dx + j;
points[0].y = dy;
points[0].z = 0;
points[0].color = 0;

points[1].u = sx + j + sliceWidth;
points[1].v = sy + height;
points[1].x = dx + j + sliceWidth;
points[1].y = dy + height;
points[1].z = 0;
points[1].color = 0;
sceGuDrawArray(GU_SPRITES, GU_COLOR_8888 | GU_TEXTURE_32BITF | GU_VERTEX_32BITF | GU_TRANSFORM_2D, 2, 0, points);
}

// enable the depthtesting again.
sceGuEnable(GU_DEPTH_TEST);
sceGuDisable(GU_TEXTURE_2D);
}
void Image::render()
{
if(hidden || !(image != NULL && image->data != NULL))
return;
if(image->textureHeight >= 512 || image->textureWidth >= 512)
{
render_big();
return;
}
// we do not need to test for depth
sceGuDisable(GU_DEPTH_TEST);
sceGuEnable(GU_TEXTURE_2D);
if(image->palette != NULL)
{
if(image->palette->data != NULL)
{
// upload palette
sceGuClutMode(image->palette->pixelFormat,0,0xff,0);
sceGuClutLoad((image->palette->nentries>>3), image->palette->data);
}
}
// setting the texture
sceGuTexMode(image->pixelFormat,0,0,image->swizzled);
sceGuTexFilter( GU_LINEAR, GU_LINEAR );
sceGuTexFunc(GU_TFX_REPLACE, image->pixelFormat == GU_PSM_5650 ? GU_TCC_RGB : GU_TCC_RGBA);
sceGuTexImage(0, image->textureWidth, image->textureHeight, image->textureWidth, image->data);

vertex2d * points = (vertex2d *)sceGuGetMemory(4 * sizeof(vertex2d));
points[0].color = points[1].color = GU_RGBA(255,255,255,255);
points[2].color = points[3].color = GU_RGBA(255,255,255,255);

points[0].u = !mirroredVert ? 0.0f : image->textureWidth;
points[0].v = !mirroredHori ? 0.0f : image->textureHeight;
points[0].x = start.x;
points[0].y = start.y;
points[0].z = 0.0f;

points[1].u = !mirroredVert ? image->textureWidth : 0.0f;
points[1].v = !mirroredHori ? 0.0f : image->textureHeight;
points[1].x = end.x;
points[1].y = start.y;
points[1].z = 0.0f;

points[2].u = !mirroredVert ? 0.0f : image->textureWidth;
points[2].v = !mirroredHori ? image->textureHeight : 0.0f;
points[2].x = start.x;
points[2].y = end.y;
points[2].z = 0.0f;

points[3].u = !mirroredVert ? image->textureWidth : 0.0f;
points[3].v = !mirroredHori ? image->textureHeight : 0.0f;
points[3].x = end.x;
points[3].y = end.y;
points[3].z = 0.0f;

// draw the trianglestrip with transform 2D
sceGuDrawArray(GU_TRIANGLE_STRIP, GU_COLOR_8888 | GU_TEXTURE_32BITF | GU_VERTEX_32BITF | GU_TRANSFORM_2D, 4, 0, points);

// enable the depthtesting again.
sceGuEnable(GU_DEPTH_TEST);
sceGuDisable(GU_TEXTURE_2D);

}


Share this post


Link to post
Share on other sites
Quote:
Original post by coolkehon
i tested my card and it says 2048 :( is there a workaround for this


Split your texture in multiple textures, but you really need textures that large?

Share this post


Link to post
Share on other sites
glTexSubImage1D/2D/3D works in pretty much the same way as glTexImage1D/2D/3D except that you specify an x,y,width,height and you just update that rectangle with the data in the buffer you provide.

You could in theory keep a copy of the texture in RAM and when you modify the byte array (of the texture) just call a glTexSubImage1D/2D/3D for the whole texture and it'll update everything.

Share this post


Link to post
Share on other sites
well i went through the redbook on texturing and learned a lot it seems like a good book to learn opengl with i was playing around with texturing and i found out i didn't have to bind the image and that i could just upload it everytime. which is very helpful to know.

how can i 16 bit images and what about palettes

edit: i load my images using this and when i do it is tinted the color that glColor is currently defined as can anyone tell me why


#include <iostream>
#include <SDL/SDL.h>
#include <SDL/SDL_opengl.h>

using namespace std;

SDL_Surface * screen = NULL;
const uint screen_width = 480;
const uint screen_height = 272;
const uint screen_bpp = 32;

bool resizeWindow(int width, int height);
void glEnable2D();
void glDisable2D();

int main(int argc, char * argv[])
{
atexit(SDL_Quit);
if(SDL_Init(SDL_INIT_VIDEO) < 0)
{
cout << "unable to init sdl: " << SDL_GetError() << endl;
exit(1);
}
/* this holds some info about our display */
const SDL_VideoInfo *videoInfo;
/* Fetch the video info */
videoInfo = SDL_GetVideoInfo( );

if ( !videoInfo )
{
cout << "Video query failed: " << SDL_GetError() << endl;
exit(1);
}

uint videoFlags = 0;
/* the flags to pass to SDL_SetVideoMode */
videoFlags = SDL_OPENGL; /* Enable OpenGL in SDL */
videoFlags |= SDL_GL_DOUBLEBUFFER; /* Enable double buffering */
videoFlags |= SDL_HWPALETTE; /* Store the palette in hardware */
videoFlags |= SDL_RESIZABLE; /* Enable window resizing */

/* This checks to see if surfaces can be stored in memory */
if ( videoInfo->hw_available )
videoFlags |= SDL_HWSURFACE;
else
videoFlags |= SDL_SWSURFACE;

/* This checks if hardware blits can be done */
if ( videoInfo->blit_hw )
videoFlags |= SDL_HWACCEL;

/* Sets up OpenGL double buffering */
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );

/* get a SDL surface */
screen = SDL_SetVideoMode(screen_width, screen_height, screen_bpp, videoFlags);
if(screen == NULL)
{
cout << "unable to set video mode: " << SDL_GetError() << endl;
exit(1);
}

//init the gl
{
/* Enable smooth shading */
glShadeModel( GL_SMOOTH );
/* Set the background black */
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
/* Depth buffer setup */
glClearDepth( 1.0f );
/* Enables Depth Testing */
glEnable( GL_DEPTH_TEST );
/* The Type Of Depth Test To Do */
glDepthFunc( GL_LEQUAL );
/* Really Nice Perspective Calculations */
glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
/* the alpha value blend function based on source alpha */
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
/* enable blending */
glEnable(GL_BLEND);
}

/* resize the initial window */
resizeWindow(screen_width, screen_height);
GLuint texture[1];
SDL_Surface * img = SDL_LoadBMP("lan_house.bmp");
glGenTextures(1,&texture[0]);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexImage2D(GL_TEXTURE_2D,0,3,img->w,img->h,0,GL_BGR,GL_UNSIGNED_BYTE,img->pixels);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
/* wait for events */
for(bool done = false, isActive = true; !done;)
{
/* handle the events in the queue */
SDL_Event event;
while ( SDL_PollEvent( &event ) )
{
switch( event.type )
{
case SDL_ACTIVEEVENT:
/* Something's happend with our focus
* If we lost focus or we are iconified, we
* shouldn't draw the screen
*/

event.active.gain == 0 ? isActive = false : isActive = true;
break;
case SDL_VIDEORESIZE:
/* handle resize event */
screen = SDL_SetVideoMode( event.resize.w,
event.resize.h,
16, videoFlags );
if ( !screen )
{
cout << "Could not get a surface after resize: " << SDL_GetError() << endl;
exit(1);
}
resizeWindow( event.resize.w, event.resize.h );
break;
case SDL_KEYDOWN:
/* handle key presses */
if(event.key.keysym.sym == SDLK_ESCAPE)
exit(0);
if(event.key.keysym.sym == SDLK_l)
{
int i = 0;
glGetIntegerv(GL_MAX_TEXTURE_SIZE,&i);
cout << "max tex size = " << i << endl;
}
// handleKeyPress( &event.key.keysym );
break;
case SDL_QUIT:
/* handle quit requests */
done = true;
break;
default:
break;
}
}
/* draw the scene */
if ( !isActive )
continue;
glClearColor(0,0,0,0);
/* Clear The Screen And The Depth Buffer */
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glEnable2D();
// glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4ub(255,255,255,150);

glBegin(GL_QUADS);
glVertex2f(0.0f,0.0f);
glVertex2f(100.0f,0.0f);
glVertex2f(100.0f,100.0f);
glVertex2f(0.0f,100.0f);
glEnd();

glColor4ub(255,0,0,255);
glBegin(GL_QUADS);
glVertex2f(110,0);
glVertex2f(210,0);
glVertex2f(210,100);
glVertex2f(110,100);
glEnd();

// glRasterPos2i(100,0);
// glDrawPixels(img->w,img->h,GL_BGR, GL_UNSIGNED_BYTE,img->pixels);
glDisable(GL_BLEND);
glEnable(GL_TEXTURE_2D);
// glBindTexture(GL_TEXTURE_2D,texture[0]);
glTexImage2D(GL_TEXTURE_2D,0,3,img->w,img->h,0,GL_BGR,GL_UNSIGNED_BYTE,img->pixels);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glBegin(GL_QUADS);
glTexCoord2f(0,0); glVertex2f(0.0f,0.0f);
glTexCoord2f(1,0); glVertex2f(img->w,0.0f);
glTexCoord2f(1,1); glVertex2f(img->w,img->h);
glTexCoord2f(0,1); glVertex2f(0.0f,img->h);
glEnd();
glDisable(GL_TEXTURE_2D);

SDL_GL_SwapBuffers();
}
exit(0);
return 0;
}

/* function to reset our viewport after a window resize */
bool resizeWindow( int width, int height )
{
/* Height / width ration */
GLfloat ratio;

/* Protect against a divide by zero */
if ( height == 0 )
height = 1;

ratio = ( GLfloat )width / ( GLfloat )height;

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

/* change to the projection matrix and set our viewing volume. */
glMatrixMode( GL_PROJECTION );
glLoadIdentity( );

/* Set our perspective */
gluPerspective( 45.0f, ratio, 0.1f, 100.0f );

/* Make sure we're chaning the model view and not the projection */
glMatrixMode( GL_MODELVIEW );

/* Reset The View */
glLoadIdentity( );

return true;
}
//-----------------------------------------------------------------------------
// Name: glEnable2D
// Desc: Enabled 2D primitive rendering by setting up the appropriate orthographic
// perspectives and matrices.
//-----------------------------------------------------------------------------
void glEnable2D( void )
{
GLint iViewport[4];

// Get a copy of the viewport
glGetIntegerv( GL_VIEWPORT, iViewport );

// Save a copy of the projection matrix so that we can restore it
// when it's time to do 3D rendering again.
glMatrixMode( GL_PROJECTION );
glPushMatrix();
glLoadIdentity();

// Set up the orthographic projection
glOrtho( iViewport[0], iViewport[0]+iViewport[2],
iViewport[1]+iViewport[3], iViewport[1], -1, 1 );
glMatrixMode( GL_MODELVIEW );
glPushMatrix();
glLoadIdentity();

// Make sure depth testing and lighting are disabled for 2D rendering until
// we are finished rendering in 2D
glPushAttrib( GL_DEPTH_BUFFER_BIT | GL_LIGHTING_BIT );
glDisable( GL_DEPTH_TEST );
glDisable( GL_LIGHTING );
/** re-enable blending ? how come i have to */
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}


//-----------------------------------------------------------------------------
// Name: glDisable2D
// Desc: Disables 2D rendering and restores the previous matrix and render states
// before they were modified.
//-----------------------------------------------------------------------------
void glDisable2D( void )
{
glPopAttrib();
glMatrixMode( GL_PROJECTION );
glPopMatrix();
glMatrixMode( GL_MODELVIEW );
glPopMatrix();
}





[Edited by - coolkehon on August 19, 2009 6:45:59 PM]

Share this post


Link to post
Share on other sites
OpenGL is a state machine.

So if you are using textures and using glColor* in the same pass, you will need to call glColor3f(1.0f, 1.0f, 1.0f) after the last glColor* call to make sure textures get modulated by 1.

Move to GLSL and not worry about these headaches if you can.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Partner Spotlight

  • Forum Statistics

    • Total Topics
      627639
    • Total Posts
      2978344
  • Similar Content

    • By xhcao
      Before using void glBindImageTexture(    GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format), does need to make sure that texture is completeness. 
    • By cebugdev
      hi guys, 
      are there any books, link online or any other resources that discusses on how to build special effects such as magic, lightning, etc. in OpenGL? i mean, yeah most of them are using particles but im looking for resources specifically on how to manipulate the particles to look like an effect that can be use for games,. i did fire particle before, and I want to learn how to do the other 'magic' as well.
      Like are there one book or link(cant find in google) that atleast featured how to make different particle effects in OpenGL (or DirectX)? If there is no one stop shop for it, maybe ill just look for some tips on how to make a particle engine that is flexible enough to enable me to design different effects/magic 
      let me know if you guys have recommendations.
      Thank you in advance!
    • By dud3
      How do we rotate the camera around x axis 360 degrees, without having the strange effect as in my video below? 
      Mine behaves exactly the same way spherical coordinates would, I'm using euler angles.
      Tried googling, but couldn't find a proper answer, guessing I don't know what exactly to google for, googled 'rotate 360 around x axis', got no proper answers.
       
      References:
      Code: https://pastebin.com/Hcshj3FQ
      The video shows the difference between blender and my rotation:
       
    • By Defend
      I've had a Google around for this but haven't yet found some solid advice. There is a lot of "it depends", but I'm not sure on what.
      My question is what's a good rule of thumb to follow when it comes to creating/using VBOs & VAOs? As in, when should I use multiple or when should I not? My understanding so far is that if I need a new VBO, then I need a new VAO. So when it comes to rendering multiple objects I can either:
      * make lots of VAO/VBO pairs and flip through them to render different objects, or
      * make one big VBO and jump around its memory to render different objects. 
      I also understand that if I need to render objects with different vertex attributes, then a new VAO is necessary in this case.
      If that "it depends" really is quite variable, what's best for a beginner with OpenGL, assuming that better approaches can be learnt later with better understanding?
       
    • By test opty
      Hello all,
       
      On my Windows 7 x64 machine I wrote the code below on VS 2017 and ran it.
      #include <glad/glad.h>  #include <GLFW/glfw3.h> #include <std_lib_facilities_4.h> using namespace std; void framebuffer_size_callback(GLFWwindow* window , int width, int height) {     glViewport(0, 0, width, height); } //****************************** void processInput(GLFWwindow* window) {     if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)         glfwSetWindowShouldClose(window, true); } //********************************* int main() {     glfwInit();     glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);     glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);     glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);     //glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);     GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", nullptr, nullptr);     if (window == nullptr)     {         cout << "Failed to create GLFW window" << endl;         glfwTerminate();         return -1;     }     glfwMakeContextCurrent(window);     if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))     {         cout << "Failed to initialize GLAD" << endl;         return -1;     }     glViewport(0, 0, 600, 480);     glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);     glClearColor(0.2f, 0.3f, 0.3f, 1.0f);     glClear(GL_COLOR_BUFFER_BIT);     while (!glfwWindowShouldClose(window))     {         processInput(window);         glfwSwapBuffers(window);         glfwPollEvents();     }     glfwTerminate();     return 0; }  
      The result should be a fixed dark green-blueish color as the end of here. But the color of my window turns from black to green-blueish repeatedly in high speed! I thought it might be a problem with my Graphics card driver but I've updated it and it's: NVIDIA GeForce GTX 750 Ti.
      What is the problem and how to solve it please?
  • Popular Now