This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-05-20 10:51:02

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

OpenGL implementation in Scratch

Yep! I did it!

http://goo.gl/RjVHC (Goo.gl link so I can track how many clicks I get from this forum)

It uses quick shading to fill triangles, and a bit of trig to handle the rotation. However, culling does not work. If you know a good way to cull faces, please feel free to remix.

Thanks,
Hardmath


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#2 2012-05-20 13:03:57

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: OpenGL implementation in Scratch

Oh, you finally figured out a method  smile
I'm sorry to say, however, that if you tilt the cube at a standard isometric perspective (more or less) the draw order still messes up. (like so)

Also, it's flashy, and it appears to clear before it finishes drawing.

Offline

 

#3 2012-05-20 13:07:55

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: OpenGL implementation in Scratch

And, for the culling:

I honestly doubt you'll ever need any when rendering a cube. For other purposes, the methods will be way too slow (I think even the quickest way would have to loop through all the other polygons to determine whether they cover the one you want)... assuming you're talking about occlusion culling.

Offline

 

#4 2012-05-20 19:55:00

applejack
Scratcher
Registered: 2010-03-23
Posts: 100+

Re: OpenGL implementation in Scratch

... I thought of an idea for a 3D engine. It would be deathly slow, but I think it might work. For each pixel, pretend it is like a ray coming from your eye. find where it hits a surface, and make the pixel on the screen that color. You could add extra variables to the surfaces, like shiny-ness, so you could bounce your ray off the surface you just touched onto another surface, where you would take that color and do some math with it to combine it with your other surface's color and so on. The problem is that I'm having trouble thinking of a way to see where a ray intersects a surface, or if it does at all. Could you help?


http://i.imgur.com/zKzps.png
http://blocks.scratchr.org/API.php?action=onlineStatus&type=square&user=applejack -I'm http://blocks.scratchr.org/API.php?action=onlineStatus&type=text&user=applejack

Offline

 

#5 2012-05-20 20:01:05

zubblewu
Scratcher
Registered: 2011-02-17
Posts: 1000+

Re: OpenGL implementation in Scratch

applejack wrote:

... I thought of an idea for a 3D engine. It would be deathly slow, but I think it might work. For each pixel, pretend it is like a ray coming from your eye. find where it hits a surface, and make the pixel on the screen that color. You could add extra variables to the surfaces, like shiny-ness, so you could bounce your ray off the surface you just touched onto another surface, where you would take that color and do some math with it to combine it with your other surface's color and so on. The problem is that I'm having trouble thinking of a way to see where a ray intersects a surface, or if it does at all. Could you help?

That's called ray tracing  wink


........................................................................................................................................................................................................................................

Offline

 

#6 2012-05-20 20:19:14

applejack
Scratcher
Registered: 2010-03-23
Posts: 100+

Re: OpenGL implementation in Scratch

So THAT'S what ray-tracing is. Thanks, there are so many different ways to make 3D. I learned something new!  big_smile  But I would still like an answer to my question  hmm

zubblewu wrote:

applejack wrote:

... I thought of an idea for a 3D engine. It would be deathly slow, but I think it might work. For each pixel, pretend it is like a ray coming from your eye. find where it hits a surface, and make the pixel on the screen that color. You could add extra variables to the surfaces, like shiny-ness, so you could bounce your ray off the surface you just touched onto another surface, where you would take that color and do some math with it to combine it with your other surface's color and so on. The problem is that I'm having trouble thinking of a way to see where a ray intersects a surface, or if it does at all. Could you help?

That's called ray tracing  wink


http://i.imgur.com/zKzps.png
http://blocks.scratchr.org/API.php?action=onlineStatus&type=square&user=applejack -I'm http://blocks.scratchr.org/API.php?action=onlineStatus&type=text&user=applejack

Offline

 

#7 2012-05-20 20:47:02

gbear605
Scratcher
Registered: 2008-03-06
Posts: 1000+

Re: OpenGL implementation in Scratch

Wow, cool!


Yeah, I'm mostly inactive.  I check in once in a while though.  If you want to contact me, I have a contact form at my website, http://escratch.org

Offline

 

#8 2012-05-21 00:34:44

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: OpenGL implementation in Scratch

applejack wrote:

So THAT'S what ray-tracing is. Thanks, there are so many different ways to make 3D. I learned something new!  big_smile  But I would still like an answer to my question  hmm

zubblewu wrote:

applejack wrote:

