Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


xargon123

Member Since 09 Dec 2005
Offline Last Active Mar 11 2015 06:20 PM

Topics I've Started

OpenGL: mapping images to textures

11 March 2015 - 04:49 PM

I am very new to OpenGL and am reading about mapping images to textures and came across this API with the following signature:

void glTexImage2D(GLenum target,  GLint level,  GLint internalformat,
                  GLsizei width,  GLsizei height,  GLint border,  
                  GLenum format,  GLenum type,  const GLvoid * data);

Now, I have read many places that graphics hardware works better if things are aligned to 4 byte boundaries. So, I was wondering about the following case where I have a RGB image. So, the format parameter should be GL_RGB. However, to take advantage of this 4 byte alignment I want to keep it internally as GL_RGBA (where the alpha channel is not really used).

 

Reading the API, I got a bit confused as to whether I need to internally change my image to have this RGBA structure or would just setting the internal format to GL_RGBA and format to GL_RGB suffice?

 

Another question that I wonder is what if I have grayscale data i.e. just a single channel. Would it also be beneficial to convert that to RGBA structure at the cost of more memory or would I not get a performance hit by keeping it as GL_RED, for example.

 

Thanks,

Luca


Question about glGenTextures

04 December 2012 - 05:49 PM

Hello,

I have a question about glGenTextures, which I use to create some 2D textures from 3D volumes as follows:

During my initialization, I have something as follows:

[source lang="cpp"]m_pXTexNames = new unsigned int[m_nXDim];glGenTextures(m_nXDim, m_pXTexNames);m_pYTexNames = new unsigned int[m_nYDim];glGenTextures(m_nYDim, m_pYTexNames);m_pZTexNames = new unsigned int[m_nZDim];glGenTextures(m_nZDim, m_pZTexNames);[/source]

And for each of these I use glTexImage2D to generate the texture with some data.

Now, my understanding is that when you use this the data resides on the GPU memory but I see the system RAM increasing quite a bit after these calls and they stay high till I deallocate the texture (I verified this using the windows task manager).

Is this normal? Have I misunderstood how this works? I can show more detailed code if you want.

Thanks,

xarg

Help with GLSL shader

19 April 2011 - 09:12 PM

Hi everyone,

I have some legacy code which I am converting/porting to a new framework using Trolltech's Qt framework. The version from 4.7 also has support for GLSL shaders.

I have some shader code in my application which is as follows. It is a fragment shader and not too complex (I think!)

//initialise fragment program 
char* szShader = new char[1024]; 
strcpy(szShader, "!!ARBfp1.0\n"); 
strcat(szShader, "PARAM c[1] = { { 65535, 0.00390625, 256, 0.0039215689 } };\n"); 
strcat(szShader, "TEMP R0;\n"); 
strcat(szShader, "TEX R0.x, fragment.texcoord[0], texture[0], 2D;\n"); 
strcat(szShader, "MUL R0.x, R0, c[0];\n"); 
strcat(szShader, "MUL R0.y, R0.x, c[0];\n"); 
strcat(szShader, "ABS R0.z, R0.y;\n"); 
strcat(szShader, "FRC R0.z, R0;\n"); 
strcat(szShader, "MUL R0.z, R0, c[0];\n"); 
strcat(szShader, "FLR R0.y, R0;\n"); 
strcat(szShader, "CMP R0.x, R0, -R0.z, R0.z;\n"); 
strcat(szShader, "MUL_SAT R0.xy, R0, c[0].w;\n"); 
strcat(szShader, "TEX result.color, R0, texture[1], 2D;\n"); 
strcat(szShader, "END\n\0"); 

Could someone help me compare this to GLSL as the Qt framework does not support shaders in this (assembly?!) sort of format. I have no experience with shadersa myself and have unfortunately hit a wall and am having difficulty making progress! I will pay in beers if you are in London anytime!

Many thanks. I really appreciate any help.

xarg


P.S: So, it turns out that I need to convert this ASM like shader to GLSL. I looked for such conversion tools but could not really find one. This shader code should be simple. Does anyone know of any such tools that can be used to convert from ASM to GLSL or other shader languages?

Catmull Rom spline derivative

21 November 2010 - 07:22 AM

Hello everyone,

I am currently using a Catmull Rom spline to interpolate intensities in an image using the matrix described here:

http://en.wikipedia.org/wiki/Cubic_Hermite_spline#Interpolation_on_the_unit_interval_without_exact_derivatives

So, I am looking at the 16 values in the neighbourhood and applying the shown matrix and calculating the interpolated intensity and this works quite well.

Now, I also need to calculate the derivative of this spline.

Is it then simply, taking the derivatives of that kernel, which would be:

0.5 *

|4x - 3x^2 - 1|
|9x^2 - 10x |
|8x - 9x^2 + 1|
|3x^2 - 2x |

Thanks,
xarg

derivative of the bicubic interpolation kernel

17 November 2010 - 03:24 AM

Hello everyone,

I am using the bicubic kernel described here ( http://en.wikipedia.org/wiki/Bicubic_interpolation#Bicubic_convolution_algorithm ) to interpolate my image after applying some transformations.

I an using the matrix kernel described here with a = -0.5.

Now, what I also need to do is estimate the kernel that is the derivative of this bicubic kernel. There is a bit of discussion in this page on the derivative but I am finding it impossible to be able to derive this kernel.

I would be really grateful if someone can help me derive this derivative kernel. My calculus skills are quite rusty but this is a roadblock for me for quite a few days now. I have also searched high and low on the internet for this derivative kernel but to no avail.

I look forward to any assistance you can give me.

xarg

PARTNERS