2013-03-13 140 views
0

我在GLcontrol中繪製了紋理,我想在它上面繪製點。相反,我得到完整的紋理設置爲我想繪製的點的顏色。我想我必須禁用紋理格式並啓用點圖,但不能達到解決方案...紋理頂部的繪製點openGL

這裏是繪圖函數: 基本上繪製的點是ROI [0],但是繪製只是我得到如下圖所示的圖像(在繪製「點」之前圖像是灰度的)。

private: void drawImg(int img){ 

     int w=this->glControl_create_grid->Width; 
     int h=this->glControl_create_grid->Height; 
     GL::MatrixMode(MatrixMode::Projection); 

     GL::LoadIdentity(); 
     GL::Ortho(0, w, 0, h, -1, 1); // Bottom-left corner pixel has coordinate (0, 0) 
     GL::Viewport(0, 0, w, h); // Use all of the glControl painting area 

     GL::Clear(ClearBufferMask::ColorBufferBit | ClearBufferMask::DepthBufferBit); 
     GL::ClearColor(Color::LightGray); 
     GL::MatrixMode(MatrixMode::Modelview); 
     GL::LoadIdentity(); 

     GL::Enable(EnableCap::Texture2D); 
     GL::BindTexture(TextureTarget::Texture2D, img); 
     OpenTK::Graphics::OpenGL::ErrorCode error=GL::GetError(); 
      GL::Begin(BeginMode::Quads); 
       GL::TexCoord2(0, 0); 
       GL::Vertex2(0 ,h); 

       GL::TexCoord2(1, 0); 
       GL::Vertex2(w, h); 

       GL::TexCoord2(1, 1); 
       GL::Vertex2(w, 0); 

       GL::TexCoord2(0, 1); 
       GL::Vertex2(0, 0); 
      GL::End(); 
      GL::Disable(EnableCap::Texture2D); 
      if (ROI[0].x!=0||ROI[0].y!=0){ 
       GL::Color3(Color::Red); 
       GL::Begin(BeginMode::Points); 
       GL::Vertex2(ROI[0].x,ROI[0].y); 
       GL::End(); 
      } 


    } 

enter image description here

我應該在我的代碼改變?我似乎無法實現它....

回答

3

我找到了答案。看起來這種顏色在綁定紋理時也適用,因此我只需在繪製紋理之前添加GL::Color3(Color::White)

+1

你說得對,根據紋理環境的設置(用glTexEnv設置),頂點顏色可以調製紋理顏色 - 這就是GL_MODULATE模式。還有另一種模式GL_DECAL,它將在頂點顏色的頂部繪製紋理;主要用於具有透明區域的紋理。然而,今天一切都是通過着色器發生的,而且你在過程的每一步都要負責(與固定功能相比,你只能拋出幾個開關)。 – datenwolf 2013-03-13 13:26:49