... I thought of an idea for a 3D engine. It would be deathly slow, but I think it might work. For each pixel, pretend it is like a ray coming from your eye. find where it hits a surface, and make the pixel on the screen that color. You could add extra variables to the surfaces, like shiny-ness, so you could bounce your ray off the surface you just touched onto another surface, where you would take that color and do some math with it to combine it with your other surface's color and so on. The problem is that I'm having trouble thinking of a way to see where a ray intersects a surface, or if it does at all. Could you help?

That's called ray tracing  wink

You can check out this project by me for a simple raytracer.  wink


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#9 2012-05-21 01:13:11

applejack
Scratcher
Registered: 2010-03-23
Posts: 100+

Re: OpenGL implementation in Scratch

I know!  big_smile  I did, but I was being lazy and "meh" like. I think that I'll try to make one on my own, so that I can learn how they work better. Your 3D projects are all awesome.

Hardmath123 wrote:

applejack wrote:

So THAT'S what ray-tracing is. Thanks, there are so many different ways to make 3D. I learned something new!  big_smile  But I would still like an answer to my question  hmm

zubblewu wrote:


That's called ray tracing  wink

You can check out this project by me for a simple raytracer.  wink


http://i.imgur.com/zKzps.png
http://blocks.scratchr.org/API.php?action=onlineStatus&type=square&user=applejack -I'm http://blocks.scratchr.org/API.php?action=onlineStatus&type=text&user=applejack

Offline

 

#10 2012-05-21 01:41:36

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: OpenGL implementation in Scratch

LS97 wrote:

And, for the culling:

I honestly doubt you'll ever need any when rendering a cube. For other purposes, the methods will be way too slow (I think even the quickest way would have to loop through all the other polygons to determine whether they cover the one you want)... assuming you're talking about occlusion culling.

I am talking about occlusion culling. Right now, I'm using a not-so-accurate method where I test the average Z positions. I am actively working on a better version though.

And yes, you do have to check each polygon against the other, making efficient occlusion tests is a hard CS problem which people are working on even today.

Last edited by Hardmath123 (2012-05-21 01:41:55)


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#11 2012-05-21 03:32:34

slinger
Scratcher
Registered: 2011-06-21
Posts: 1000+

Re: OpenGL implementation in Scratch

Amazing. I may want to point out that there seems to be no perspective.


http://s0.bcbits.com/img/buttons/bandcamp_130x27_blue.png

Offline

 

#12 2012-05-21 05:43:46

nathanprocks
Scratcher
Registered: 2011-04-14
Posts: 1000+

Re: OpenGL implementation in Scratch

Cool but when I turned the thing around, one part was rendered in front of the part that was meant to be at the front.


http://carrot.cassiedragonandfriends.org/Scratch_Signature/randomsig.php
http://trinary.site40.net/images/scratchrank.php?username=nathanprocks&display=small

Offline

 

#13 2012-05-21 05:45:39

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: OpenGL implementation in Scratch

nathanprocks wrote:

Cool but when I turned the thing around, one part was rendered in front of the part that was meant to be at the front.

I know, that's the "depth testing" I've been ranting about since I posted this project. There are ways to get it right, but my closest approximation was 70 lines of hard-code recursive JavaScript and I'm not ready to Scratch it without being convinced there are better ways.


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#14 2012-05-21 09:55:39

ZeroLuck
Scratcher
Registered: 2010-02-23
Posts: 500+

Re: OpenGL implementation in Scratch

I like it, but why do you call this OpenGL?  smile


http://3.bp.blogspot.com/-oL2Atzp0Byw/T465vIQ36dI/AAAAAAAAADo/1vqL4PvhkM0/s1600/scratchdachwiki.png

Offline

 

#15 2012-05-21 10:17:28

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: OpenGL implementation in Scratch

ZeroLuck wrote:

I like it, but why do you call this OpenGL?  smile

Well, at some point I'm hoping to be able to read and evaluate OpenGL ES code.


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#16 2012-05-21 11:43:24

ProgrammingFreak
Scratcher
Registered: 2010-09-04
Posts: 1000+

Re: OpenGL implementation in Scratch

Very good. I can't wait to see the new versions with bug fixes. :3

Offline

 

#17 2012-05-21 11:58:03

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: OpenGL implementation in Scratch

Thanks.


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#18 2012-05-21 13:47:00

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: OpenGL implementation in Scratch

Almost too good to be just in Scratch!  tongue  And 1 sprite 1 script, too!
And even though this is a slightly technical project, it does belong in Show and Tell. You could just mention "1S1S 3D graphics" in the title to attract people who don't know what OpenGL is.  tongue

Offline

 

