PDA

View Full Version : problem in set a byte array in texturing



pnpvivek
11-26-2008, 05:22 AM
Hi
I want to set the particular bytearray as a thin plot (dot) in a texturing .How do i? if possible plz consider my problem.
i sent that code also.
following code is:
OnPaint()
{
glEnable (GL_BLEND) ;
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) ;
glShadeModel (GL_SMOOTH) ;
glEnable(GL_TEXTURE_2D) ;
glPushMatrix() ;
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) ;
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) ;
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP) ;
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP) ;
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) ;
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) ;
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB , m_nWidth, m_nHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, m_nTextureData) ;
LoadSubImageTexture() ;
glPopMatrix() ;
glDisable(GL_TEXTURE_2D) ;
}

void CPPIDisplayCtrl::LoadSubImageTexture()
{

GLfloat fYoffSetVal,fXoffSetVal ;

//user's Point of view Outer most circle Radius 20 / 55 is a radius of outermost circle in Pc point of view.
fRangeResolution = m_fRangeVal / 0.36363636363636363636363636363636 ;
// To locate the point on specified angle
//0.017453292519943295769236907684886 Used to radian to degree convertion factor (PI/180).
m_fXOffsetVal = (fRangeResolution * sin(m_fAzimuth * 0.017453292519943295769236907684886)) ;
//Used to locate the point with (64,64) as center of the PPI.
fXoffSetVal = 64.0 + m_fXOffsetVal ;

m_fYOffsetVal = (fRangeResolution * cos(m_fAzimuth * 0.017453292519943295769236907684886)) ;
fYoffSetVal = 64.0 - m_fYOffsetVal ;

int nIndex = (((int)fXoffSetVal) * 3.0) + (128.0 * ((int)fYoffSetVal) * 3.0) ; //(128 * 53 * 3) + (63* 3); 53 is Y value && 63 is X value //20 95 //47 115
//nIndex = nIndex - (nIndex % 3) ;

//Changing color when plotting points are going to an outside of the circle.

//if(fRangeResolution <= 55.0000)
////int n = (82 * 3) + (128 * 11 * 3) ;
// m_nTextureData[nIndex] = 255 ;
//else//
m_nTextureData[nIndex + 1/*+ 1*/] = 255 ;
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_nWidth, m_nHeight, GL_RGB , GL_UNSIGNED_BYTE, m_nTextureData);
SetTextureCoOrdinate() ;
}
void CPPIDisplayCtrl::SetTextureCoOrdinate()
{
RECT rect;
GetClientRect(&rect) ;
int nWindowWidth = rect.right - rect.left ;
int nWindowHeight = rect.bottom - rect.top ;

gluOrtho2D(0, nWindowWidth/2, nWindowHeight/2, 0) ;
glBegin(GL_POLYGON) ;
glTexCoord2f(0.0f, 0.0f) ;
glVertex2i(0, 0) ;
glTexCoord2f(1.0f, 0.0f) ;
glVertex2i(nWindowWidth/2 , 0) ;
glTexCoord2f(1.0f, 1.0f) ;
glVertex2i(nWindowWidth/2, nWindowHeight/2) ;
glTexCoord2f(0.0f, 1.0f) ;
glVertex2i(0, nWindowHeight/2 ) ;
glEnd() ;

}

