Jump to content

Custom Cursor C++


Aaron Symons
 Share

Recommended Posts

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? smile.png

 

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

Win7 64-bit | Intel i7-3770 3.40GHz | NVIDIA GeForce GTX 660

Link to comment
Share on other sites

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

  • Upvote 1

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

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.

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

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! :)

Win7 64-bit | Intel i7-3770 3.40GHz | NVIDIA GeForce GTX 660

Link to comment
Share on other sites

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.

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

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!

Win7 64-bit | Intel i7-3770 3.40GHz | NVIDIA GeForce GTX 660

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...