Sign in to follow this  
chen884488shi

OpenGL about texRECTlod in cg

Recommended Posts

I use openGL and Cg script. I want to get the LOD of my image .This is my openGL code: ///////////////////////////////////////////////////////////////////////////////////////// BOOL CTestVGriyDlg::CgVGriyFunction(WORD*m_pIn,int m_nInW,int m_nInH,int m_nInB, WORD*m_pOut) { image_w=m_nW; image_h=m_nH; int i; // float* data = (float*)malloc(image_w*image_h*sizeof(float)); float* result = (float*)malloc(4*image_w*image_h*sizeof(float)); for (i=0; i<image_w*image_h; i++) data[i] = (float)m_pIn[i]/*/16383*/; glutCreateWindow("TEST1"); glewInit(); //init_cg(); //init_cg_for_all(); //初始化参数 InitCgVGriyParam(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0,image_w,0.0,image_h); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glViewport(0,0,image_w,image_h); GLuint fb; glGenFramebuffersEXT(1,&fb); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,fb); // glGenTextures (1, &tex); glGenTextures (1, &fboTex); glBindTexture(GL_TEXTURE_RECTANGLE_ARB,fboTex); glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexImage2D(GL_TEXTURE_RECTANGLE_ARB,0,GL_RGBA32F_ARB, image_w,image_h,0,GL_RGBA,GL_FLOAT,0); glBindTexture(GL_TEXTURE_RECTANGLE_ARB,tex); glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_COLOR,GL_DECAL); glTexImage2D(GL_TEXTURE_RECTANGLE_ARB,0,GL_LUMINANCE32F_ARB, image_w,image_h,0,GL_LUMINANCE,GL_FLOAT,0); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_ARB,fboTex,0); glBindTexture(GL_TEXTURE_RECTANGLE_ARB,tex); //////////////////////////////////////////////////////////////////////////////////// // float* fLevelData=NULL; long lW=image_w; long lH=image_h; for (int face =0;; face++) { lW=(lW>>face); lH=(lH>>face); if(lW<=0) break; if(lH<=0) break; int mm=(1<<face); fLevelData=new float[lH*lW]; memset(fLevelData,0,sizeof(float)*lH*lW); for(int hIndex=0;hIndex<lH;hIndex++) { for(int wIndex=0;wIndex<lW;wIndex++) { fLevelData[wIndex+lW*hIndex]=data[wIndex*mm+image_w*mm*hIndex]; } } //glTexImage2D(GL_TEXTURE_RECTANGLE_ARB ,face,GL_LUMINANCE,lW,lH,0, GL_LUMINANCE, GL_FLOAT, fLevelData); glTexImage2D(GL_TEXTURE_RECTANGLE_ARB,face,GL_RGBA32F_ARB, lW,lH,0,GL_RGBA,GL_FLOAT,0); glTexSubImage2D(GL_TEXTURE_RECTANGLE_ARB,face,0,0,lW,lH, GL_LUMINANCE,GL_FLOAT,fLevelData); /*glTexImage2D(GL_TEXTURE_2D, level, GL_RGB8, size, size, 0, GL_RGB, GL_UNSIGNED_BYTE, image);*/ } //////////////////////////////////////////////////////////////////////////////////// /*glTexSubImage2D(GL_TEXTURE_RECTANGLE_ARB,0,0,0,image_w,image_h, GL_LUMINANCE,GL_FLOAT,data);*/ //////////////////////////////////////////////////////////////////////////////////// //glBindTexture(GL_TEXTURE_RECTANGLE_ARB, TO_NORMALIZE_VECTOR_CUBE_MAP); //glTexImage2D(GL_TEXTURE_RECTANGLE_ARB,0,GL_RGBA32F_ARB, w2,h2,0,GL_RGBA,GL_FLOAT,0); //// glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //// glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); //// glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); //glBindTexture(GL_TEXTURE_RECTANGLE_ARB,TO_NORMALIZE_VECTOR_CUBE_MAP); //glTexSubImage2D(GL_TEXTURE_RECTANGLE_ARB,0,0,0,w2,h2, // GL_LUMINANCE,GL_FLOAT,m_fPicConvVal); /* Load each 32x32 face (without mipmaps) of range-compressed "normalize vector" cube map. */ //////////////////////////////////////////////////////////////////////////////////// //--------------------begin------------------------- int n1=GetTickCount(); glColor4f(1.00f,1.00f,1.00f,1.0f); glBindTexture(GL_TEXTURE_RECTANGLE_ARB,tex); glEnable(GL_TEXTURE_RECTANGLE_ARB); ///////////////////////////////////////////////////////////////////////////////////////////// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //cgGLBindProgram(myCgFragmentProgram); //checkForCgError("binding fragment program"); //aa cgGLEnableProfile(myCgFragmentProfile); checkForCgError("enabling fragment profile"); /*cgGLEnableTextureParameter(InputImage); checkForCgError("enable InputImage");*/ // cgGLBindProgram(myZywSecEnlarge); // checkForCgError("binding fragment program"); // // cgGLEnableProfile(myCgFragmentProfile); // checkForCgError("enabling fragment profile"); //glBindTexture(GL_TEXTURE_RECTANGLE_ARB,tex); ////////////////////////////////////////////////////////////////////////////////////////// glBegin(GL_QUADS); glTexCoord2f(0.0, 0.0); glVertex2f(0.0, 0.0); glTexCoord2f(image_w, 0.0); glVertex2f(image_w, 0.0); glTexCoord2f(image_w, image_h); glVertex2f(image_w, image_h); glTexCoord2f(0.0, image_h); glVertex2f(0.0, image_h); glEnd(); //////////////////////////////////////////////////////////////////////////////////////////////// //cgGLDisableTextureParameter(myCgFragmentParam_decal); //checkForCgError("disabling decal texture"); //////////////////////////////////////////////////////////////////////////////////////////////// //--------------------end------------------------ GLenum errCode; const GLubyte *errStr; if ((errCode = glGetError()) != GL_NO_ERROR) { errStr = gluErrorString(errCode); printf("OpenGL ERROR: "); printf((char*)errStr); printf("(Label: "); printf(""); printf(").\n"); } /*image_w/=16; image_h/=16; result=new float[image_w*image_h*4];*/ glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); glReadPixels(0, 0, image_w, image_h,GL_RGBA,GL_FLOAT,result); int n2=GetTickCount(); //cgGLDisableProfile(myCgFragmentProfile); //checkForCgError("disabling fragment profile"); //aa cgGLDisableProfile(myCgFragmentProfile); checkForCgError("disabling fragment profile"); printf("%d-ms",n2-n1); if ((errCode = glGetError()) != GL_NO_ERROR) { errStr = gluErrorString(errCode); printf("OpenGL ERROR: "); printf((char*)errStr); printf("(Label: "); printf(""); printf(")\n."); } //printf("Data before roundtrip: \n"); //for (i=0; i<texSize*texSize; i++) //printf("%f \n",data[i]); //WORD *pixel1=new WORD[image_h * image_w]; for(/*int*/ i=0;i<image_w*image_h;i++) { m_pOut[i]=(WORD)(result[4*i]); //printf("%f\n",pixel1[i]); } HRESULT hr=m_pDicomFile->SetPixelData(( unsigned char *)m_pOut,sizeof(WORD)*image_h * image_w); m_pDicomFile->PutColumns(image_w); m_pDicomFile->PutRows(image_h); hr=m_pDicomFile->SaveTo("c:\\MEX3.DCM"); // printf("Data after roundtrip: \n"); // for (i=0; i<image_w*image_h*4; i++) // printf("%f \n",result[i]); // free(data); free(result); // cgDestroyProgram(myCgVertexProgram); cgDestroyProgram(myCgFragmentProgram); cgDestroyContext(myCgContext); //exit(0); glDeleteFramebuffersEXT (1,&fb); glDeleteTextures (1,&tex); glDeleteTextures(1,&fboTex); return 0; return TRUE; } /////////////////////////////////////////////////////////////////////////////////////////// In cg : typedef float4 COLORTYPE; //高斯卷积核 typedef float color; COLORTYPE Conv_smooth(uniform samplerRECT image : TEXUNIT0, float2 pos : TEXCOORD0 // position in image ) : COLOR { //图像控制参数,来自susan代码 COLORTYPE c = 0; COLORTYPE c1 = 0; COLORTYPE tem=0; //color weight=1.0/kernel_width/kernel_height; float area=0; float total=0; float pm; int tmp=0; COLORTYPE mVal=0; c1=texRECTlod(image, float4(pos ,0.0,2.0)); //c1=8192; return c1; } //////////////////////////////////////////////////////////////////////////////////// But the Image data result is from level 0.Why?Thanks a lot.

Share this post


Link to post
Share on other sites
It is hard to read. Can you put bracket source bracket and
bracket /source bracket around your code.

Also, it looks like you are making RECT textures. RECT doesn't support mipmaps, so it is normal that you only have lod 0 available.

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