trinitrotoluene
11-26-2008, 07:51 AM
In your OnPaint function, you forget to call glGenTextures (http://www.opengl.org/sdk/docs/man/xhtml/glGenTextures.xml) and glBindTexture (http://www.opengl.org/sdk/docs/man/xhtml/glBindTexture.xml). In your SetTextureCoOrdinate() function, you forget to call glEnable(GL_TEXTURE_2D),glBindTexture(...) and glDisable(GL_TEXTURE_2D). There is a good tutorial about texturing (http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=06) at NeHe web site.

pnpvivek
11-27-2008, 05:45 AM
Hi,
Thanks for your reply.
I am doing texturing using openGL in Activex Control in MFC.
I want to change the background color using property page on activex control .
I change back color using propety page in Activex control.
but the texturing portion did not change the corresponding color.
consider the problem.
awaiting your reply.

trinitrotoluene
11-27-2008, 03:02 PM
I change back color using propety page in Activex control.

I assume that somewhere you call glClearColor (http://www.opengl.org/sdk/docs/man/xhtml/glClearColor.xml) to do that, if you want only a single color as background color of course. If not, you are drawing a full screen quad (http://www.opengl.org/resources/faq/technical/transformations.htm#tran0090) with a texture on it. Now if I understand you well, the user of your software have the possibility to change the background colors (an image) but for now it doesn't work. To change the image or a portion of an image for an existing texture, you can use glTexSubImage2D (http://www.opengl.org/sdk/docs/man/xhtml/glTexSubImage2D.xml) to do that. All you have to do is: 1) bind the texture id => glBinTexture(...). 2) replace the texture data with glTexSubImage2D(GL_TEXTURE_2D,0,0,0,tex_width,tex_ height,GL_RGB,GL_UNSIGNED_BYTE,new_pixel_data);.
If you are still no able to achieve it, I can post a small sample program to demonstrate it.

Al Shameer
11-28-2008, 04:05 AM
Please see glTexSubImage2D in openGL redbook might me helpful not sure.....

pnpvivek
11-28-2008, 06:04 AM
Hi,
Thanks for your reply.
Now texturing portion of changing the corresponding color are coming successfully. But, the color in the texturing portion is displaying differently compare to that other window area.
the portion which i applied the texturing is clearly showing as it is .
consider the problem.
awaiting your reply.

trinitrotoluene
11-28-2008, 08:19 AM
But, the color in the texturing portion is displaying differently compare to that other window area. Do you mean that you get wrong colors. If it's that try to replace the GL_RGB parameter of the glTexSubImage2D with GL_BGR. Remember by default in OpenGL the texture color is multiplied by the incoming fragment color (GL_MODULATE). You can also try glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_RE PLACE); so only the texture color will be applied. Finally, when you are updating the texture data with glTexSubImage don't forget to call glBindTexture just before with the right texture ID otherwise you will change the wrong texture.

pnpvivek
11-28-2008, 10:30 PM
Hi trinitrotoluene,
i am having another problem in viewport area. consider this also
I applied texturing using OpenGL in MFC activex control.I want to move the texturing portion along with circle to the left corner of the window as well as i want to move the font which i mentioned near the right side of the circle.

whenever I resize the MFC activex control,texturing portion and also the Font is going out of the control.(ie, Half of the circle is displaying & Font is getting collapsed).Because I am using glRasterPos2d(....).
I want the circle and Font displayed to be clearly viewable AS ORIGINAL , if i resize the control

I AM ATTACHING MY CODE ALSO:


void CPPIDisplayCtrl::OnSize(UINT nType, int cx, int cy)
{
COleControl::OnSize(nType, cx, cy);

HWND hWnd = GetSafeHwnd() ;
HDC hDc = ::GetDC(hWnd) ;
wglMakeCurrent(hDc, m_hGLContext) ;

int width, height;
double aspect;

width = cx;
height = cy;

glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

if (width > height)
{
if (cy==0)
aspect = (double)width;
else
aspect = (double)width/(double)height;

glOrtho(-1*aspect, 1*aspect, -1, 1, -1, 1);
}
else
{
if (cx==0)
aspect = (double)height;
else
aspect = (double)height/(double)width;

glOrtho(-1, 1, -1*aspect, 1*aspect, -1, 1);
}

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDrawBuffer(GL_BACK);

}

void CPPIDisplayCtrl::DisplayParameterInfo()
{
glColor3ub(255,0,0);
glRasterPos2d(1.3, 0.3);
m_nFont.FontPrintf(m_glDegreeFont, 1, "%d", m_nCount) ;
}
I call the DisplayParameterInfo() in OnPaint() only.

awiting your reply.

trinitrotoluene
11-29-2008, 08:32 AM
I have tried to reproduce your bug but without great success.



whenever I resize the MFC activex control,texturing portion and also the Font is going out of the control.(ie, Half of the circle is displaying & Font is getting collapsed).Because I am using glRasterPos2d(....).
I want the circle and Font displayed to be clearly viewable AS ORIGINAL , if i resize the control


Can you post a screen shot of your application. One before you resize your viewport (original) and one after you resize your viewport (bug apparent).

pnpvivek
12-05-2008, 05:00 AM
It is coming .but when i resize the window only the half of the circle displayed and font collapsed. i think that aspect value is problem.can you check the aspect value. if possible you correct that aspect value and post it.
awaiting your reply.