Aaron Symons Posted May 7, 2016 Share Posted May 7, 2016 Hi all! I have a custom Cursor class written in C++. The image (a *.tex file) is being drawn multiple times across the window as I move the mouse. How can I draw it only where the mouse is, and avoid it being drawn all over the place? I have this for drawing: context->SetBlendMode(Leadwerks::Blend::Alpha); context->DrawImage(cursorImage, (mousePosition.x - cursorOffset.x), (mousePosition.y - cursorOffset.y)); context->SetBlendMode(Leadwerks::Blend::Solid); I've attempted clearing the context - which resolves this issue - but other drawn images do not display, as the cursor is the last thing to be drawn. Many thanks Quote Win7 64-bit | Intel i7-3770 3.40GHz | NVIDIA GeForce GTX 660 Link to comment Share on other sites More sharing options...
macklebee Posted May 11, 2016 Share Posted May 11, 2016 so you are not rendering a world, but just drawing 2D items? If thats the case, then just clear the context prior to drawing any of the 2D items each loop. simple example: window = Window:Create() context = Context:Create(window) background = Texture:Load("Materials/Developer/greengrid.tex") crosshair = Texture:Load("Materials/Hud/crosshair.tex") ch_width = crosshair:GetWidth() ch_height = crosshair:GetHeight() window:HideMouse() while window:KeyDown(Key.Escape)==false do m_pos = window:GetMousePosition() context:SetColor(1,1,1) context:Clear() context:DrawImage(background,0,0,context:GetWidth(),context:GetHeight()) context:SetBlendMode(Blend.Alpha) context:SetColor(0,0,1) context:DrawImage(crosshair, m_pos.x - (ch_width/2), m_pos.y - (ch_height/2)) context:SetColor(1,0,0) context:DrawText("Mouse position: "..m_pos.x..", "..m_pos.y, 2, 2) context:SetBlendMode(Blend.Solid) context:Sync(true) end 1 Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
gamecreator Posted May 11, 2016 Share Posted May 11, 2016 You may also need to use SetColor before the Clear because I believe Clear uses the last color set. 1 Quote Link to comment Share on other sites More sharing options...
macklebee Posted May 11, 2016 Share Posted May 11, 2016 You may also need to use SetColor before the Clear because I believe Clear uses the last color set. good catch - fixed in the code above. I didn't see it since my code is drawing a texture over the entire context, but that's exactly what would happen if I was not doing that. Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Aaron Symons Posted May 14, 2016 Author Share Posted May 14, 2016 Hi guys, Thanks for the response. Clearing the context works, but only works without setting the color (before or after clearing), as I receive a black screen. However, as my background is currently black, I feel I could possibly draw a black background instead of setting the context color. This might be the way to go. I'll keep you guys updated with what I find. Thanks again! Quote Win7 64-bit | Intel i7-3770 3.40GHz | NVIDIA GeForce GTX 660 Link to comment Share on other sites More sharing options...
macklebee Posted May 14, 2016 Share Posted May 14, 2016 Thanks for the response. Clearing the context works, but only works without setting the color (before or after clearing), as I receive a black screen. This should not occur. You should post your code. Or compare my example to what you are doing to see the difference. Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Aaron Symons Posted May 21, 2016 Author Share Posted May 21, 2016 This should not occur. You should post your code. Or compare my example to what you are doing to see the difference. Your code basically follows the same flow I'm using, except I don't set the context color before clearing the context. Everything renders as needed now, but if you think I definitely should be setting the context color before clearing the context, we can explore and discuss further. Thanks! Quote Win7 64-bit | Intel i7-3770 3.40GHz | NVIDIA GeForce GTX 660 Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.