#19 2012-05-21 16:36:54

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: OpenGL implementation in Scratch

Implement shaders...


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#20 2012-05-21 18:03:11

gbear605
Scratcher
Registered: 2008-03-06
Posts: 1000+

Re: OpenGL implementation in Scratch

scimonster wrote:

Almost too good to be just in Scratch!  tongue  And 1 sprite 1 script, too!
And even though this is a slightly technical project, it does belong in Show and Tell. You could just mention "1S1S 3D graphics" in the title to attract people who don't know what OpenGL is.  tongue

I'm not so sure it goes in show and tell.  In the past, projects like this were put in Advanced Topics, because of the advanced code.  Y'know, because of the advanced-ness.

Last edited by gbear605 (2012-05-21 18:03:48)


Yeah, I'm mostly inactive.  I check in once in a while though.  If you want to contact me, I have a contact form at my website, http://escratch.org

Offline

 

#21 2012-05-22 05:47:13

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: OpenGL implementation in Scratch

scimonster wrote:

Almost too good to be just in Scratch!  tongue  And 1 sprite 1 script, too!
And even though this is a slightly technical project, it does belong in Show and Tell. You could just mention "1S1S 3D graphics" in the title to attract people who don't know what OpenGL is.  tongue

I put this in the ATs deliberately, because this project uses hard math and tries to simulate a complex programming library. It's the kind of thing we Advanced Scratchers love, so I wanted to see how they would react, what questions they would have.

Another, bigger, reason was the fact that I was asking for the answer to a complex math problem (depth testing), and I was pretty sure I was only gonna get a response from our geniuses over at the ATs, not from people at the Show and Tell (no offense to the Show & Tell guys, it's just that I don't see much complex math around there).

So please move it back to the ATs. Thanks!  smile


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#22 2012-05-22 07:17:02

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: OpenGL implementation in Scratch

Hardmath123 wrote:

scimonster wrote:

Almost too good to be just in Scratch!  tongue  And 1 sprite 1 script, too!
And even though this is a slightly technical project, it does belong in Show and Tell. You could just mention "1S1S 3D graphics" in the title to attract people who don't know what OpenGL is.  tongue

I put this in the ATs deliberately, because this project uses hard math and tries to simulate a complex programming library. It's the kind of thing we Advanced Scratchers love, so I wanted to see how they would react, what questions they would have.

Another, bigger, reason was the fact that I was asking for the answer to a complex math problem (depth testing), and I was pretty sure I was only gonna get a response from our geniuses over at the ATs, not from people at the Show and Tell (no offense to the Show & Tell guys, it's just that I don't see much complex math around there).

So please move it back to the ATs. Thanks!  smile

I'll buy those arguments  smile


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#23 2012-05-22 07:31:28

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: OpenGL implementation in Scratch

Paddle2See wrote:

Hardmath123 wrote:

scimonster wrote:

Almost too good to be just in Scratch!  tongue  And 1 sprite 1 script, too!
And even though this is a slightly technical project, it does belong in Show and Tell. You could just mention "1S1S 3D graphics" in the title to attract people who don't know what OpenGL is.  tongue

I put this in the ATs deliberately, because this project uses hard math and tries to simulate a complex programming library. It's the kind of thing we Advanced Scratchers love, so I wanted to see how they would react, what questions they would have.

Another, bigger, reason was the fact that I was asking for the answer to a complex math problem (depth testing), and I was pretty sure I was only gonna get a response from our geniuses over at the ATs, not from people at the Show and Tell (no offense to the Show & Tell guys, it's just that I don't see much complex math around there).

So please move it back to the ATs. Thanks!  smile

I'll buy those arguments  smile

And in show and tell, you don't argue with mods.


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#24 2012-05-22 13:43:15

rookwood101
Scratcher
Registered: 2011-07-29
Posts: 500+

Re: OpenGL implementation in Scratch

Could some of the stuff on this blog help you?

(with the z-indexing)

Last edited by rookwood101 (2012-05-22 13:43:32)


http://i.imgur.com/zeIZW.png

Offline

 

#25 2012-05-22 16:24:48

MathWizz
Scratcher
Registered: 2009-08-31
Posts: 1000+

Re: OpenGL implementation in Scratch

Hardmath123 wrote:

ZeroLuck wrote:

I like it, but why do you call this OpenGL?  smile

Well, at some point I'm hoping to be able to read and evaluate OpenGL ES code.

Eeeaaauummm... Wat? Really?  yikes


http://block.site90.net/scratch.mit/text.php?size=30&text=%20A%20signature!&color=333333

Offline

 

Board footer